BarChart: Check by displayName (#71161)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Adela Almasan 2023-07-06 20:56:36 -05:00 committed by GitHub
parent c87de8305c
commit bde9478c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View File

@ -43,6 +43,14 @@ export function getFrameDisplayName(frame: DataFrame, index?: number) {
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 {
const existingTitle = field.state?.displayName;
const multipleFrames = Boolean(allFrames && allFrames.length > 1);

View File

@ -14,5 +14,5 @@ export { FieldConfigOptionsRegistry } from './FieldConfigOptionsRegistry';
export { sortThresholds, getActiveThreshold } from './thresholds';
export { applyFieldOverrides, validateFieldConfig, applyRawFieldOverrides, useFieldOverrides } from './fieldOverrides';
export { getFieldDisplayValuesProxy } from './getFieldDisplayValuesProxy';
export { getFieldDisplayName, getFrameDisplayName } from './fieldState';
export { getFieldDisplayName, getFrameDisplayName, cacheFieldDisplayNames } from './fieldState';
export { getScaleCalculator, getFieldConfigWithMinMax, getMinMaxAndDelta } from './scale';

View File

@ -7,6 +7,7 @@ import {
formattedValueToString,
getDisplayProcessor,
getFieldColorModeForField,
cacheFieldDisplayNames,
getFieldSeriesColor,
GrafanaTheme2,
outerJoinDataFrames,
@ -362,6 +363,8 @@ export function prepareBarChartDisplayValues(
return { warn: 'No data in response' };
}
cacheFieldDisplayNames(series);
// Bar chart requires a single frame
const frame =
series.length === 1
@ -475,12 +478,7 @@ export function prepareBarChartDisplayValues(
let legendFields: Field[] = fields;
if (options.stacking === StackingMode.Percent) {
legendFields = fields.map((field) => {
const alignedFrameField = frame.fields.find((f) => {
if (f.labels) {
return f.name === field.name && f.labels.name === field.labels?.name;
}
return f.name === field.name;
})!;
const alignedFrameField = frame.fields.find((f) => f.state?.displayName === field.state?.displayName)!;
const copy = {
...field,