mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
GraphNG: Ignore string fields when building data for uPlot in GraphNG (#32150)
This commit is contained in:
parent
ea484312a0
commit
fb337e5c1d
@ -7,6 +7,7 @@ import {
|
|||||||
DataFrameFieldIndex,
|
DataFrameFieldIndex,
|
||||||
FieldMatcherID,
|
FieldMatcherID,
|
||||||
fieldMatchers,
|
fieldMatchers,
|
||||||
|
FieldType,
|
||||||
TimeRange,
|
TimeRange,
|
||||||
TimeZone,
|
TimeZone,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
@ -92,7 +93,7 @@ class UnthemedGraphNG extends React.Component<GraphNGProps, GraphNGState> {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
data: preparePlotData(frame),
|
data: preparePlotData(frame, [FieldType.string]),
|
||||||
alignedDataFrame: frame,
|
alignedDataFrame: frame,
|
||||||
seriesToDataFrameFieldIndexMap: frame.fields.map((f) => f.state!.origin!),
|
seriesToDataFrameFieldIndexMap: frame.fields.map((f) => f.state!.origin!),
|
||||||
dimFields,
|
dimFields,
|
||||||
|
@ -33,21 +33,31 @@ export function buildPlotConfig(props: PlotProps, plugins: Record<string, PlotPl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export function preparePlotData(frame: DataFrame): AlignedData {
|
export function preparePlotData(frame: DataFrame, ignoreFieldTypes?: FieldType[]): AlignedData {
|
||||||
return frame.fields.map((f) => {
|
const result: any[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < frame.fields.length; i++) {
|
||||||
|
const f = frame.fields[i];
|
||||||
|
|
||||||
if (f.type === FieldType.time) {
|
if (f.type === FieldType.time) {
|
||||||
if (f.values.length > 0 && typeof f.values.get(0) === 'string') {
|
if (f.values.length > 0 && typeof f.values.get(0) === 'string') {
|
||||||
const timestamps = [];
|
const timestamps = [];
|
||||||
for (let i = 0; i < f.values.length; i++) {
|
for (let i = 0; i < f.values.length; i++) {
|
||||||
timestamps.push(dateTime(f.values.get(i)).valueOf());
|
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();
|
if (ignoreFieldTypes && ignoreFieldTypes.indexOf(f.type) > -1) {
|
||||||
}) as AlignedData;
|
continue;
|
||||||
|
}
|
||||||
|
result.push(f.values.toArray());
|
||||||
|
}
|
||||||
|
return result as AlignedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dev helpers
|
// Dev helpers
|
||||||
|
Loading…
Reference in New Issue
Block a user