-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Enable Hover and Click Events Anywhere #7707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5ab032d
8d4562a
a92246d
1eb8d6e
fb4ccbe
a981ca5
2ba5ddb
19ac09c
5ba0f25
78305ac
7868ae9
dae94d4
7dfecf6
e93310f
ed0a5a8
a974535
e7934c9
2df7c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,11 @@ exports.loneHover = function loneHover(hoverItems, opts) { | |
| y1: y1 + gTop | ||
| }; | ||
|
|
||
| // xPixel/yPixel are pixel coordinates of the hover point's center, | ||
| // relative to the top-left corner of the graph div | ||
| eventData.xPixel = (_x0 + _x1) / 2; | ||
| eventData.yPixel = (_y0 + _y1) / 2; | ||
|
|
||
| if (opts.inOut_bbox) { | ||
| opts.inOut_bbox.push(eventData.bbox); | ||
| } | ||
|
|
@@ -473,6 +478,14 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
| } | ||
| } | ||
|
|
||
| // Save coordinate values so clickanywhere can be used without hoveranywhere | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we only do this step if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't functionally matter but I can change it just to be more explicit + make it more intuitive |
||
| if (fullLayout.clickanywhere) { | ||
| gd._hoverXVals = xvalArray; | ||
| gd._hoverYVals = yvalArray; | ||
| gd._hoverXAxes = xaArray; | ||
| gd._hoverYAxes = yaArray; | ||
| } | ||
|
|
||
| // the pixel distance to beat as a matching point | ||
| // in 'x' or 'y' mode this resets for each trace | ||
| var distance = Infinity; | ||
|
|
@@ -778,6 +791,18 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
| createSpikelines(gd, spikePoints, spikelineOpts); | ||
| } | ||
| } | ||
|
|
||
| if (fullLayout.hoveranywhere && !noHoverEvent && eventTarget) { | ||
| var oldHoverData = gd._hoverdata; | ||
| if (oldHoverData && oldHoverData.length) { | ||
| gd.emit('plotly_unhover', { | ||
| event: evt, | ||
| points: oldHoverData | ||
| }); | ||
| gd._hoverdata = []; | ||
| } | ||
| emitHover([]); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -877,6 +902,9 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
| y0: y0 + gTop, | ||
| y1: y1 + gTop | ||
| }; | ||
|
|
||
| eventData.xPixel = (_x0 + _x1) / 2; | ||
| eventData.yPixel = (_y0 + _y1) / 2; | ||
| } | ||
|
|
||
| pt.eventData = [eventData]; | ||
|
|
@@ -914,23 +942,28 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) { | |
| } | ||
|
|
||
| // don't emit events if called manually | ||
| if (!eventTarget || noHoverEvent || !hoverChanged(gd, evt, oldhoverdata)) return; | ||
| var _hoverChanged = hoverChanged(gd, evt, oldhoverdata); | ||
| if (!eventTarget || noHoverEvent || (!_hoverChanged && !fullLayout.hoveranywhere)) return; | ||
|
|
||
| if (oldhoverdata) { | ||
| if (oldhoverdata && _hoverChanged) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that when |
||
| gd.emit('plotly_unhover', { | ||
| event: evt, | ||
| points: oldhoverdata | ||
| }); | ||
| } | ||
|
|
||
| gd.emit('plotly_hover', { | ||
| event: evt, | ||
| points: gd._hoverdata, | ||
| xaxes: xaArray, | ||
| yaxes: yaArray, | ||
| xvals: xvalArray, | ||
| yvals: yvalArray | ||
| }); | ||
| emitHover(gd._hoverdata); | ||
|
|
||
| function emitHover(points) { | ||
| gd.emit('plotly_hover', { | ||
| event: evt, | ||
| points: points, | ||
| xaxes: xaArray, | ||
| yaxes: yaArray, | ||
| xvals: xvalArray, | ||
| yvals: yvalArray | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function hoverDataKey(d) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexshoe what's the purpose of these lines?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we track hover points as bounding boxes with x0, x1, y0, y1
So xPixel and yPixel are calculated centers of those bounding boxes for convenience
and all these are pixel values with the top-left corner of the graph div as the origin. I'll add a comment to document this