Skip to content

Commit 9bb7d91

Browse files
committed
use dragElement.unhover to queued Fx.hover calls
... when dragging off-screen - attach handlers to bgRect (not framework), doesn't change any thing, but is more consistent.
1 parent 303de22 commit 9bb7d91

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

src/plots/geo/geo.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ proto.updateDims = function(fullLayout, geoLayout) {
330330

331331
proto.updateFx = function(fullLayout, geoLayout) {
332332
var _this = this;
333-
var framework = _this.framework;
334333
var gd = _this.graphDiv;
334+
var bgRect = _this.bgRect;
335335
var dragMode = fullLayout.dragmode;
336336

337337
if(_this.isStatic) return;
@@ -356,12 +356,12 @@ proto.updateFx = function(fullLayout, geoLayout) {
356356
}
357357

358358
if(dragMode === 'pan') {
359-
_this.bgRect.node().onmousedown = null;
360-
framework.call(createGeoZoom(_this, geoLayout));
361-
framework.on('dblclick.zoom', zoomReset);
359+
bgRect.node().onmousedown = null;
360+
bgRect.call(createGeoZoom(_this, geoLayout));
361+
bgRect.on('dblclick.zoom', zoomReset);
362362
}
363363
else if(dragMode === 'select' || dragMode === 'lasso') {
364-
framework.on('.zoom', null);
364+
bgRect.on('.zoom', null);
365365

366366
var fillRangeItems;
367367

@@ -406,22 +406,24 @@ proto.updateFx = function(fullLayout, geoLayout) {
406406
dragElement.init(dragOptions);
407407
}
408408

409-
framework.on('mousemove', function() {
409+
bgRect.on('mousemove', function() {
410410
var lonlat = _this.projection.invert(d3.mouse(this));
411411

412-
if(!lonlat || isNaN(lonlat[0]) || isNaN(lonlat[1])) return;
412+
if(!lonlat || isNaN(lonlat[0]) || isNaN(lonlat[1])) {
413+
return dragElement.unhover(gd, d3.event);
414+
}
413415

414416
_this.xaxis.p2c = function() { return lonlat[0]; };
415417
_this.yaxis.p2c = function() { return lonlat[1]; };
416418

417419
Fx.hover(gd, d3.event, _this.id);
418420
});
419421

420-
framework.on('mouseout', function() {
421-
Fx.loneUnhover(fullLayout._toppaper);
422+
bgRect.on('mouseout', function() {
423+
dragElement.unhover(gd, d3.event);
422424
});
423425

424-
framework.on('click', function() {
426+
bgRect.on('click', function() {
425427
Fx.click(gd, d3.event);
426428
});
427429
};

test/jasmine/tests/geo_test.js

+42-7
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ function move(fromX, fromY, toX, toY, delay) {
3030
}
3131

3232
describe('Test Geo layout defaults', function() {
33-
'use strict';
34-
3533
var layoutAttributes = Geo.layoutAttributes;
3634
var supplyLayoutDefaults = Geo.supplyLayoutDefaults;
3735

@@ -461,8 +459,6 @@ describe('Test Geo layout defaults', function() {
461459
});
462460

463461
describe('geojson / topojson utils', function() {
464-
'use strict';
465-
466462
function _locationToFeature(topojson, loc, locationmode) {
467463
var trace = { locationmode: locationmode };
468464
var features = topojsonUtils.getTopojsonFeatures(trace, topojson);
@@ -523,8 +519,6 @@ describe('geojson / topojson utils', function() {
523519
});
524520

525521
describe('Test geo interactions', function() {
526-
'use strict';
527-
528522
afterEach(destroyGraphDiv);
529523

530524
describe('mock geo_first.json', function() {
@@ -1166,8 +1160,49 @@ describe('Test geo interactions', function() {
11661160
.catch(fail)
11671161
.then(done);
11681162
});
1169-
});
11701163

1164+
it('@noCI should clear hover label when cursor slips off subplot', function(done) {
1165+
var gd = createGraphDiv();
1166+
var fig = Lib.extendDeep({}, require('@mocks/geo_orthographic.json'));
1167+
1168+
function _assert(msg, hoverLabelCnt) {
1169+
expect(d3.selectAll('g.hovertext').size())
1170+
.toBe(hoverLabelCnt, msg);
1171+
}
1172+
1173+
var px = 390;
1174+
var py = 290;
1175+
var cnt = 0;
1176+
1177+
Plotly.plot(gd, fig).then(function() {
1178+
gd.on('plotly_unhover', function() { cnt++; });
1179+
1180+
mouseEvent('mousemove', px, py);
1181+
_assert('base state', 1);
1182+
1183+
return new Promise(function(resolve) {
1184+
var interval = setInterval(function() {
1185+
px += 2;
1186+
mouseEvent('mousemove', px, py);
1187+
1188+
if(px < 402) {
1189+
_assert('- px ' + px, 1);
1190+
expect(cnt).toBe(0, 'no plotly_unhover event so far');
1191+
} else {
1192+
_assert('- px ' + px, 0);
1193+
expect(cnt).toBe(1, 'plotly_unhover event count');
1194+
1195+
clearInterval(interval);
1196+
resolve();
1197+
}
1198+
}, 100);
1199+
});
1200+
})
1201+
.catch(fail)
1202+
.then(done);
1203+
});
1204+
1205+
});
11711206

11721207
describe('Test event property of interactions on a geo plot:', function() {
11731208
var mock = require('@mocks/geo_scattergeo-locations.json');

0 commit comments

Comments
 (0)