Sort graph legend alphabetically

pull/742/head
Andrew Watkins 2017-01-06 11:56:38 -08:00
parent 31adca6e77
commit 1619f9be99
2 changed files with 68 additions and 1 deletions

View File

@ -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);
});
});

View File

@ -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,
};