Skip to content

Commit 683f601

Browse files
authored
Merge pull request #5954 from dwoznicki/fix-scatter3d-unhover
Fix unhover event data for gl3d subplots
2 parents 073b327 + 6d3b3c0 commit 683f601

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

draftlogs/5954_fix.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Fix unhover event data for gl3d subplots [[#5954](https://github.com/plotly/plotly.js/pull/5954)],
2+
with thanks to @dwoznicki for the contribution!
3+

src/plots/gl3d/scene.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ proto.render = function() {
332332
return Axes.hoverLabelText(ax, val, hoverformat);
333333
}
334334

335-
var oldEventData;
336-
337335
if(lastPicked !== null) {
338336
var pdata = project(scene.glplot.cameraParams, selection.dataCoordinate);
339337
trace = lastPicked.data;
@@ -456,10 +454,11 @@ proto.render = function() {
456454
gd.emit('plotly_hover', eventData);
457455
}
458456

459-
oldEventData = eventData;
457+
this.oldEventData = eventData;
460458
} else {
461459
Fx.loneUnhover(svgContainer);
462-
gd.emit('plotly_unhover', oldEventData);
460+
if(this.oldEventData) gd.emit('plotly_unhover', this.oldEventData);
461+
this.oldEventData = undefined;
463462
}
464463

465464
scene.drawAnnotations(scene);

test/jasmine/tests/gl3d_hover_click_test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,81 @@ describe('Test gl3d trace click/hover:', function() {
12681268
});
12691269
});
12701270
});
1271+
1272+
it('@gl should emit correct event data on unhover', function(done) {
1273+
var _mock = Lib.extendDeep({}, mock2);
1274+
var x = 655;
1275+
var y = 221;
1276+
1277+
function _hover() {
1278+
mouseEvent('mouseover', x, y);
1279+
}
1280+
1281+
function _unhover() {
1282+
return new Promise(function(resolve) {
1283+
var x0 = x;
1284+
var y0 = y;
1285+
var initialElement = document.elementFromPoint(x0, y0);
1286+
var canceler = setInterval(function() {
1287+
x0 -= 2;
1288+
y0 -= 2;
1289+
mouseEvent('mouseover', x0, y0);
1290+
1291+
var nowElement = document.elementFromPoint(x0, y0);
1292+
if(nowElement !== initialElement) {
1293+
mouseEvent('mouseout', x0, y0, {element: initialElement});
1294+
}
1295+
}, 10);
1296+
1297+
gd.on('plotly_unhover', function(eventData) {
1298+
clearInterval(canceler);
1299+
resolve(eventData);
1300+
});
1301+
1302+
setTimeout(function() {
1303+
clearInterval(canceler);
1304+
resolve(null);
1305+
}, 350);
1306+
});
1307+
}
1308+
1309+
Plotly.newPlot(gd, _mock)
1310+
.then(delay(20))
1311+
.then(function() {
1312+
gd.on('plotly_hover', function(eventData) {
1313+
ptData = eventData.points[0];
1314+
});
1315+
gd.on('plotly_unhover', function(eventData) {
1316+
if(eventData) {
1317+
ptData = eventData.points[0];
1318+
} else {
1319+
ptData = {};
1320+
}
1321+
});
1322+
})
1323+
.then(delay(20))
1324+
.then(_hover)
1325+
.then(delay(20))
1326+
.then(function() {
1327+
assertEventData(100.75, -102.63, -102.63, 0, 0, {
1328+
'marker.symbol': 'circle',
1329+
'marker.size': 10,
1330+
'marker.color': 'blue',
1331+
'marker.line.color': 'black'
1332+
});
1333+
})
1334+
.then(_unhover)
1335+
.then(delay(20))
1336+
.then(function() {
1337+
assertEventData(100.75, -102.63, -102.63, 0, 0, {
1338+
'marker.symbol': 'circle',
1339+
'marker.size': 10,
1340+
'marker.color': 'blue',
1341+
'marker.line.color': 'black'
1342+
});
1343+
})
1344+
.then(done, done.fail);
1345+
});
12711346
});
12721347

12731348
describe('hover on traces with (x|y|z|u|v|w)hoverformat and valuehoverformat', function() {

0 commit comments

Comments
 (0)