-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Correct wrong element targeting on hover in shadow DOM #5256
Conversation
When using plotly inside of a shadow DOM, the calculations used to determine if the pointer has moved off of the graph would use the wrong element to determine the bounding box.
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 very much for the PR.
Is there an open issue related to this problem?
If not, please open an issue including a codepen to illustrate the bug while using the last (not latest) plotly.js version similar to this codepen.
Then you may also reuse that to add a test to lock down the bug here:
https://github.com/plotly/plotly.js/blob/master/test/jasmine/tests/hover_label_test.js
@@ -333,7 +333,12 @@ function _hover(gd, evt, subplot, noHoverEvent) { | |||
return; | |||
} | |||
|
|||
var dbb = evt.target.getBoundingClientRect(); | |||
// Discover event target, traversing open shadow roots. | |||
var target = evt.composedPath && evt.composedPath()[0]; |
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.
Have you also investigated a possible workaround for IE?
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.
I haven't -- I'll do so and update with my findings.
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.
After some investigation, I think the best we can do in the case of IE is simply fallback to the original behavior of directly using the event target.
var target = evt.composedPath && evt.composedPath()[0]; | |
var target = evt.composedPath && evt.composedPath()[0]; | |
if(!target) { | |
target = 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.
Thanks. Please commit your suggestion.
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.
Or simply
var target = (evt.composedPath && evt.composedPath()[0]) || evt.target;
@dbluhm in addition to hover (fx), there are some other places e.g. dragelement
, shapes
and mapbox
which evt.target
is used. Could you please investigate if there is a issue that similar fix may help?
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.
ping @dbluhm
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.
Sure, I'll take a look! Apologies for the slow response -- working to address this issue just as time arises. Thanks for your patience!
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.
I don't believe there is an open issue for this currently; I'll be sure to open one and include a codepen. I'll also work on getting a test for it in |
Opened #5277 to track the issue solved by this PR. |
@dbluhm to avoid conflicts namely with mapbox hover please merge upstream/master into this branch before generalizing this logic to few other places. |
As a brief update, this PR has been moved to my backlog due to some changes in my development priorities associated with an employer change. I'm still hoping to resolve these issues and get this merged but my timeline is less certain now. My primary obstacle at the moment is lack of familiarity with the testing framework (I don't spend too much time in JavaScript) so I've struggled to recreate the conditions needed to exhibit this behavior in tests with my relatively limited time. Still open to feedback and any direction you'd like to give 🙂 |
Thanks @dbluhm for the contribution. Note: I'll work on the remaining items in a following PR. |
When using plotly inside of a shadow DOM, the calculations used to determine if the pointer has moved off of the graph would use the wrong element to determine the bounding box. This was resulting in a flicker in the hover text as it would find that the mouse pointer had apparently moved off the graph when it actually hadn't and the next
mousemove
event would immediately redraw the hover text.This PR uses the
Event.composedPath()
method of the Event interface to determine the correct element from which to base bounding box calculations.In my limited testing, I found that occasionally a
mousemove
event originating from a shadow DOM would get raised that did not have a properly formedcomposedPath()
-- it would return an empty list. I haven't been able to nail down exactly why but for those rare cases, the early return ensures the hover text doesn't flicker.I'm pretty new to Plotly but I tried to do my research so hopefully this solution isn't too naive. More than happy to work with maintainers to get this to a point where it can be accepted.
Thanks and excellent work on Plotly!