Skip to content

fix bug with unhover in gl2d #1753

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
Jun 2, 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
28 changes: 24 additions & 4 deletions src/plots/gl2d/scene2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function Scene2D(options, fullLayout) {
// last pick result
this.pickResult = null;

// is the mouse over the plot?
// it's OK if this says true when it's not, so long as
// when we get a mouseout we set it to false before handling
this.isMouseOver = true;

this.bounds = [Infinity, Infinity, -Infinity, -Infinity];

// flag to stop render loop
Expand Down Expand Up @@ -153,6 +158,15 @@ proto.makeFramework = function() {
container.appendChild(canvas);
container.appendChild(svgContainer);
container.appendChild(mouseContainer);

var self = this;
mouseContainer.addEventListener('mouseout', function() {
self.isMouseOver = false;
self.unhover();
});
mouseContainer.addEventListener('mouseover', function() {
self.isMouseOver = true;
});
};

proto.toImage = function(format) {
Expand Down Expand Up @@ -574,7 +588,7 @@ proto.draw = function() {

glplot.setDirty();
}
else if(!camera.panning) {
else if(!camera.panning && this.isMouseOver) {
this.selectBox.enabled = false;

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

// Remove hover effects if we're not over a point OR
// if we're zooming or panning (in which case result is not set)
if(!result && this.lastPickResult) {
if(!result) {
this.unhover();
}

glplot.draw();
};

proto.unhover = function() {
if(this.lastPickResult) {
this.spikes.update({});
this.lastPickResult = null;
this.graphDiv.emit('plotly_unhover');
Fx.loneUnhover(this.svgContainer);
}

glplot.draw();
};

proto.hoverFormatter = function(axisName, val) {
Expand Down
7 changes: 7 additions & 0 deletions test/jasmine/tests/gl2d_click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var fail = require('../assets/fail_test.js');
var click = require('../assets/timed_click');
var hover = require('../assets/hover');
var delay = require('../assets/delay');
var mouseEvent = require('../assets/mouse_event');

// contourgl is not part of the dist plotly.js bundle initially
Plotly.register([
Expand Down Expand Up @@ -84,11 +85,17 @@ describe('Test hover and click interactions', function() {
function makeUnhoverFn(gd, x0, y0) {
return function() {
return new Promise(function(resolve) {
var initialElement = document.elementFromPoint(x0, y0);
// fairly realistic simulation of moving with the cursor
var canceler = setInterval(function() {
x0 -= 2;
y0 -= 2;
hover(x0, y0);

var nowElement = document.elementFromPoint(x0, y0);
if(nowElement !== initialElement) {
mouseEvent('mouseout', x0, y0, {element: initialElement});
}
}, 10);

gd.on('plotly_unhover', function() {
Expand Down