mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
BarChart: Check by displayName (#71161)
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
parent
c87de8305c
commit
bde9478c5e
@ -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);
|
||||
|
@ -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';
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user