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 { DataProcessor } from '../data_processor'; |
||||||
|
import { getProcessedSeriesData } from 'app/features/dashboard/state/PanelQueryState'; |
||||||
|
|
||||||
describe('Graph DataProcessor', () => { |
describe('Graph DataProcessor', () => { |
||||||
const panel: any = { |
const panel: any = { |
||||||
xaxis: {}, |
xaxis: { mode: 'series' }, |
||||||
|
aliasColors: {}, |
||||||
}; |
}; |
||||||
|
|
||||||
const processor = new DataProcessor(panel); |
const processor = new DataProcessor(panel); |
||||||
|
|
||||||
describe('Given default xaxis options and query that returns docs', () => { |
describe('getTimeSeries from LegacyResponseData', () => { |
||||||
beforeEach(() => { |
// Try each type of data
|
||||||
panel.xaxis.mode = 'time'; |
const dataList = getProcessedSeriesData([ |
||||||
panel.xaxis.name = 'hostname'; |
|
||||||
panel.xaxis.values = []; |
|
||||||
|
|
||||||
processor.getSeriesList({ |
|
||||||
dataList: [ |
|
||||||
{ |
{ |
||||||
type: 'docs', |
alias: 'First (time_series)', |
||||||
datapoints: [{ hostname: 'server1', avg: 10 }], |
datapoints: [[1, 1001], [2, 1002], [3, 1003]], |
||||||
|
unit: 'watt', |
||||||
}, |
}, |
||||||
], |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
it('Should automatically set xaxis mode to field', () => { |
|
||||||
expect(panel.xaxis.mode).toBe('field'); |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
describe('getDataFieldNames(', () => { |
|
||||||
const dataList = [ |
|
||||||
{ |
|
||||||
type: 'docs', |
|
||||||
datapoints: [ |
|
||||||
{ |
{ |
||||||
hostname: 'server1', |
name: 'table_data', |
||||||
valueField: 11, |
columns: [ |
||||||
nested: { |
{ text: 'time' }, |
||||||
prop1: 'server2', |
{ text: 'v1', unit: 'ohm' }, |
||||||
value2: 23, |
{ text: 'v2' }, // no unit
|
||||||
}, |
{ text: 'string' }, // skipped
|
||||||
|
], |
||||||
|
rows: [ |
||||||
|
[1001, 0.1, 1.1, 'a'], // a
|
||||||
|
[1002, 0.2, 2.2, 'b'], // b
|
||||||
|
[1003, 0.3, 3.3, 'c'], // c
|
||||||
|
], |
||||||
}, |
}, |
||||||
|
{ |
||||||
|
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', () => { |
it('Should return a new series for each field', () => { |
||||||
const fields = processor.getDataFieldNames(dataList, false); |
panel.xaxis.mode = 'series'; |
||||||
expect(fields).toContain('hostname'); |
const series = processor.getSeriesList({ dataList }); |
||||||
expect(fields).toContain('valueField'); |
expect(series.length).toEqual(5); |
||||||
expect(fields).toContain('nested.prop1'); |
expect(series).toMatchSnapshot(); |
||||||
expect(fields).toContain('nested.value2'); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('Should return all number fields', () => { |
it('Should return single histogram', () => { |
||||||
const fields = processor.getDataFieldNames(dataList, true); |
panel.xaxis.mode = 'histogram'; |
||||||
expect(fields).toContain('valueField'); |
const series = processor.getSeriesList({ dataList }); |
||||||
expect(fields).toContain('nested.value2'); |
expect(series.length).toEqual(1); |
||||||
|
expect(series).toMatchSnapshot(); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
Loading…
Reference in new issue