Skip to content

Commit e7934c9

Browse files
committed
Add xPixel/yPixel documentation, and add emitHover helper
1 parent a974535 commit e7934c9

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/components/fx/hover.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ exports.loneHover = function loneHover(hoverItems, opts) {
167167
y1: y1 + gTop
168168
};
169169

170+
// xPixel/yPixel are pixel coordinates of the hover point's center,
171+
// relative to the top-left corner of the graph div
170172
eventData.xPixel = (_x0 + _x1) / 2;
171173
eventData.yPixel = (_y0 + _y1) / 2;
172174

@@ -477,10 +479,12 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
477479
}
478480

479481
// Save coordinate values so clickanywhere can be used without hoveranywhere
480-
gd._hoverXVals = xvalArray;
481-
gd._hoverYVals = yvalArray;
482-
gd._hoverXAxes = xaArray;
483-
gd._hoverYAxes = yaArray;
482+
if (fullLayout.clickanywhere) {
483+
gd._hoverXVals = xvalArray;
484+
gd._hoverYVals = yvalArray;
485+
gd._hoverXAxes = xaArray;
486+
gd._hoverYAxes = yaArray;
487+
}
484488

485489
// the pixel distance to beat as a matching point
486490
// in 'x' or 'y' mode this resets for each trace
@@ -789,14 +793,15 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
789793
}
790794

791795
if (fullLayout.hoveranywhere && !noHoverEvent && eventTarget) {
792-
gd.emit('plotly_hover', {
793-
event: evt,
794-
points: [],
795-
xaxes: xaArray,
796-
yaxes: yaArray,
797-
xvals: xvalArray,
798-
yvals: yvalArray
799-
});
796+
var oldHoverData = gd._hoverdata;
797+
if (oldHoverData && oldHoverData.length) {
798+
gd.emit('plotly_unhover', {
799+
event: evt,
800+
points: oldHoverData
801+
});
802+
gd._hoverdata = [];
803+
}
804+
emitHover([]);
800805
}
801806
return result;
802807
}
@@ -947,14 +952,18 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
947952
});
948953
}
949954

950-
gd.emit('plotly_hover', {
951-
event: evt,
952-
points: gd._hoverdata,
953-
xaxes: xaArray,
954-
yaxes: yaArray,
955-
xvals: xvalArray,
956-
yvals: yvalArray
957-
});
955+
emitHover(gd._hoverdata);
956+
957+
function emitHover(points) {
958+
gd.emit('plotly_hover', {
959+
event: evt,
960+
points: points,
961+
xaxes: xaArray,
962+
yaxes: yaArray,
963+
xvals: xvalArray,
964+
yvals: yvalArray
965+
});
966+
}
958967
}
959968

960969
function hoverDataKey(d) {

0 commit comments

Comments
 (0)