Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #7152 (Hover label on category sometimes shows label from neighbo…
…ring category)

Now, data points within hoverdistance but outside the hovered category are omitted from the hover label.
Within the category, the hoverdistance still filters away too distant data points.
  • Loading branch information
my-tien committed Aug 13, 2026
commit 015d3f0659c1563c181e0e920575c431c5c2388b
15 changes: 15 additions & 0 deletions src/components/fx/hover.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an improvement, but I still see the same issue when hovering over the center or left side of the Other bar (from the issue figure). We need to add a filter looking at the category under the cursor before the spike line and winning point are chosen to handle that case. Could you please look into that? I have a solution that I've tested locally and I can push that if you'd like.

Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,21 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
for (k = hoverData.length - 1; k > initLen - 1; k--) {
insert(hoverData[k]);
}

// on category axes only keep points that fall in the hovered category
var winAx = winningPoint[axLetter + 'a'];
if (winAx && (winAx.type === 'category' || winAx.type === 'multicategory')) {
var winCat = winningPoint[axLetter + 'LabelVal'];
finalPoints = finalPoints.filter(function (point) {
var pointAx = point[axLetter + 'a'];
if (!pointAx || (pointAx.type !== 'category' && pointAx.type !== 'multicategory')) {
// rare case of data point on overlaying axis
return true;
}
return point[axLetter + 'LabelVal'] === winCat;
});
}

hoverData = finalPoints;
sortHoverData();
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/fx/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ module.exports = {
'This is only a real distance for hovering on point-like objects,',
'like scatter points. For area-like objects (bars, scatter fills, etc)',
'hovering is on inside the area and off outside, but these objects',
'will not supersede hover on point-like objects in case of conflict.'
'will not supersede hover on point-like objects in case of conflict.',
'For hovermodes *x*, *y*, *x unified* and *y unified*',
'on a category axis, only points that fall in the hovered category',
'are shown in the hover label, regardless of this distance.'
].join(' ')
},
spikedistance: {
Expand Down
Loading