Skip to content

Commit 8ea836b

Browse files
authored
Merge pull request #6901 from OBe95/fix-hovermode-x-tooltip-pointer
fix: tooltip pointer position in hovermode x
2 parents a04e81d + a1ddd19 commit 8ea836b

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

draftlogs/6900_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix tooltip pointer position calculation when hovermode is set to 'x' - [issue [#6900](https://github.com/plotly/plotly.js/issues/6900) | PR [#6901](https://github.com/plotly/plotly.js/pull/6901)]

src/components/fx/hover.js

+13-25
Original file line numberDiff line numberDiff line change
@@ -999,35 +999,23 @@ function createHoverText(hoverData, opts) {
999999

10001000
var halfWidth = tbb.width / 2 + HOVERTEXTPAD;
10011001

1002+
var tooltipMidX = lx;
10021003
if(lx < halfWidth) {
1003-
lx = halfWidth;
1004-
1005-
lpath.attr('d', 'M-' + (halfWidth - HOVERARROWSIZE) + ',0' +
1006-
'L-' + (halfWidth - HOVERARROWSIZE * 2) + ',' + topsign + HOVERARROWSIZE +
1007-
'H' + (halfWidth) +
1008-
'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) +
1009-
'H-' + halfWidth +
1010-
'V' + topsign + HOVERARROWSIZE +
1011-
'Z');
1004+
tooltipMidX = halfWidth;
10121005
} else if(lx > (fullLayout.width - halfWidth)) {
1013-
lx = fullLayout.width - halfWidth;
1014-
1015-
lpath.attr('d', 'M' + (halfWidth - HOVERARROWSIZE) + ',0' +
1016-
'L' + halfWidth + ',' + topsign + HOVERARROWSIZE +
1017-
'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) +
1018-
'H-' + halfWidth +
1019-
'V' + topsign + HOVERARROWSIZE +
1020-
'H' + (halfWidth - HOVERARROWSIZE * 2) + 'Z');
1021-
} else {
1022-
lpath.attr('d', 'M0,0' +
1023-
'L' + HOVERARROWSIZE + ',' + topsign + HOVERARROWSIZE +
1024-
'H' + (halfWidth) +
1025-
'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) +
1026-
'H-' + (halfWidth) +
1027-
'V' + topsign + HOVERARROWSIZE +
1028-
'H-' + HOVERARROWSIZE + 'Z');
1006+
tooltipMidX = fullLayout.width - halfWidth;
10291007
}
10301008

1009+
lpath.attr('d', 'M' + (lx - tooltipMidX) + ',0' +
1010+
'L' + (lx - tooltipMidX + HOVERARROWSIZE) + ',' + topsign + HOVERARROWSIZE +
1011+
'H' + halfWidth +
1012+
'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) +
1013+
'H' + (-halfWidth) +
1014+
'V' + topsign + HOVERARROWSIZE +
1015+
'H' + (lx - tooltipMidX - HOVERARROWSIZE) +
1016+
'Z');
1017+
1018+
lx = tooltipMidX;
10311019
commonLabelRect.minX = lx - halfWidth;
10321020
commonLabelRect.maxX = lx + halfWidth;
10331021
if(xa.side === 'top') {

0 commit comments

Comments
 (0)