|
1 | 1 | import { ReactNode } from 'react'; |
2 | 2 |
|
3 | | -import { colorManipulator, DataFrame, InterpolateFunction, LinkModel } from '@grafana/data'; |
| 3 | +import { colorManipulator, DataFrame, Field, InterpolateFunction, LinkModel } from '@grafana/data'; |
4 | 4 | import { |
5 | 5 | VizTooltipContent, |
6 | 6 | VizTooltipFooter, |
@@ -34,6 +34,14 @@ function stripSeriesName(fieldName: string, seriesName: string) { |
34 | 34 | return fieldName; |
35 | 35 | } |
36 | 36 |
|
| 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 | + |
37 | 45 | export const XYChartTooltip = ({ |
38 | 46 | dataIdxs, |
39 | 47 | seriesIdx, |
@@ -70,37 +78,49 @@ export const XYChartTooltip = ({ |
70 | 78 | colorIndicator: ColorIndicator.marker_md, |
71 | 79 | }; |
72 | 80 |
|
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), |
76 | 87 | 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), |
80 | 95 | value: fmt(yField, yField.values[rowIndex]), |
81 | | - }, |
82 | | - ]; |
| 96 | + }); |
| 97 | + addedFields.add(yField); |
| 98 | + } |
83 | 99 |
|
84 | 100 | // mapped fields for size/color |
85 | | - if (sizeField != null && sizeField !== yField) { |
| 101 | + if (sizeField != null && !addedFields.has(sizeField) && !hideFromTooltip(sizeField)) { |
86 | 102 | contentItems.push({ |
87 | | - label: stripSeriesName(sizeField.state?.displayName ?? sizeField.name, label), |
| 103 | + label: stripSeriesName(getFieldName(sizeField), label), |
88 | 104 | value: fmt(sizeField, sizeField.values[rowIndex]), |
89 | 105 | }); |
| 106 | + addedFields.add(sizeField); |
90 | 107 | } |
91 | 108 |
|
92 | | - if (colorField != null && colorField !== yField) { |
| 109 | + if (colorField != null && !addedFields.has(colorField) && !hideFromTooltip(colorField)) { |
93 | 110 | contentItems.push({ |
94 | | - label: stripSeriesName(colorField.state?.displayName ?? colorField.name, label), |
| 111 | + label: stripSeriesName(getFieldName(colorField), label), |
95 | 112 | value: fmt(colorField, colorField.values[rowIndex]), |
96 | 113 | }); |
| 114 | + addedFields.add(colorField); |
97 | 115 | } |
98 | 116 |
|
99 | 117 | 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 | + } |
104 | 124 | }); |
105 | 125 |
|
106 | 126 | let footer: ReactNode; |
|
0 commit comments