Skip to content

Commit

Permalink
XYChart2: Remove common series name from tooltip items (#86739)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7754d0d)
  • Loading branch information
leeoniya authored and grafana-delivery-bot[bot] committed Apr 23, 2024
1 parent 6271513 commit 3b57b64
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions public/app/plugins/panel/xychart/v2/XYChartTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export interface Props {
xySeries: XYSeries[];
}

function stripSeriesName(fieldName: string, seriesName: string) {
if (fieldName.includes(' ')) {
fieldName = fieldName.replace(seriesName, '').trim();
}

return fieldName;
}

export const XYChartTooltip = ({ dataIdxs, seriesIdx, data, xySeries, dismiss, isPinned }: Props) => {
const styles = useStyles2(getStyles);

Expand Down Expand Up @@ -51,18 +59,18 @@ export const XYChartTooltip = ({ dataIdxs, seriesIdx, data, xySeries, dismiss, i

const contentItems: VizTooltipItem[] = [
{
label: xField.state?.displayName ?? xField.name,
label: stripSeriesName(xField.state?.displayName ?? xField.name, label),
value: fmt(xField, xField.values[rowIndex]),
},
{
label: yField.state?.displayName ?? yField.name,
label: stripSeriesName(yField.state?.displayName ?? yField.name, label),
value: fmt(yField, yField.values[rowIndex]),
},
];

series._rest.forEach((field) => {
contentItems.push({
label: field.state?.displayName ?? field.name,
label: stripSeriesName(field.state?.displayName ?? field.name, label),
value: fmt(field, field.values[rowIndex]),
});
});
Expand Down

0 comments on commit 3b57b64

Please sign in to comment.