mirror of https://github.com/grafana/grafana
GraphPanel: show results for all SeriesData (#16966)
* Graph panel should support SeriesData * Graph panel should support SeriesData * same path for all series * merge master * support docs * add test for processor * Graph: removed old unused data processing logic * Graph: minor refactoring data processing * fix histogram * set Count as titlepull/17019/head
parent
cf39a264ca
commit
813e3ffc15
@ -0,0 +1,233 @@ |
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
||||
exports[`Graph DataProcessor getTimeSeries from LegacyResponseData Should return a new series for each field 1`] = ` |
||||
Array [ |
||||
TimeSeries { |
||||
"alias": "Value", |
||||
"aliasEscaped": "Value", |
||||
"bars": Object { |
||||
"fillColor": "#7EB26D", |
||||
}, |
||||
"color": "#7EB26D", |
||||
"datapoints": Array [ |
||||
Array [ |
||||
1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
3, |
||||
1003, |
||||
], |
||||
], |
||||
"hasMsResolution": false, |
||||
"id": "Value", |
||||
"label": "Value", |
||||
"legend": true, |
||||
"stats": Object {}, |
||||
"unit": "watt", |
||||
"valueFormater": [Function], |
||||
}, |
||||
TimeSeries { |
||||
"alias": "table_data v1", |
||||
"aliasEscaped": "table_data v1", |
||||
"bars": Object { |
||||
"fillColor": "#EAB839", |
||||
}, |
||||
"color": "#EAB839", |
||||
"datapoints": Array [ |
||||
Array [ |
||||
0.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
0.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
0.3, |
||||
1003, |
||||
], |
||||
], |
||||
"hasMsResolution": false, |
||||
"id": "table_data v1", |
||||
"label": "table_data v1", |
||||
"legend": true, |
||||
"stats": Object {}, |
||||
"unit": "ohm", |
||||
"valueFormater": [Function], |
||||
}, |
||||
TimeSeries { |
||||
"alias": "table_data v2", |
||||
"aliasEscaped": "table_data v2", |
||||
"bars": Object { |
||||
"fillColor": "#6ED0E0", |
||||
}, |
||||
"color": "#6ED0E0", |
||||
"datapoints": Array [ |
||||
Array [ |
||||
1.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
2.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
3.3, |
||||
1003, |
||||
], |
||||
], |
||||
"hasMsResolution": false, |
||||
"id": "table_data v2", |
||||
"label": "table_data v2", |
||||
"legend": true, |
||||
"stats": Object {}, |
||||
"unit": undefined, |
||||
"valueFormater": [Function], |
||||
}, |
||||
TimeSeries { |
||||
"alias": "series v1", |
||||
"aliasEscaped": "series v1", |
||||
"bars": Object { |
||||
"fillColor": "#EF843C", |
||||
}, |
||||
"color": "#EF843C", |
||||
"datapoints": Array [ |
||||
Array [ |
||||
0.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
0.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
0.3, |
||||
1003, |
||||
], |
||||
], |
||||
"hasMsResolution": false, |
||||
"id": "series v1", |
||||
"label": "series v1", |
||||
"legend": true, |
||||
"stats": Object {}, |
||||
"unit": undefined, |
||||
"valueFormater": [Function], |
||||
}, |
||||
TimeSeries { |
||||
"alias": "series v2", |
||||
"aliasEscaped": "series v2", |
||||
"bars": Object { |
||||
"fillColor": "#E24D42", |
||||
}, |
||||
"color": "#E24D42", |
||||
"datapoints": Array [ |
||||
Array [ |
||||
1.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
2.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
3.3, |
||||
1003, |
||||
], |
||||
], |
||||
"hasMsResolution": false, |
||||
"id": "series v2", |
||||
"label": "series v2", |
||||
"legend": true, |
||||
"stats": Object {}, |
||||
"unit": undefined, |
||||
"valueFormater": [Function], |
||||
}, |
||||
] |
||||
`; |
||||
|
||||
exports[`Graph DataProcessor getTimeSeries from LegacyResponseData Should return single histogram 1`] = ` |
||||
Array [ |
||||
TimeSeries { |
||||
"alias": "Count", |
||||
"aliasEscaped": "Count", |
||||
"bars": Object { |
||||
"fillColor": "#7EB26D", |
||||
}, |
||||
"color": "#7EB26D", |
||||
"datapoints": Array [ |
||||
Array [ |
||||
1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
3, |
||||
1003, |
||||
], |
||||
Array [ |
||||
0.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
0.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
0.3, |
||||
1003, |
||||
], |
||||
Array [ |
||||
1.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
2.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
3.3, |
||||
1003, |
||||
], |
||||
Array [ |
||||
0.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
0.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
0.3, |
||||
1003, |
||||
], |
||||
Array [ |
||||
1.1, |
||||
1001, |
||||
], |
||||
Array [ |
||||
2.2, |
||||
1002, |
||||
], |
||||
Array [ |
||||
3.3, |
||||
1003, |
||||
], |
||||
], |
||||
"hasMsResolution": false, |
||||
"id": "Value", |
||||
"label": "Value", |
||||
"legend": true, |
||||
"stats": Object {}, |
||||
"unit": "watt", |
||||
"valueFormater": [Function], |
||||
}, |
||||
] |
||||
`; |
@ -1,62 +1,60 @@ |
||||
import { DataProcessor } from '../data_processor'; |
||||
import { getProcessedSeriesData } from 'app/features/dashboard/state/PanelQueryState'; |
||||
|
||||
describe('Graph DataProcessor', () => { |
||||
const panel: any = { |
||||
xaxis: {}, |
||||
xaxis: { mode: 'series' }, |
||||
aliasColors: {}, |
||||
}; |
||||
|
||||
const processor = new DataProcessor(panel); |
||||
|
||||
describe('Given default xaxis options and query that returns docs', () => { |
||||
beforeEach(() => { |
||||
panel.xaxis.mode = 'time'; |
||||
panel.xaxis.name = 'hostname'; |
||||
panel.xaxis.values = []; |
||||
|
||||
processor.getSeriesList({ |
||||
dataList: [ |
||||
{ |
||||
type: 'docs', |
||||
datapoints: [{ hostname: 'server1', avg: 10 }], |
||||
}, |
||||
describe('getTimeSeries from LegacyResponseData', () => { |
||||
// Try each type of data
|
||||
const dataList = getProcessedSeriesData([ |
||||
{ |
||||
alias: 'First (time_series)', |
||||
datapoints: [[1, 1001], [2, 1002], [3, 1003]], |
||||
unit: 'watt', |
||||
}, |
||||
{ |
||||
name: 'table_data', |
||||
columns: [ |
||||
{ text: 'time' }, |
||||
{ text: 'v1', unit: 'ohm' }, |
||||
{ text: 'v2' }, // no unit
|
||||
{ text: 'string' }, // skipped
|
||||
], |
||||
}); |
||||
}); |
||||
|
||||
it('Should automatically set xaxis mode to field', () => { |
||||
expect(panel.xaxis.mode).toBe('field'); |
||||
}); |
||||
}); |
||||
|
||||
describe('getDataFieldNames(', () => { |
||||
const dataList = [ |
||||
rows: [ |
||||
[1001, 0.1, 1.1, 'a'], // a
|
||||
[1002, 0.2, 2.2, 'b'], // b
|
||||
[1003, 0.3, 3.3, 'c'], // c
|
||||
], |
||||
}, |
||||
{ |
||||
type: 'docs', |
||||
datapoints: [ |
||||
{ |
||||
hostname: 'server1', |
||||
valueField: 11, |
||||
nested: { |
||||
prop1: 'server2', |
||||
value2: 23, |
||||
}, |
||||
}, |
||||
name: 'series', |
||||
fields: [ |
||||
{ name: 'v1' }, // first
|
||||
{ name: 'v2' }, // second
|
||||
{ name: 'string' }, // skip
|
||||
{ name: 'time' }, // Time is last column
|
||||
], |
||||
rows: [[0.1, 1.1, 'a', 1001], [0.2, 2.2, 'b', 1002], [0.3, 3.3, 'c', 1003]], |
||||
}, |
||||
]; |
||||
]); |
||||
|
||||
it('Should return all field names', () => { |
||||
const fields = processor.getDataFieldNames(dataList, false); |
||||
expect(fields).toContain('hostname'); |
||||
expect(fields).toContain('valueField'); |
||||
expect(fields).toContain('nested.prop1'); |
||||
expect(fields).toContain('nested.value2'); |
||||
it('Should return a new series for each field', () => { |
||||
panel.xaxis.mode = 'series'; |
||||
const series = processor.getSeriesList({ dataList }); |
||||
expect(series.length).toEqual(5); |
||||
expect(series).toMatchSnapshot(); |
||||
}); |
||||
|
||||
it('Should return all number fields', () => { |
||||
const fields = processor.getDataFieldNames(dataList, true); |
||||
expect(fields).toContain('valueField'); |
||||
expect(fields).toContain('nested.value2'); |
||||
it('Should return single histogram', () => { |
||||
panel.xaxis.mode = 'histogram'; |
||||
const series = processor.getSeriesList({ dataList }); |
||||
expect(series.length).toEqual(1); |
||||
expect(series).toMatchSnapshot(); |
||||
}); |
||||
}); |
||||
}); |
||||
|
Loading…
Reference in new issue