[v10.0.x] BarChart: Check by displayName (#71165)
This commit is contained in:
@@ -36,6 +36,14 @@ export function getFrameDisplayName(frame: DataFrame, index?: number) {
|
|||||||
return `Series (${index})`;
|
return `Series (${index})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cacheFieldDisplayNames(frames: DataFrame[]) {
|
||||||
|
frames.forEach((frame) => {
|
||||||
|
frame.fields.forEach((field) => {
|
||||||
|
getFieldDisplayName(field, frame, frames);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function getFieldDisplayName(field: Field, frame?: DataFrame, allFrames?: DataFrame[]): string {
|
export function getFieldDisplayName(field: Field, frame?: DataFrame, allFrames?: DataFrame[]): string {
|
||||||
const existingTitle = field.state?.displayName;
|
const existingTitle = field.state?.displayName;
|
||||||
const multipleFrames = Boolean(allFrames && allFrames.length > 1);
|
const multipleFrames = Boolean(allFrames && allFrames.length > 1);
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ export { FieldConfigOptionsRegistry } from './FieldConfigOptionsRegistry';
|
|||||||
export { sortThresholds, getActiveThreshold } from './thresholds';
|
export { sortThresholds, getActiveThreshold } from './thresholds';
|
||||||
export { applyFieldOverrides, validateFieldConfig, applyRawFieldOverrides, useFieldOverrides } from './fieldOverrides';
|
export { applyFieldOverrides, validateFieldConfig, applyRawFieldOverrides, useFieldOverrides } from './fieldOverrides';
|
||||||
export { getFieldDisplayValuesProxy } from './getFieldDisplayValuesProxy';
|
export { getFieldDisplayValuesProxy } from './getFieldDisplayValuesProxy';
|
||||||
export { getFieldDisplayName, getFrameDisplayName } from './fieldState';
|
export { getFieldDisplayName, getFrameDisplayName, cacheFieldDisplayNames } from './fieldState';
|
||||||
export { getScaleCalculator, getFieldConfigWithMinMax, getMinMaxAndDelta } from './scale';
|
export { getScaleCalculator, getFieldConfigWithMinMax, getMinMaxAndDelta } from './scale';
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
formattedValueToString,
|
formattedValueToString,
|
||||||
getDisplayProcessor,
|
getDisplayProcessor,
|
||||||
getFieldColorModeForField,
|
getFieldColorModeForField,
|
||||||
|
cacheFieldDisplayNames,
|
||||||
getFieldSeriesColor,
|
getFieldSeriesColor,
|
||||||
GrafanaTheme2,
|
GrafanaTheme2,
|
||||||
outerJoinDataFrames,
|
outerJoinDataFrames,
|
||||||
@@ -364,6 +365,8 @@ export function prepareBarChartDisplayValues(
|
|||||||
return { warn: 'No data in response' };
|
return { warn: 'No data in response' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cacheFieldDisplayNames(series);
|
||||||
|
|
||||||
// Bar chart requires a single frame
|
// Bar chart requires a single frame
|
||||||
const frame =
|
const frame =
|
||||||
series.length === 1
|
series.length === 1
|
||||||
@@ -489,12 +492,7 @@ export function prepareBarChartDisplayValues(
|
|||||||
let legendFields: Field[] = fields;
|
let legendFields: Field[] = fields;
|
||||||
if (options.stacking === StackingMode.Percent) {
|
if (options.stacking === StackingMode.Percent) {
|
||||||
legendFields = fields.map((field) => {
|
legendFields = fields.map((field) => {
|
||||||
const alignedFrameField = frame.fields.find((f) => {
|
const alignedFrameField = frame.fields.find((f) => f.state?.displayName === field.state?.displayName)!;
|
||||||
if (f.labels) {
|
|
||||||
return f.name === field.name && f.labels.name === field.labels?.name;
|
|
||||||
}
|
|
||||||
return f.name === field.name;
|
|
||||||
})!;
|
|
||||||
|
|
||||||
const copy = {
|
const copy = {
|
||||||
...field,
|
...field,
|
||||||
|
|||||||
Reference in New Issue
Block a user