Skip to content

Clear gd._hoverdata before emitting plotly_unhover #1448

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

Merged
merged 1 commit into from
Mar 7, 2017
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
8 changes: 4 additions & 4 deletions src/components/dragelement/unhover.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ unhover.wrapped = function(gd, evt, subplot) {
// remove hover effects on mouse out, and emit unhover event
unhover.raw = function unhoverRaw(gd, evt) {
var fullLayout = gd._fullLayout;
var oldhoverdata = gd._hoverdata;

if(!evt) evt = {};
if(evt.target &&
Expand All @@ -40,10 +41,9 @@ unhover.raw = function unhoverRaw(gd, evt) {
}

fullLayout._hoverlayer.selectAll('g').remove();
gd._hoverdata = undefined;

if(evt.target && gd._hoverdata) {
gd.emit('plotly_unhover', {points: gd._hoverdata});
if(evt.target && oldhoverdata) {
gd.emit('plotly_unhover', {points: oldhoverdata});
}

gd._hoverdata = undefined;
};
58 changes: 58 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,62 @@ describe('hover updates', function() {
return assertLabelsCorrect(null, [103, 100], 'trace 10.5');
}).catch(fail).then(done);
});

it('should not trigger infinite loop of plotly_unhover events', function(done) {
var gd = createGraphDiv();
var colors0 = ['#00000', '#00000', '#00000', '#00000', '#00000', '#00000', '#00000'];

function unhover() {
return new Promise(function(resolve) {
mouseEvent('mousemove', 394, 285);
setTimeout(function() {
resolve();
}, constants.HOVERMINTIME);
});
}

var hoverCnt = 0;
var unHoverCnt = 0;

Plotly.plot(gd, [{
mode: 'markers',
x: [1, 2, 3, 4, 5, 6, 7],
y: [1, 2, 3, 2, 3, 4, 3],
marker: {
size: 16,
colors: colors0.slice()
}
}])
.then(function() {

gd.on('plotly_hover', function(eventData) {
hoverCnt++;

var pt = eventData.points[0];
Plotly.restyle(gd, 'marker.color[' + pt.pointNumber + ']', 'red');
});

gd.on('plotly_unhover', function() {
unHoverCnt++;

Plotly.restyle(gd, 'marker.color', [colors0.slice()]);
});

return assertLabelsCorrect([351, 251], [358, 272], '2');
})
.then(unhover)
.then(function() {
expect(hoverCnt).toEqual(1);
expect(unHoverCnt).toEqual(1);

return assertLabelsCorrect([400, 200], [435, 198], '3');
})
.then(unhover)
.then(function() {
expect(hoverCnt).toEqual(2);
expect(unHoverCnt).toEqual(2);
})
.then(done);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test case led to

image

before the above dragelement patch.


});
});