Skip to content

Commit

Permalink
fix(point): Fix custom point hover position
Browse files Browse the repository at this point in the history
Safari & Edge return different x/y value from .getBBox()
Use node's x/y attribute instead

Fix #618
Close #700
  • Loading branch information
netil committed Dec 11, 2018
1 parent becd3c3 commit 2edb82a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/shape/line.js
Expand Up @@ -567,6 +567,7 @@ extend(ChartInternal.prototype, {

const circles = $$.getCircles(i, id).classed(CLASS.EXPANDED, true);
const scale = r(circles) / $$.config.point_r;
const ratio = 1 - scale;

if ($$.isCirclePoint()) {
circles.attr("r", r);
Expand All @@ -575,15 +576,15 @@ extend(ChartInternal.prototype, {
circles.each(function() {
const point = d3Select(this);

const {x, y, width, height} = this.getBBox();
const x1 = x + (width * 0.5);
const y1 = y + (height * 0.5);
const x2 = (1 - scale) * x1;
const y2 = (1 - scale) * y1;
if (this.tagName === "circle") {
point.attr("r", r);
} else {
const {width, height} = this.getBBox();
const x = ratio * (+point.attr("x") + width / 2);
const y = ratio * (+point.attr("y") + height / 2);

this.tagName === "circle" ?
point.attr("r", r) :
point.style("transform", `translate(${x2}px, ${y2}px) scale(${scale})`);
point.style("transform", `translate(${x}px, ${y}px) scale(${scale})`);
}
});
}
},
Expand Down

0 comments on commit 2edb82a

Please sign in to comment.