Sort graph legend alphabetically
parent
31adca6e77
commit
1619f9be99
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue