-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add mouse event to plotly_click
, plotly_hover
and plotly_unhover
#1505
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
Conversation
* Include the mouse event in the event data returned by `plotly_click`, `plotly_hover` and `plotly_unhover`. * Keep compatibility with IE9: - try `new MouseEvent(type, evt)`, - and revert to `initMouseEvent` in case of failure.
* Test the property event in `plotly_click`, `plotly_hover` and `plotly_unhover`. * Test modified clicks (e.g. ctrlKey). * Updated the helper function click. Added a click event after mouseup, otherwise click events in pie plots don't get triggered.
* Test that 'plotly_hover' is triggered when `hoverinfo` is set to `"none"`.
* Test that 'plotly_click' doesn't emit an undefined trace.
* Use `evt.target` to determine whether the user invoked `Fx.hover` with a fake event.
Amazing work @n-riesco thanks very much! I'll review this at some point today. |
test/jasmine/tests/ternary_test.js
Outdated
@@ -12,6 +12,16 @@ var doubleClick = require('../assets/double_click'); | |||
var customMatchers = require('../assets/custom_matchers'); | |||
|
|||
|
|||
function getClientPosition(selector, index) { |
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.
@n-riesco Nice helper!
Would you mind making this an assets module in test/jasmine/assets/get_client_position.js
?
@@ -414,7 +414,7 @@ function hover(gd, evt, subplot) { | |||
|
|||
// [x|y]px: the pixels (from top left) of the mouse location | |||
// on the currently selected plot area | |||
var hasUserCalledHover = ('xpx' in evt || 'ypx' in evt), | |||
var hasUserCalledHover = !evt.target, |
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.
Which test(s) broke while ('xpx' in evt || 'ypx' in evt)
?
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.
Fx.hover('graph', evt, 'xy'); |
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.
Thanks. Good to know!
@@ -86,6 +86,8 @@ module.exports = function plot(gd, cdpie) { | |||
hasHoverData = false; | |||
|
|||
function handleMouseOver(evt) { | |||
evt.originalEvent = d3.event; |
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.
Thanks!
src/traces/pie/plot.js
Outdated
@@ -149,7 +149,7 @@ module.exports = function plot(gd, cdpie) { | |||
|
|||
function handleClick() { | |||
gd._hoverdata = [pt]; | |||
gd._hoverdata.trace = cd.trace; | |||
gd._hoverdata.trace = cd0.trace; |
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.
Nicely done 🎉
@n-riesco amazing PR! A new future spanning 5 of our 8 (did I count right?) subplot types and fixing two bugs while at it 💪 I made one blocking #1505 (comment) and one non-blocking #1505 (comment) 🚀 |
I'm going to start merging things for next week's Great work @n-riesco 🎉 |
With this PR, listeners to
plotly_click
,plotly_hover
andplotly_unhover
receive the original mouse event (that triggered the event) indata.event
.Implements #988 for scatter (@etpinard edit: cartesian), pie, ternary, geo and mapbox plots.
Fixes #1456 and #902