WIP Fix label ordering bug
parent
0375d88e2f
commit
9cb38ae4ba
|
@ -322,45 +322,35 @@ describe('timeSeriesToDygraph', () => {
|
||||||
expect(dygraphSeries["m2.f2"].strokeWidth).to.be.above(dygraphSeries["m1.f1"].strokeWidth);
|
expect(dygraphSeries["m2.f2"].strokeWidth).to.be.above(dygraphSeries["m1.f1"].strokeWidth);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parses a raw InfluxDB response into a dygraph friendly data format', () => {
|
it('parses labels alphabetically with the correct field values for multiple series', () => {
|
||||||
const influxResponse = [
|
const influxResponse = [
|
||||||
{
|
{
|
||||||
"response":
|
"response":
|
||||||
{
|
{
|
||||||
"results": [
|
"results": [
|
||||||
{
|
|
||||||
"series": [
|
|
||||||
{
|
|
||||||
"name":"mb",
|
|
||||||
"columns": ["time","f1"],
|
|
||||||
"values": [[1000, 1],[2000, 2]],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"series": [
|
"series": [
|
||||||
{
|
{
|
||||||
"name":"ma",
|
"name":"ma",
|
||||||
"columns": ["time","f1"],
|
"columns": ["time","fa","fc","fb"],
|
||||||
"values": [[1000, 1],[2000, 2]],
|
"values": [
|
||||||
|
[1000, 20, 10, 10],
|
||||||
|
[2000, 30, 15, 9],
|
||||||
|
[3000, 40, 20, 8],
|
||||||
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"series": [
|
"series": [
|
||||||
{
|
{
|
||||||
"name":"mc",
|
"name":"mb",
|
||||||
"columns": ["time","f2"],
|
"columns": ["time","fa","fc","fb"],
|
||||||
"values": [[2000, 3],[4000, 4]],
|
"values": [
|
||||||
},
|
[1000, 200, 100, 100],
|
||||||
]
|
[2000, 300, 150, 90],
|
||||||
},
|
[3000, 400, 200, 80],
|
||||||
{
|
],
|
||||||
"series": [
|
|
||||||
{
|
|
||||||
"name":"mc",
|
|
||||||
"columns": ["time","f1"],
|
|
||||||
"values": [[2000, 3],[4000, 4]],
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -371,14 +361,25 @@ describe('timeSeriesToDygraph', () => {
|
||||||
|
|
||||||
const actual = timeSeriesToDygraph(influxResponse);
|
const actual = timeSeriesToDygraph(influxResponse);
|
||||||
|
|
||||||
const expected = [
|
const expected = {
|
||||||
'time',
|
labels: [
|
||||||
`ma.f1`,
|
'time',
|
||||||
`mb.f1`,
|
`ma.fa`,
|
||||||
`mc.f1`,
|
`ma.fb`,
|
||||||
`mc.f2`,
|
`ma.fc`,
|
||||||
];
|
`mb.fa`,
|
||||||
|
`mb.fb`,
|
||||||
|
`mb.fc`,
|
||||||
|
],
|
||||||
|
timeSeries: [
|
||||||
|
[new Date(1000), 20, 10, 10],
|
||||||
|
[new Date(2000), 30, 9, 15],
|
||||||
|
[new Date(3000), 40, 8, 20],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
expect(actual.labels).to.deep.equal(expected);
|
console.log(actual.timeSeries);
|
||||||
|
expect(actual.labels).to.deep.equal(expected.labels);
|
||||||
|
expect(actual.timeSeries).to.deep.equal(expected.timeSeries);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -79,14 +79,20 @@ export default function timeSeriesToDygraph(raw = [], activeQueryIndex, isInData
|
||||||
*/
|
*/
|
||||||
const measurementName = series.name;
|
const measurementName = series.name;
|
||||||
const columns = series.columns;
|
const columns = series.columns;
|
||||||
|
|
||||||
// Tags are only included in an influxdb response under certain circumstances, e.g.
|
// Tags are only included in an influxdb response under certain circumstances, e.g.
|
||||||
// when a query is using GROUP BY (<tag key>).
|
// when a query is using GROUP BY (<tag key>).
|
||||||
const tags = Object.keys(series.tags || {}).map((key) => {
|
const tags = Object.keys(series.tags || {}).map((key) => {
|
||||||
return `[${key}=${series.tags[key]}]`;
|
return `[${key}=${series.tags[key]}]`;
|
||||||
}).sort().join('');
|
}).sort().join('');
|
||||||
|
|
||||||
columns.slice(1).forEach((fieldName) => {
|
const c = columns.slice(1).sort();
|
||||||
|
let previousColumnLength = 0;
|
||||||
|
|
||||||
|
if (c.length != previousColumnLength) {
|
||||||
|
previousColumnLength = c.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
c.forEach((fieldName) => {
|
||||||
let effectiveFieldName = `${measurementName}.${fieldName}${tags}`;
|
let effectiveFieldName = `${measurementName}.${fieldName}${tags}`;
|
||||||
|
|
||||||
// If there are duplicate effectiveFieldNames identify them by their queryIndex
|
// If there are duplicate effectiveFieldNames identify them by their queryIndex
|
||||||
|
@ -96,7 +102,7 @@ export default function timeSeriesToDygraph(raw = [], activeQueryIndex, isInData
|
||||||
|
|
||||||
// Given a field name, identify which column in the timeSeries result should hold the field's value
|
// Given a field name, identify which column in the timeSeries result should hold the field's value
|
||||||
// ex given this timeSeries [Date, 10, 20, 30] field index at 2 would correspond to value 20
|
// ex given this timeSeries [Date, 10, 20, 30] field index at 2 would correspond to value 20
|
||||||
fieldToIndex[effectiveFieldName] = labels.length + 1;
|
fieldToIndex[effectiveFieldName] = c.indexOf(fieldName) + previousColumnLength;
|
||||||
labels.push(effectiveFieldName);
|
labels.push(effectiveFieldName);
|
||||||
|
|
||||||
const {light, heavy} = STROKE_WIDTH;
|
const {light, heavy} = STROKE_WIDTH;
|
||||||
|
@ -156,6 +162,7 @@ export default function timeSeriesToDygraph(raw = [], activeQueryIndex, isInData
|
||||||
row[0] = new Date(dates[date]);
|
row[0] = new Date(dates[date]);
|
||||||
|
|
||||||
const fieldsForRow = dateToFieldValue[date];
|
const fieldsForRow = dateToFieldValue[date];
|
||||||
|
|
||||||
Object.keys(fieldsForRow).forEach((effectiveFieldName) => {
|
Object.keys(fieldsForRow).forEach((effectiveFieldName) => {
|
||||||
row[fieldToIndex[effectiveFieldName]] = fieldsForRow[effectiveFieldName];
|
row[fieldToIndex[effectiveFieldName]] = fieldsForRow[effectiveFieldName];
|
||||||
});
|
});
|
||||||
|
@ -178,4 +185,3 @@ function isEmpty(resp) {
|
||||||
function hasError(resp) {
|
function hasError(resp) {
|
||||||
return !!resp.results[0].error;
|
return !!resp.results[0].error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue