fix: Incorrect hovered items in tooltips (#30405)

This commit is contained in:
Michael S. Molina 2024-09-26 16:08:59 -03:00 committed by GitHub
parent 0fdcd8b27e
commit 36f7a3f524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 11 deletions

View File

@ -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,
@ -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: {

View File

@ -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) {
@ -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)];
@ -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: {