Skip to content

Commit

Permalink
adjust vertical and horizontal alignment of unified hover label
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Jul 23, 2021
1 parent dca5b1e commit df6353d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,11 @@ function createHoverText(hoverData, opts, gd) {
legendDraw(gd, mockLegend);

// Position the hover
var legendContainer = container.select('g.legend');
var tbb = legendContainer.node().getBoundingClientRect();
var tWidth = tbb.width + 2 * HOVERTEXTPAD;
var tHeight = tbb.height + 2 * HOVERTEXTPAD;
var winningPoint = hoverData[0];

// When the scatter point wins, it's OK for the hovelabel to occlude the bar and other points.
var scatterWon = cartesianScatterPoints[winningPoint.trace.type];

Expand All @@ -1098,7 +1101,7 @@ function createHoverText(hoverData, opts, gd) {
lyBottom = Math.max.apply(null, hoverData.map(function(c) { return Math.max(c.y0, c.y1); }));
}
} else {
lyTop = lyBottom = Lib.mean(hoverData.map(function(c) { return (c.y0 + c.y1) / 2; }));
lyTop = lyBottom = Lib.mean(hoverData.map(function(c) { return (c.y0 + c.y1) / 2; })) - tHeight / 2;
}

var lxRight, lxLeft;
Expand All @@ -1111,14 +1114,9 @@ function createHoverText(hoverData, opts, gd) {
lxLeft = Math.min.apply(null, hoverData.map(function(c) { return Math.min(c.x0, c.x1); }));
}
} else {
lxRight = lxLeft = Lib.mean(hoverData.map(function(c) { return (c.x0 + c.x1) / 2; }));
lxRight = lxLeft = Lib.mean(hoverData.map(function(c) { return (c.x0 + c.x1) / 2; })) - tWidth / 2;
}

var legendContainer = container.select('g.legend');
var tbb = legendContainer.node().getBoundingClientRect();
var tWidth = tbb.width + 2 * HOVERTEXTPAD;
var tHeight = tbb.height + 2 * HOVERTEXTPAD;

var xOffset = xa._offset;
var yOffset = ya._offset;
lyBottom += yOffset;
Expand Down

0 comments on commit df6353d

Please sign in to comment.