Skip to content

Commit c654063

Browse files
authored
Merge pull request #1753 from plotly/gl2d-mouseout
fix bug with unhover in gl2d
2 parents 8a253d2 + 0d8964a commit c654063

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/plots/gl2d/scene2d.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ function Scene2D(options, fullLayout) {
6767
// last pick result
6868
this.pickResult = null;
6969

70+
// is the mouse over the plot?
71+
// it's OK if this says true when it's not, so long as
72+
// when we get a mouseout we set it to false before handling
73+
this.isMouseOver = true;
74+
7075
this.bounds = [Infinity, Infinity, -Infinity, -Infinity];
7176

7277
// flag to stop render loop
@@ -153,6 +158,15 @@ proto.makeFramework = function() {
153158
container.appendChild(canvas);
154159
container.appendChild(svgContainer);
155160
container.appendChild(mouseContainer);
161+
162+
var self = this;
163+
mouseContainer.addEventListener('mouseout', function() {
164+
self.isMouseOver = false;
165+
self.unhover();
166+
});
167+
mouseContainer.addEventListener('mouseover', function() {
168+
self.isMouseOver = true;
169+
});
156170
};
157171

158172
proto.toImage = function(format) {
@@ -574,7 +588,7 @@ proto.draw = function() {
574588

575589
glplot.setDirty();
576590
}
577-
else if(!camera.panning) {
591+
else if(!camera.panning && this.isMouseOver) {
578592
this.selectBox.enabled = false;
579593

580594
var size = fullLayout._size,
@@ -658,14 +672,20 @@ proto.draw = function() {
658672

659673
// Remove hover effects if we're not over a point OR
660674
// if we're zooming or panning (in which case result is not set)
661-
if(!result && this.lastPickResult) {
675+
if(!result) {
676+
this.unhover();
677+
}
678+
679+
glplot.draw();
680+
};
681+
682+
proto.unhover = function() {
683+
if(this.lastPickResult) {
662684
this.spikes.update({});
663685
this.lastPickResult = null;
664686
this.graphDiv.emit('plotly_unhover');
665687
Fx.loneUnhover(this.svgContainer);
666688
}
667-
668-
glplot.draw();
669689
};
670690

671691
proto.hoverFormatter = function(axisName, val) {

test/jasmine/tests/gl2d_click_test.js

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var fail = require('../assets/fail_test.js');
1313
var click = require('../assets/timed_click');
1414
var hover = require('../assets/hover');
1515
var delay = require('../assets/delay');
16+
var mouseEvent = require('../assets/mouse_event');
1617

1718
// contourgl is not part of the dist plotly.js bundle initially
1819
Plotly.register([
@@ -84,11 +85,17 @@ describe('Test hover and click interactions', function() {
8485
function makeUnhoverFn(gd, x0, y0) {
8586
return function() {
8687
return new Promise(function(resolve) {
88+
var initialElement = document.elementFromPoint(x0, y0);
8789
// fairly realistic simulation of moving with the cursor
8890
var canceler = setInterval(function() {
8991
x0 -= 2;
9092
y0 -= 2;
9193
hover(x0, y0);
94+
95+
var nowElement = document.elementFromPoint(x0, y0);
96+
if(nowElement !== initialElement) {
97+
mouseEvent('mouseout', x0, y0, {element: initialElement});
98+
}
9299
}, 10);
93100

94101
gd.on('plotly_unhover', function() {

0 commit comments

Comments
 (0)