Skip to content

Commit

Permalink
Fix conversion to wide data frame, fixes #1309
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Sep 22, 2021
1 parent b65a638 commit d3bf7eb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/datasource-zabbix/responseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ export function alignFrames(data: MutableDataFrame[]): MutableDataFrame[] {
}

export function convertToWide(data: MutableDataFrame[]): DataFrame[] {
const timeField = data[0].fields.find(f => f.type === FieldType.time);
const maxLengthIndex = getLongestFrame(data);
const timeField = data[maxLengthIndex].fields.find(f => f.type === FieldType.time);
if (!timeField) {
return [];
}
Expand Down Expand Up @@ -347,6 +348,20 @@ export function convertToWide(data: MutableDataFrame[]): DataFrame[] {
return [frame];
}

function getLongestFrame(data: MutableDataFrame[]): number {
let maxLengthIndex = 0;
let maxLength = 0;
for (let i = 0; i < data.length; i++) {
const timeField = data[i].fields.find(f => f.type === FieldType.time);
if (timeField.values.length > maxLength) {
maxLength = timeField.values.length;
maxLengthIndex = i;
}
}

return maxLengthIndex;
}

function sortTimeseries(timeseries) {
// Sort trend data, issue #202
_.forEach(timeseries, series => {
Expand Down

0 comments on commit d3bf7eb

Please sign in to comment.