Skip to content

Commit 0426f42

Browse files
author
Daniel Gröger
committed
Fix bounds used: check overlap on y axis when hovermode is y
1 parent 08ff50b commit 0426f42

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/components/fx/hover.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,11 +1555,12 @@ function hoverAvoidOverlaps(hoverLabels, rotateLabels, fullLayout, commonLabel)
15551555
var shiftX = getLabelShiftX(d);
15561556
// calculation based on alignHoverText function
15571557
var offsetRectX = (shiftX.x2x + (shiftX.alignShift - 1) * d.tx2width / 2 + offsets.x) * fullLayout._invScaleX;
1558+
var offsetRectY = (offsets.y - d.by / 2 - 1) * fullLayout._invScaleY;
15581559

1559-
var labelMinX = d.crossPos + offsetRectX;
1560-
var labelMaxX = labelMinX + d.tx2width;
1560+
var labelMin = d.crossPos + (axIsX ? offsetRectY : offsetRectX);
1561+
var labelMax = labelMin + (axIsX ? d.tx2width * fullLayout._invScaleX : (d.by + 2) * fullLayout._invScaleY);
15611562
if(axIsX) {
1562-
if(axisLabelMinY !== undefined && axisLabelMaxY !== undefined && Math.max(labelMinX, axisLabelMinY) <= Math.min(labelMaxX, axisLabelMaxY)) {
1563+
if(axisLabelMinY !== undefined && axisLabelMaxY !== undefined && Math.max(labelMin, axisLabelMinY) <= Math.min(labelMax, axisLabelMaxY)) {
15631564
// has overlap with axis label
15641565
if(crossAx.side === 'left') {
15651566
pmin = crossAx._mainLinePosition;
@@ -1569,7 +1570,7 @@ function hoverAvoidOverlaps(hoverLabels, rotateLabels, fullLayout, commonLabel)
15691570
}
15701571
}
15711572
} else {
1572-
if(axisLabelMinX !== undefined && axisLabelMaxX !== undefined && Math.max(labelMinX, axisLabelMinX) <= Math.min(labelMaxX, axisLabelMaxX)) {
1573+
if(axisLabelMinX !== undefined && axisLabelMaxX !== undefined && Math.max(labelMin, axisLabelMinX) <= Math.min(labelMax, axisLabelMaxX)) {
15731574
// has overlap with axis label
15741575
if(crossAx.side === 'top') {
15751576
pmin = crossAx._mainLinePosition;

0 commit comments

Comments
 (0)