Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scattergl hover over nulls #4213

Merged
merged 2 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/traces/scattergl/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function hoverPoints(pointData, xval, yval, hovermode) {
Math.max(xl, xr), Math.max(yl, yr)
);
}
} else if(stash.ids) {
} else {
ids = stash.ids;
} else return [pointData];
}

// pick the id closest to the point
// note that point possibly may not be found
Expand Down 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) {
archmoj marked this conversation as resolved.
Show resolved Hide resolved
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