diff --git a/ui/spec/utils/timeSeriesToDygraphSpec.js b/ui/spec/utils/timeSeriesToDygraphSpec.js index 0b3b6c72a..8a9442cc7 100644 --- a/ui/spec/utils/timeSeriesToDygraphSpec.js +++ b/ui/spec/utils/timeSeriesToDygraphSpec.js @@ -176,4 +176,64 @@ describe('timeSeriesToDygraph', () => { expect(actual.dygraphSeries).to.deep.equal(expected.dygraphSeries); }); + + it('parses a raw InfluxDB response into a dygraph friendly data format', () => { + const influxResponse = [ + { + "response": + { + "results": [ + { + "series": [ + { + "name":"mb", + "columns": ["time","f1"], + "values": [[1000, 1],[2000, 2]], + }, + ] + }, + { + "series": [ + { + "name":"ma", + "columns": ["time","f1"], + "values": [[1000, 1],[2000, 2]], + }, + ] + }, + { + "series": [ + { + "name":"mc", + "columns": ["time","f2"], + "values": [[2000, 3],[4000, 4]], + }, + ] + }, + { + "series": [ + { + "name":"mc", + "columns": ["time","f1"], + "values": [[2000, 3],[4000, 4]], + }, + ] + }, + ], + }, + } + ]; + + const actual = timeSeriesToDygraph(influxResponse); + + const expected = [ + 'time', + `ma.f1`, + `mb.f1`, + `mc.f1`, + `mc.f2`, + ]; + + expect(actual.labels).to.deep.equal(expected); + }); }); diff --git a/ui/src/utils/timeSeriesToDygraph.js b/ui/src/utils/timeSeriesToDygraph.js index 9702842c4..a13d99410 100644 --- a/ui/src/utils/timeSeriesToDygraph.js +++ b/ui/src/utils/timeSeriesToDygraph.js @@ -148,8 +148,15 @@ export default function timeSeriesToDygraph(raw = [], activeQueryIndex) { }); } + function sortLabels() { + const time = labels.shift(); + labels.sort(); + labels.unshift(time); + return labels; + } + return { - labels, + labels: sortLabels(labels), timeSeries: buildTimeSeries(), dygraphSeries, };