Skip to content

Commit 0a19b64

Browse files
authored
Merge pull request #4213 from plotly/fix-scattergl-hover-over-nulls
Fix scattergl hover over nulls
2 parents 43c4e0d + 5d9bd0a commit 0a19b64

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

src/traces/scattergl/hover.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ function hoverPoints(pointData, xval, yval, hovermode) {
4343
Math.max(xl, xr), Math.max(yl, yr)
4444
);
4545
}
46-
} else if(stash.ids) {
46+
} else {
4747
ids = stash.ids;
48-
} else return [pointData];
48+
}
4949

5050
// pick the id closest to the point
5151
// note that point possibly may not be found
@@ -84,9 +84,7 @@ function hoverPoints(pointData, xval, yval, hovermode) {
8484

8585
if(id === undefined) return [pointData];
8686

87-
calcHover(pointData, x, y, trace);
88-
89-
return [pointData];
87+
return [calcHover(pointData, x, y, trace)];
9088
}
9189

9290
function calcHover(pointData, x, y, trace) {
@@ -163,7 +161,7 @@ function calcHover(pointData, x, y, trace) {
163161
var fakeCd = {};
164162
fakeCd[pointData.index] = di;
165163

166-
Lib.extendFlat(pointData, {
164+
var pointData2 = Lib.extendFlat({}, pointData, {
167165
color: getTraceColor(trace, di),
168166

169167
x0: xp - rad,
@@ -181,14 +179,14 @@ function calcHover(pointData, x, y, trace) {
181179
hovertemplate: di.ht
182180
});
183181

184-
if(di.htx) pointData.text = di.htx;
185-
else if(di.tx) pointData.text = di.tx;
186-
else if(trace.text) pointData.text = trace.text;
182+
if(di.htx) pointData2.text = di.htx;
183+
else if(di.tx) pointData2.text = di.tx;
184+
else if(trace.text) pointData2.text = trace.text;
187185

188-
Lib.fillText(di, trace, pointData);
189-
Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);
186+
Lib.fillText(di, trace, pointData2);
187+
Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData2);
190188

191-
return pointData;
189+
return pointData2;
192190
}
193191

194192
module.exports = {

src/traces/splom/hover.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ function hoverPoints(pointData, xval, yval) {
5151

5252
if(id === undefined) return [pointData];
5353

54-
calcHover(pointData, x, y, trace);
55-
56-
return [pointData];
54+
return [calcHover(pointData, x, y, trace)];
5755
}
5856

5957
module.exports = {

test/jasmine/tests/gl2d_click_test.js

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

349+
it('@gl should not error when scattergl trace has missing points', function(done) {
350+
var _mock = {
351+
data: [{
352+
type: 'scattergl',
353+
mode: 'markers',
354+
x: [1, 2, 3, 4],
355+
y: [10, 15, null, 17],
356+
}],
357+
layout: {
358+
width: 500,
359+
height: 500
360+
}
361+
};
362+
363+
Plotly.plot(gd, _mock)
364+
.then(function() {
365+
gd.on('plotly_hover', function() {
366+
fail('should not trigger plotly_hover event');
367+
});
368+
})
369+
.then(function() {
370+
var xp = 300;
371+
var yp = 250;
372+
var interval = setInterval(function() { hover(xp--, yp--); }, 10);
373+
return delay(100)().then(function() { clearInterval(interval); });
374+
})
375+
.catch(failTest)
376+
.then(done);
377+
});
378+
349379
it('@gl should show last point data for overlapped scattergl points with hovermode set to closest', function(done) {
350380
var _mock = Lib.extendDeep({}, mock1);
351381
_mock.data[0].hovertext = 'text';

0 commit comments

Comments
 (0)