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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ dragElement.init = function init(options) {

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

if(gd._dragged && options.moveFn && !rightClick) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/dragelement/unhover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {
return;
}
Expand Down
49 changes: 49 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,55 @@ describe('hover updates', function() {
})
.then(done, done.fail);
});

it('drag should trigger unhover', function(done) {
var data = [{y: [1]}];

var layout = {
hovermode: 'x',
width: 400,
height: 200,
margin: {l: 0, t: 0, r: 0, b: 0},
showlegend: false
};

var gd = createGraphDiv();

var hoverHandler = jasmine.createSpy('hover');
var unhoverHandler = jasmine.createSpy('unhover');

var hoverPt = [200, 100];
var dragPt = [210, 100];

function hover() {
mouseEvent('mousemove', hoverPt[0], hoverPt[1]);
Lib.clearThrottle();
}

function drag() {
mouseEvent('mousedown', hoverPt[0], hoverPt[1]);
mouseEvent('mousemove', dragPt[0], dragPt[1]);
mouseEvent('mouseup', dragPt[0], dragPt[1]);
Lib.clearThrottle();
}

Plotly.react(gd, data, layout)
.then(function() {
gd.on('plotly_hover', hoverHandler);
gd.on('plotly_unhover', unhoverHandler);
})
.then(hover)
.then(function() {
expect(hoverHandler).toHaveBeenCalled();
expect(unhoverHandler).not.toHaveBeenCalled();
})
.then(drag)
.then(function() {
expect(hoverHandler).toHaveBeenCalled();
expect(unhoverHandler).toHaveBeenCalled();
})
.then(done, done.fail);
});
});

describe('Test hover label custom styling:', function() {
Expand Down