Skip to content

Commit c7a9dd5

Browse files
committed
couple of perf and style tweaks to regular point hover
1 parent 2018a74 commit c7a9dd5

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/traces/scatter/hover.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
107107
// always will show up regardless of point size, but
108108
// prioritize smaller points
109109
var rad = Math.max(3, di.mrc || 0);
110-
return Math.max(Math.abs(xa.c2p(di.x) - xa.c2p(xval)) - rad, 1 - 3 / rad);
110+
return Math.max(Math.abs(xa.c2p(di.x) - xpx) - rad, 1 - 3 / rad);
111111
},
112112
dy = function(di) {
113113
var rad = Math.max(3, di.mrc || 0);
114-
return Math.max(Math.abs(ya.c2p(di.y) - ya.c2p(yval)) - rad, 1 - 3 / rad);
114+
return Math.max(Math.abs(ya.c2p(di.y) - ypx) - rad, 1 - 3 / rad);
115115
},
116116
dxy = function(di) {
117117
var rad = Math.max(3, di.mrc || 0),
118-
dx = Math.abs(xa.c2p(di.x) - xa.c2p(xval)),
119-
dy = Math.abs(ya.c2p(di.y) - ya.c2p(yval));
118+
dx = xa.c2p(di.x) - xpx,
119+
dy = ya.c2p(di.y) - ypx;
120120
return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - 3 / rad);
121121
},
122122
distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);
@@ -132,15 +132,17 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
132132
yc = ya.c2p(di.y, true),
133133
rad = di.mrc || 1;
134134

135-
pointData.color = getTraceColor(trace, di);
135+
Lib.extendFlat(pointData, {
136+
color: getTraceColor(trace, di),
136137

137-
pointData.x0 = xc - rad;
138-
pointData.x1 = xc + rad;
139-
pointData.xLabelVal = di.x;
138+
x0: xc - rad,
139+
x1: xc + rad,
140+
xLabelVal: di.x,
140141

141-
pointData.y0 = yc - rad;
142-
pointData.y1 = yc + rad;
143-
pointData.yLabelVal = di.y;
142+
y0: yc - rad,
143+
y1: yc + rad,
144+
yLabelVal: di.y
145+
});
144146

145147
if(di.tx) pointData.text = di.tx;
146148
else if(trace.text) pointData.text = trace.text;

0 commit comments

Comments
 (0)