Skip to content

Commit

Permalink
fix: Incorrect hovered items in tooltips (apache#30405)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Sep 26, 2024
1 parent 0fdcd8b commit 36f7a3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ export default function transformProps(
extractForecastValuesFromTooltipParams(forecastValue);

const keys = Object.keys(forecastValues);
let focusedRow;
keys.forEach(key => {
const value = forecastValues[key];
// if there are no dimensions, key is a verbose name of a metric,
Expand Down Expand Up @@ -627,12 +628,11 @@ export default function transformProps(
: tooltipFormatterSecondary,
});
rows.push(row);
if (key === focusedSeries) {
focusedRow = rows.length - 1;
}
});
return tooltipHtml(
rows,
tooltipFormatter(xValue),
keys.findIndex(key => key === focusedSeries),
);
return tooltipHtml(rows, tooltipFormatter(xValue), focusedRow);
},
},
legend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ export default function transformProps(
const showTotal = Boolean(isMultiSeries) && richTooltip && !isForecast;
const showPercentage = showTotal && !forcePercentFormatter;
const keys = Object.keys(forecastValues);
let focusedRow;
keys.forEach(key => {
const value = forecastValues[key];
if (value.observation === 0 && stack) {
Expand All @@ -583,10 +584,15 @@ export default function transformProps(
row.push(percentFormatter.format(value.observation / (total || 1)));
}
rows.push(row);
if (key === focusedSeries) {
focusedRow = rows.length - 1;
}
});
if (stack) {
keys.reverse();
rows.reverse();
if (focusedRow) {
focusedRow = rows.length - focusedRow - 1;
}
}
if (showTotal) {
const totalRow = ['Total', formatter.format(total)];
Expand All @@ -595,11 +601,7 @@ export default function transformProps(
}
rows.push(totalRow);
}
return tooltipHtml(
rows,
tooltipFormatter(xValue),
keys.findIndex(key => key === focusedSeries),
);
return tooltipHtml(rows, tooltipFormatter(xValue), focusedRow);
},
},
legend: {
Expand Down

0 comments on commit 36f7a3f

Please sign in to comment.