mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
GraphNG: Fix PlotLegend field display name being outdated (#32064)
This commit is contained in:
parent
c8d8dcd067
commit
48f46a597f
@ -1,5 +1,5 @@
|
|||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { DataFrame, DisplayValue, fieldReducers, reduceField } from '@grafana/data';
|
import { DataFrame, DisplayValue, fieldReducers, getFieldDisplayName, reduceField } from '@grafana/data';
|
||||||
import { UPlotConfigBuilder } from './config/UPlotConfigBuilder';
|
import { UPlotConfigBuilder } from './config/UPlotConfigBuilder';
|
||||||
import { VizLegendItem, VizLegendOptions } from '../VizLegend/types';
|
import { VizLegendItem, VizLegendOptions } from '../VizLegend/types';
|
||||||
import { AxisPlacement } from './config';
|
import { AxisPlacement } from './config';
|
||||||
@ -55,12 +55,13 @@ export const PlotLegend: React.FC<PlotLegendProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex];
|
const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex];
|
||||||
|
const label = getFieldDisplayName(field, data[fieldIndex.frameIndex]!);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
disabled: !seriesConfig.show ?? false,
|
disabled: !seriesConfig.show ?? false,
|
||||||
fieldIndex,
|
fieldIndex,
|
||||||
color: seriesConfig.lineColor!,
|
color: seriesConfig.lineColor!,
|
||||||
label: seriesConfig.fieldName,
|
label,
|
||||||
yAxis: axisPlacement === AxisPlacement.Left ? 1 : 2,
|
yAxis: axisPlacement === AxisPlacement.Left ? 1 : 2,
|
||||||
getDisplayValues: () => {
|
getDisplayValues: () => {
|
||||||
if (!calcs?.length) {
|
if (!calcs?.length) {
|
||||||
@ -80,6 +81,7 @@ export const PlotLegend: React.FC<PlotLegendProps> = ({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
getItemKey: () => `${label}-${fieldIndex.frameIndex}-${fieldIndex.fieldIndex}`,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter((i) => i !== undefined) as VizLegendItem[];
|
.filter((i) => i !== undefined) as VizLegendItem[];
|
||||||
|
Loading…
Reference in New Issue
Block a user