GraphNG: Ignore string fields when building data for uPlot in GraphNG (#32150) (#32151)

(cherry picked from commit fb337e5c1d)

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2021-03-19 11:25:44 +01:00
committed by GitHub
co-authored by Dominik Prokop
parent fbf3469e80
commit 1df1d60e1e
2 changed files with 18 additions and 7 deletions
@@ -7,6 +7,7 @@ import {
DataFrameFieldIndex,
FieldMatcherID,
fieldMatchers,
FieldType,
TimeRange,
TimeZone,
} from '@grafana/data';
@@ -89,7 +90,7 @@ class UnthemedGraphNG extends React.Component<GraphNGProps, GraphNGState> {
return {
...state,
data: preparePlotData(frame),
data: preparePlotData(frame, [FieldType.string]),
alignedDataFrame: frame,
seriesToDataFrameFieldIndexMap: frame.fields.map((f) => f.state!.origin!),
dimFields,
@@ -33,21 +33,31 @@ export function buildPlotConfig(props: PlotProps, plugins: Record<string, PlotPl
}
/** @internal */
export function preparePlotData(frame: DataFrame): AlignedData {
return frame.fields.map((f) => {
export function preparePlotData(frame: DataFrame, ignoreFieldTypes?: FieldType[]): AlignedData {
const result: any[] = [];
for (let i = 0; i < frame.fields.length; i++) {
const f = frame.fields[i];
if (f.type === FieldType.time) {
if (f.values.length > 0 && typeof f.values.get(0) === 'string') {
const timestamps = [];
for (let i = 0; i < f.values.length; i++) {
timestamps.push(dateTime(f.values.get(i)).valueOf());
}
return timestamps;
result.push(timestamps);
continue;
}
return f.values.toArray();
result.push(f.values.toArray());
continue;
}
return f.values.toArray();
}) as AlignedData;
if (ignoreFieldTypes && ignoreFieldTypes.indexOf(f.type) > -1) {
continue;
}
result.push(f.values.toArray());
}
return result as AlignedData;
}
// Dev helpers