diff --git a/public/app/features/dimensions/utils.ts b/public/app/features/dimensions/utils.ts index f04c597027b..3e762cc5841 100644 --- a/public/app/features/dimensions/utils.ts +++ b/public/app/features/dimensions/utils.ts @@ -93,11 +93,11 @@ export function getTextDimensionFromData( } export function findField(frame?: DataFrame, name?: string): Field | undefined { - const idx = findFieldIndex(frame, name); + const idx = findFieldIndex(name, frame); return idx == null ? undefined : frame!.fields[idx]; } -export function findFieldIndex(frame?: DataFrame, name?: string): number | undefined { +export function findFieldIndex(name?: string, frame?: DataFrame, frames?: DataFrame[]): number | undefined { if (!frame || !name?.length) { return undefined; } @@ -107,7 +107,7 @@ export function findFieldIndex(frame?: DataFrame, name?: string): number | undef if (name === field.name) { return i; } - const disp = getFieldDisplayName(field, frame); + const disp = getFieldDisplayName(field, frame, frames); if (name === disp) { return i; } diff --git a/public/app/plugins/panel/trend/TrendPanel.tsx b/public/app/plugins/panel/trend/TrendPanel.tsx index e5371dca263..59aee22776d 100644 --- a/public/app/plugins/panel/trend/TrendPanel.tsx +++ b/public/app/plugins/panel/trend/TrendPanel.tsx @@ -49,7 +49,7 @@ export const TrendPanel = ({ let frames = data.series; let xFieldIdx: number | undefined; if (options.xField) { - xFieldIdx = findFieldIndex(frames[0], options.xField); + xFieldIdx = findFieldIndex(options.xField, frames[0]); if (xFieldIdx == null) { return { warning: 'Unable to find field: ' + options.xField, diff --git a/public/app/plugins/panel/xychart/scatter.ts b/public/app/plugins/panel/xychart/scatter.ts index f112be980e8..a4d6b5e9043 100644 --- a/public/app/plugins/panel/xychart/scatter.ts +++ b/public/app/plugins/panel/xychart/scatter.ts @@ -225,11 +225,11 @@ function prepSeries(options: Options, frames: DataFrame[]): ScatterSeries[] { for (let frameIndex = 0; frameIndex < frames.length; frameIndex++) { const frame = frames[frameIndex]; - const xIndex = findFieldIndex(frame, series.x); + const xIndex = findFieldIndex(series.x, frame, frames); if (xIndex != null) { // TODO: this should find multiple y fields - const yIndex = findFieldIndex(frame, series.y); + const yIndex = findFieldIndex(series.y, frame, frames); if (yIndex == null) { throw 'Y must be in the same frame as X'; @@ -237,9 +237,9 @@ function prepSeries(options: Options, frames: DataFrame[]): ScatterSeries[] { const dims: Dims = { pointColorFixed: series.pointColor?.fixed, - pointColorIndex: findFieldIndex(frame, series.pointColor?.field), + pointColorIndex: findFieldIndex(series.pointColor?.field, frame, frames), pointSizeConfig: series.pointSize, - pointSizeIndex: findFieldIndex(frame, series.pointSize?.field), + pointSizeIndex: findFieldIndex(series.pointSize?.field, frame, frames), }; scatterSeries.push(getScatterSeries(seriesIndex++, frames, frameIndex, xIndex, yIndex, dims)); } @@ -255,7 +255,7 @@ function prepSeries(options: Options, frames: DataFrame[]): ScatterSeries[] { const frame = frames[frameIndex]; const numericIndices: number[] = []; - let xIndex = findFieldIndex(frame, dims.x); + let xIndex = findFieldIndex(dims.x, frame, frames); for (let i = 0; i < frame.fields.length; i++) { if (isGraphable(frame.fields[i])) { if (xIndex == null || i === xIndex) {