Skip to content

Commit c86a12b

Browse files
author
Daniel Gröger
committed
Fix for overlap on other axis and other sides
1 parent 88d2475 commit c86a12b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/components/fx/hover.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@ function getHoverLabelText(d, showCommonLabel, hovermode, fullLayout, t0, g) {
14941494
// the other, though it hardly matters - there's just too much
14951495
// information then.
14961496
function hoverAvoidOverlaps(hoverLabels, axKey, fullLayout) {
1497+
let crossAxKey = axKey === 'xa' ? 'ya' : 'xa';
14971498
var nummoves = 0;
14981499
var axSign = 1;
14991500
var nLabels = hoverLabels.size();
@@ -1504,21 +1505,41 @@ function hoverAvoidOverlaps(hoverLabels, axKey, fullLayout) {
15041505

15051506
hoverLabels.each(function(d) {
15061507
var ax = d[axKey];
1508+
let crossAx = d[crossAxKey];
15071509
var axIsX = ax._id.charAt(0) === 'x';
15081510
var rng = ax.range;
15091511

15101512
if(k === 0 && rng && ((rng[0] > rng[1]) !== axIsX)) {
15111513
axSign = -1;
15121514
}
1515+
let pmin, pmax;
1516+
if (axIsX) {
1517+
if (crossAx.side === 'left') {
1518+
pmin = crossAx._mainLinePosition;
1519+
pmax = fullLayout.width;
1520+
} else {
1521+
pmin = 0;
1522+
pmax = crossAx._mainLinePosition;
1523+
}
1524+
} else {
1525+
if (crossAx.side === 'top') {
1526+
pmin = crossAx._mainLinePosition;
1527+
pmax = fullLayout.height;
1528+
} else {
1529+
pmin = 0;
1530+
pmax = crossAx._mainLinePosition;
1531+
}
1532+
}
1533+
15131534
pointgroups[k++] = [{
15141535
datum: d,
15151536
traceIndex: d.trace.index,
15161537
dp: 0,
15171538
pos: d.pos,
15181539
posref: d.posref,
15191540
size: d.by * (axIsX ? YFACTOR : 1) / 2,
1520-
pmin: 0,
1521-
pmax: (axIsX ? fullLayout.width : fullLayout.height) - ax._mainLinePosition
1541+
pmin,
1542+
pmax
15221543
}];
15231544
});
15241545

0 commit comments

Comments
 (0)