Skip to content

Commit

Permalink
fix #4212 - create new pointData object instead extending original
Browse files Browse the repository at this point in the history
... so that we don't mutate pointData.cd and propagate 'fake'
    `gd.calcdata[i][j]` to subsequent _module.hoverPoints calls.
  • Loading branch information
etpinard committed Sep 23, 2019
1 parent 184c0b0 commit 880b7e9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/traces/scattergl/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ function hoverPoints(pointData, xval, yval, hovermode) {

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

calcHover(pointData, x, y, trace);

return [pointData];
return [calcHover(pointData, x, y, trace)];
}

function calcHover(pointData, x, y, trace) {
Expand Down Expand Up @@ -163,7 +161,7 @@ function calcHover(pointData, x, y, trace) {
var fakeCd = {};
fakeCd[pointData.index] = di;

Lib.extendFlat(pointData, {
var pointData2 = Lib.extendFlat({}, pointData, {
color: getTraceColor(trace, di),

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

if(di.htx) pointData.text = di.htx;
else if(di.tx) pointData.text = di.tx;
else if(trace.text) pointData.text = trace.text;
if(di.htx) pointData2.text = di.htx;
else if(di.tx) pointData2.text = di.tx;
else if(trace.text) pointData2.text = trace.text;

Lib.fillText(di, trace, pointData);
Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);
Lib.fillText(di, trace, pointData2);
Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData2);

return pointData;
return pointData2;
}

module.exports = {
Expand Down
4 changes: 1 addition & 3 deletions src/traces/splom/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function hoverPoints(pointData, xval, yval) {

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

calcHover(pointData, x, y, trace);

return [pointData];
return [calcHover(pointData, x, y, trace)];
}

module.exports = {
Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/gl2d_click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,36 @@ describe('Test hover and click interactions', function() {
.then(done);
});

it('@gl should not error when scattergl trace has missing points', function(done) {
var _mock = {
data: [{
type: 'scattergl',
mode: 'markers',
x: [1, 2, 3, 4],
y: [10, 15, null, 17],
}],
layout: {
width: 500,
height: 500
}
};

Plotly.plot(gd, _mock)
.then(function() {
gd.on('plotly_hover', function() {
fail('should not trigger plotly_hover event');
});
})
.then(function() {
var xp = 300;
var yp = 250;
var interval = setInterval(function() { hover(xp--, yp--); }, 10);
return delay(100)().then(function() { clearInterval(interval); });
})
.catch(failTest)
.then(done);
});

it('@gl should show last point data for overlapped scattergl points with hovermode set to closest', function(done) {
var _mock = Lib.extendDeep({}, mock1);
_mock.data[0].hovertext = 'text';
Expand Down

0 comments on commit 880b7e9

Please sign in to comment.