Skip to content

Commit 499c079

Browse files
authored
Merge pull request #5407 from rreusser/unhoverfix
Fire unhover when dragging plot
2 parents c8e969b + a2f7bd5 commit 499c079

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/components/dragelement/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ dragElement.init = function init(options) {
180180

181181
if(dx || dy) {
182182
gd._dragged = true;
183-
dragElement.unhover(gd);
183+
dragElement.unhover(gd, e);
184184
}
185185

186186
if(gd._dragged && options.moveFn && !rightClick) {

src/components/dragelement/unhover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ unhover.raw = function raw(gd, evt) {
3434
var oldhoverdata = gd._hoverdata;
3535

3636
if(!evt) evt = {};
37-
if(evt.target &&
37+
if(evt.target && !gd._dragged &&
3838
Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {
3939
return;
4040
}

test/jasmine/tests/hover_label_test.js

+49
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,55 @@ describe('hover updates', function() {
36323632
})
36333633
.then(done, done.fail);
36343634
});
3635+
3636+
it('drag should trigger unhover', function(done) {
3637+
var data = [{y: [1]}];
3638+
3639+
var layout = {
3640+
hovermode: 'x',
3641+
width: 400,
3642+
height: 200,
3643+
margin: {l: 0, t: 0, r: 0, b: 0},
3644+
showlegend: false
3645+
};
3646+
3647+
var gd = createGraphDiv();
3648+
3649+
var hoverHandler = jasmine.createSpy('hover');
3650+
var unhoverHandler = jasmine.createSpy('unhover');
3651+
3652+
var hoverPt = [200, 100];
3653+
var dragPt = [210, 100];
3654+
3655+
function hover() {
3656+
mouseEvent('mousemove', hoverPt[0], hoverPt[1]);
3657+
Lib.clearThrottle();
3658+
}
3659+
3660+
function drag() {
3661+
mouseEvent('mousedown', hoverPt[0], hoverPt[1]);
3662+
mouseEvent('mousemove', dragPt[0], dragPt[1]);
3663+
mouseEvent('mouseup', dragPt[0], dragPt[1]);
3664+
Lib.clearThrottle();
3665+
}
3666+
3667+
Plotly.react(gd, data, layout)
3668+
.then(function() {
3669+
gd.on('plotly_hover', hoverHandler);
3670+
gd.on('plotly_unhover', unhoverHandler);
3671+
})
3672+
.then(hover)
3673+
.then(function() {
3674+
expect(hoverHandler).toHaveBeenCalled();
3675+
expect(unhoverHandler).not.toHaveBeenCalled();
3676+
})
3677+
.then(drag)
3678+
.then(function() {
3679+
expect(hoverHandler).toHaveBeenCalled();
3680+
expect(unhoverHandler).toHaveBeenCalled();
3681+
})
3682+
.then(done, done.fail);
3683+
});
36353684
});
36363685

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

0 commit comments

Comments
 (0)