Skip to content

Commit 297ecb7

Browse files
authored
Merge pull request #3924 from plotly/phx-241
fix for ScatterGL hover and click events give the 'top' point instead of the 'bottom' point
2 parents c9b377d + f72389d commit 297ecb7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/traces/scattergl/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ function hoverPoints(pointData, xval, yval, hovermode) {
732732
}
733733
}
734734
} else {
735-
for(i = 0; i < ids.length; i++) {
735+
for(i = ids.length - 1; i > -1; i--) {
736736
ptx = x[ids[i]];
737737
pty = y[ids[i]];
738738
dx = xa.c2p(ptx) - xpx;

test/jasmine/tests/gl2d_click_test.js

+41
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,47 @@ describe('Test hover and click interactions', function() {
346346
.then(done);
347347
});
348348

349+
it('@gl should show last point data for overlapped scattergl points with hovermode set to closest', function(done) {
350+
var _mock = Lib.extendDeep({}, mock1);
351+
_mock.data[0].hovertext = 'text';
352+
_mock.data[0].hovertext = 'HoVeRtExT';
353+
_mock.layout.hovermode = 'closest';
354+
355+
var run = makeRunner([200, 200], {
356+
x: 2,
357+
y: 0,
358+
label: ['(2, 0)\nTRUE', null],
359+
curveNumber: 0,
360+
pointNumber: 3,
361+
bgcolor: 'rgb(31, 119, 180)',
362+
bordercolor: 'rgb(255, 255, 255)',
363+
fontSize: 13,
364+
fontFamily: 'Arial',
365+
fontColor: 'rgb(255, 255, 255)'
366+
}, {
367+
msg: 'scattergl with hovertext'
368+
});
369+
370+
Plotly.plot(gd, {
371+
data: [{
372+
text: ['', 'FALSE', '', 'TRUE'],
373+
x: [1, 2, 3, 2],
374+
y: [0, 0, 0, 0],
375+
type: 'scattergl',
376+
mode: 'markers',
377+
marker: { size: 40 }
378+
}],
379+
layout: {
380+
width: 400,
381+
height: 400,
382+
hovermode: 'closest'
383+
}
384+
})
385+
.then(run)
386+
.catch(failTest)
387+
.then(done);
388+
});
389+
349390
it('@gl should output correct event data for pointcloud', function(done) {
350391
var _mock = Lib.extendDeep({}, mock2);
351392

0 commit comments

Comments
 (0)