Skip to content

Commit d43606c

Browse files
authored
XYChart: Fix hideFrom.tooltip (#108359)
1 parent 66323b2 commit d43606c

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

public/app/plugins/panel/xychart/XYChartTooltip.tsx

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReactNode } from 'react';
22

3-
import { colorManipulator, DataFrame, InterpolateFunction, LinkModel } from '@grafana/data';
3+
import { colorManipulator, DataFrame, Field, InterpolateFunction, LinkModel } from '@grafana/data';
44
import {
55
VizTooltipContent,
66
VizTooltipFooter,
@@ -34,6 +34,14 @@ function stripSeriesName(fieldName: string, seriesName: string) {
3434
return fieldName;
3535
}
3636

37+
function hideFromTooltip(field: Field) {
38+
return field.config.custom.hideFrom?.tooltip ?? false;
39+
}
40+
41+
function getFieldName(field: Field) {
42+
return field.state?.displayName ?? field.name;
43+
}
44+
3745
export const XYChartTooltip = ({
3846
dataIdxs,
3947
seriesIdx,
@@ -70,37 +78,49 @@ export const XYChartTooltip = ({
7078
colorIndicator: ColorIndicator.marker_md,
7179
};
7280

73-
const contentItems: VizTooltipItem[] = [
74-
{
75-
label: stripSeriesName(xField.state?.displayName ?? xField.name, label),
81+
const contentItems: VizTooltipItem[] = [];
82+
const addedFields = new Set<Field>();
83+
84+
if (!hideFromTooltip(xField)) {
85+
contentItems.push({
86+
label: stripSeriesName(getFieldName(xField), label),
7687
value: fmt(xField, xField.values[rowIndex]),
77-
},
78-
{
79-
label: stripSeriesName(yField.state?.displayName ?? yField.name, label),
88+
});
89+
addedFields.add(xField);
90+
}
91+
92+
if (!hideFromTooltip(yField)) {
93+
contentItems.push({
94+
label: stripSeriesName(getFieldName(yField), label),
8095
value: fmt(yField, yField.values[rowIndex]),
81-
},
82-
];
96+
});
97+
addedFields.add(yField);
98+
}
8399

84100
// mapped fields for size/color
85-
if (sizeField != null && sizeField !== yField) {
101+
if (sizeField != null && !addedFields.has(sizeField) && !hideFromTooltip(sizeField)) {
86102
contentItems.push({
87-
label: stripSeriesName(sizeField.state?.displayName ?? sizeField.name, label),
103+
label: stripSeriesName(getFieldName(sizeField), label),
88104
value: fmt(sizeField, sizeField.values[rowIndex]),
89105
});
106+
addedFields.add(sizeField);
90107
}
91108

92-
if (colorField != null && colorField !== yField) {
109+
if (colorField != null && !addedFields.has(colorField) && !hideFromTooltip(colorField)) {
93110
contentItems.push({
94-
label: stripSeriesName(colorField.state?.displayName ?? colorField.name, label),
111+
label: stripSeriesName(getFieldName(colorField), label),
95112
value: fmt(colorField, colorField.values[rowIndex]),
96113
});
114+
addedFields.add(colorField);
97115
}
98116

99117
series._rest.forEach((field) => {
100-
contentItems.push({
101-
label: stripSeriesName(field.state?.displayName ?? field.name, label),
102-
value: fmt(field, field.values[rowIndex]),
103-
});
118+
if (!hideFromTooltip(field)) {
119+
contentItems.push({
120+
label: stripSeriesName(field.state?.displayName ?? field.name, label),
121+
value: fmt(field, field.values[rowIndex]),
122+
});
123+
}
104124
});
105125

106126
let footer: ReactNode;

0 commit comments

Comments
 (0)