Skip to content

Commit

Permalink
fix for erroring out when invalid value field is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
KatrinaTurner committed Apr 30, 2024
1 parent 99c5d9e commit fc27e48
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/dataParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DataFrameView, Field, getFieldDisplayName, Vector } from '@grafana/data
* @return {valueField[0]}
*/
export function parseData(data: { series: any[] }, options: { valueField: any }, monochrome: boolean, color: any) {
const valueFieldName = options.valueField;


/**
* Colors
Expand Down Expand Up @@ -126,13 +126,25 @@ export function parseData(data: { series: any[] }, options: { valueField: any },
});

// Find selected value field or default to the first number field and use for values.
const valueField = valueFieldName
? data.series.map((series: { fields: any[] }) =>
series.fields.find((field: { name: any }) => field.name === valueFieldName)
)
: data.series.map((series: { fields: any[] }) =>
// const valueFieldName = options.valueField;
// const valueField = options.valueField
// ? data.series.map((series: { fields: any[] }) =>
// series.fields.find((field: { name: any }) => field.name === options.valueField)
// )
// : data.series.map((series: { fields: any[] }) =>
// series.fields.find((field: { type: string }) => field.type === 'number')
// );
// Fix to avoid erroring out when value field is hidden by transform
let valueField = data.series.map((series: { fields: any[] }) =>
series.fields.find((field: { name: any }) => field.name === options.valueField)
)
if(!valueField[0]) {
valueField = data.series.map((series: { fields: any[] }) =>
series.fields.find((field: { type: string }) => field.type === 'number')
);
}



let values = [];
valueField[0].values.map((value: any) => {
Expand Down

0 comments on commit fc27e48

Please sign in to comment.