mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
XYChart: Fix series names in legend and tooltip when y field is renamed (#98470)
This commit is contained in:
parent
0d8a71c664
commit
aac8626326
@ -124,7 +124,40 @@ export function prepSeries(
|
||||
// if we match non-excluded y, create series
|
||||
if (yMatcher(field, frame, frames) && !field.config.custom?.hideFrom?.viz) {
|
||||
let y = field;
|
||||
let name = seriesCfg.name?.fixed ?? getFieldDisplayName(y, frame, frames);
|
||||
|
||||
let name = seriesCfg.name?.fixed;
|
||||
|
||||
if (name == null) {
|
||||
// if the displayed field name is likely to have a common prefix or suffix
|
||||
// (such as those from Partition by values transformation)
|
||||
const likelyHasCommonParts =
|
||||
frames.length > 1 && (frame.name != null || Object.keys(y.labels ?? {}).length > 0);
|
||||
|
||||
// if the field was explictly (re)named using config.displayName or config.displayNameFromDS
|
||||
// we still want to retain any frame name prefix or suffix so that autoNameSeries() can
|
||||
// properly detect + strip common parts across all series...
|
||||
const { displayName, displayNameFromDS } = y.config;
|
||||
const hasExplicitName = displayName != null || displayNameFromDS != null;
|
||||
|
||||
if (likelyHasCommonParts && hasExplicitName) {
|
||||
// ...and a hacky way to do this is to temp remove the explicit name, get the auto name, then revert
|
||||
const stateDisplayName = y.state!.displayName;
|
||||
|
||||
// clear config and cache
|
||||
y.config.displayName = y.config.displayNameFromDS = y.state!.displayName = undefined;
|
||||
// get default/calculated display name (maybe use calculateFieldDisplayName() here instead?)
|
||||
name = getFieldDisplayName(y, frame, frames);
|
||||
// replace original field name with explicit one
|
||||
name = name.replace(y.name, (displayNameFromDS ?? displayName)!);
|
||||
|
||||
// revert
|
||||
y.config.displayName = displayName;
|
||||
y.config.displayNameFromDS = displayNameFromDS;
|
||||
y.state!.displayName = stateDisplayName;
|
||||
} else {
|
||||
name = getFieldDisplayName(y, frame, frames);
|
||||
}
|
||||
}
|
||||
|
||||
let ser: XYSeries = {
|
||||
// these typically come from y field
|
||||
|
Loading…
Reference in New Issue
Block a user