Skip to content

Commit f598fea

Browse files
authored
Merge pull request #5845 from plotly/fix5844-unified-average-position
Position hover in respect to the average of values in (x|y) unified modes
2 parents 91d81ec + c9d06e5 commit f598fea

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

draftlogs/5845_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Position hover in respect to the average of values in (x|y) unified modes (regression introduced in 2.0.0) [[#5845](https://github.com/plotly/plotly.js/pull/5845)]

src/components/fx/hover.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,11 @@ function createHoverText(hoverData, opts, gd) {
10721072

10731073
// Position the hover
10741074
var winningPoint = hoverData[0];
1075-
var ly = (winningPoint.y0 + winningPoint.y1) / 2;
1076-
var lx = (winningPoint.x0 + winningPoint.x1) / 2;
1075+
var ly = axLetter === 'y' ?
1076+
(winningPoint.y0 + winningPoint.y1) / 2 : Lib.mean(hoverData.map(function(c) {return (c.y0 + c.y1) / 2;}));
1077+
var lx = axLetter === 'x' ?
1078+
(winningPoint.x0 + winningPoint.x1) / 2 : Lib.mean(hoverData.map(function(c) {return (c.x0 + c.x1) / 2;}));
1079+
10771080
var legendContainer = container.select('g.legend');
10781081
var tbb = legendContainer.node().getBoundingClientRect();
10791082
lx += xa._offset;

0 commit comments

Comments
 (0)