Skip to content
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

Fire unhover when dragging plot #5407

Merged
merged 3 commits into from
Jan 26, 2021
Merged

Fire unhover when dragging plot #5407

merged 3 commits into from
Jan 26, 2021

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Jan 14, 2021

Fixes #5437.

This PR makes a small change to unhover behavior. My premise is that, toward hooking up external HTML/CSS hovers, plotly_hover and plotly_unhover should be enough to manage hover state.

The GIF below shows plotly hover along with HTML/CSS hover. plotly_unhover does not currently fire when you drag the plot, resulting in a stray hover.

badhover

The cause is this conditional, which is not passed the event from the onMove handler, hence evt.target is empty.

if(evt.target && oldhoverdata) {

if(dx || dy) {
gd._dragged = true;
dragElement.unhover(gd);
}

One solution, without adding additional flags, is to check if the plot is being dragged and fire the event if so. Then, hover/unhover are sufficient to manage the state in this case.

goodhover

(It could pass the event from onMove in order to accomplish this, but then plotly_beforehover is fired many times while dragging, which would require other flags and fixes to avoid)

/cc @plotly/plotly_js @jonmmease and probably also @nicolaskruchten @alexcjohnson

@rreusser
Copy link
Contributor Author

Oh, and to be clear, gd._hoverdata is flushed so that with this fix, plotly_unhover is only fired once, when the drag begins.

@archmoj
Copy link
Contributor

archmoj commented Jan 14, 2021

Thanks for the PR!
Please tag @plotly/plotly_js, @jonmmease and others in the pull description.

@alexcjohnson
Copy link
Collaborator

We do have an event e at that dragElement.unhover(gd) call - can we just pass it in? Consumers of this plotly event may want the base browser event.

@archmoj archmoj added this to the NEXT milestone Jan 15, 2021
@rreusser
Copy link
Contributor Author

@alexcjohnson Yes, I can pass it in. Then I think I just need to invert the logic and prevent this from firing on every drag move event:

if(!evt) evt = {};
if(evt.target &&
Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {
return;
}

@rreusser
Copy link
Contributor Author

rreusser commented Jan 18, 2021

Okay, sorry, had to dust this off and double-check it. I think it now passes the event through but uses gd._dragged to avoid plotly_beforehover being called when it doesn't apply. /cc @archmoj

@rreusser
Copy link
Contributor Author

rreusser commented Jan 18, 2021

Debugging nontrivial/non-fluke test failure.

@rreusser
Copy link
Contributor Author

rreusser commented Jan 18, 2021

Update: I rebuilt on circle-ci and am maybe >85% confident that this is not actually a real test failure related to the changes in this PR.

@rreusser
Copy link
Contributor Author

@archmoj I don't currently have additional things to add to this PR. It looks like it did eventually pass all tests on circle-ci. Just let me know if there's anything else you'd like to have happen on this PR, otherwise I'll put the ball in your court to hit the button and merge, unless you prefer otherwise.

@archmoj
Copy link
Contributor

archmoj commented Jan 22, 2021

@archmoj I don't currently have additional things to add to this PR. It looks like it did eventually pass all tests on circle-ci. Just let me know if there's anything else you'd like to have happen on this PR, otherwise I'll put the ball in your court to hit the button and merge, unless you prefer otherwise.

Overall LGTM. Let's me have a second look.
BTW we are missing a test to lock this down.
Could you please also open an issue to illustrate the bug we are fixing here?

@@ -34,7 +34,7 @@ unhover.raw = function raw(gd, evt) {
var oldhoverdata = gd._hoverdata;

if(!evt) evt = {};
if(evt.target &&
if(evt.target && !gd._dragged &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if in addition to gd._dragged we should check for gd._editing here?

However the following codepen titled after appears to be correct when editing the title positioned at center.
Before vs After

So I think there is no need for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll check that as well.

@rreusser
Copy link
Contributor Author

@archmoj Pardon the slow turnaround, but I've added a test and confirmed that this change fixes it! I thought about _editing and, in particular based on your example, I don't immediately see that the behavior should change if editing, no?

@archmoj
Copy link
Contributor

archmoj commented Jan 26, 2021

Nicely done.
💃

@archmoj archmoj merged commit 499c079 into plotly:master Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhover does not fire when drag triggers unhover
3 participants