Skip to content

Fix scattermapbox and scattergeo handling of '' text items #1283

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

Merged
merged 2 commits into from
Jan 5, 2017
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
5 changes: 4 additions & 1 deletion src/traces/scattergeo/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ function getExtraText(trace, pt, axis) {
else if(hasLon) text.push('lon: ' + format(pt.lonlat[0]));
else if(hasLat) text.push('lat: ' + format(pt.lonlat[1]));

if(hasText) text.push(pt.tx || trace.text);
if(hasText) {
var tx = pt.tx || trace.text;
if(!Array.isArray(tx)) text.push(tx);
}

return text.join('<br>');
}
3 changes: 2 additions & 1 deletion src/traces/scattermapbox/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function getExtraText(trace, di) {
else if(hasLat) text.push('lat: ' + format(lonlat[1]));

if(isAll || hoverinfo.indexOf('text') !== -1) {
text.push(di.tx || trace.text);
var tx = di.tx || trace.text;
if(!Array.isArray(tx)) text.push(tx);
}

return text.join('<br>');
Expand Down
41 changes: 35 additions & 6 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,25 +420,54 @@ describe('Test geo interactions', function() {
});

describe('scattergeo hover labels', function() {
beforeEach(function() {
mouseEventScatterGeo('mousemove');
});

it('should show one hover text group', function() {
mouseEventScatterGeo('mousemove');
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
});

it('should show longitude and latitude values', function() {
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][0];
mouseEventScatterGeo('mousemove');

var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][0];
expect(node.innerHTML).toEqual('(0°, 0°)');
});

it('should show the trace name', function() {
var node = d3.selectAll('g.hovertext').selectAll('text')[0][0];
mouseEventScatterGeo('mousemove');

var node = d3.selectAll('g.hovertext').selectAll('text')[0][0];
expect(node.innerHTML).toEqual('trace 0');
});

it('should show *text* (case 1)', function(done) {
Plotly.restyle(gd, 'text', [['A', 'B']]).then(function() {
mouseEventScatterGeo('mousemove');

var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
expect(node.innerHTML).toEqual('A');
})
.then(done);
});

it('should show *text* (case 2)', function(done) {
Plotly.restyle(gd, 'text', [[null, 'B']]).then(function() {
mouseEventScatterGeo('mousemove');

var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
expect(node).toBeUndefined();
})
.then(done);
});

it('should show *text* (case 3)', function(done) {
Plotly.restyle(gd, 'text', [['', 'B']]).then(function() {
mouseEventScatterGeo('mousemove');

var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
expect(node).toBeUndefined();
})
.then(done);
});
});

describe('scattergeo hover events', function() {
Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/scattermapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,36 @@ describe('scattermapbox hover', function() {
expect(out.color).toEqual('#1f77b4');
});

it('should skip over blank and non-string text items', function(done) {
var xval = 11,
yval = 11,
out;

Plotly.restyle(gd, 'text', [['', 'B', 'C']]).then(function() {
out = hoverPoints(getPointData(gd), xval, yval)[0];
expect(out.extraText).toEqual('(10°, 10°)');

return Plotly.restyle(gd, 'text', [[null, 'B', 'C']]);
})
.then(function() {
out = hoverPoints(getPointData(gd), xval, yval)[0];
expect(out.extraText).toEqual('(10°, 10°)');

return Plotly.restyle(gd, 'text', [[false, 'B', 'C']]);
})
.then(function() {
out = hoverPoints(getPointData(gd), xval, yval)[0];
expect(out.extraText).toEqual('(10°, 10°)');

return Plotly.restyle(gd, 'text', [['A', 'B', 'C']]);
})
.then(function() {
out = hoverPoints(getPointData(gd), xval, yval)[0];
expect(out.extraText).toEqual('(10°, 10°)<br>A');
})
.then(done);
});

it('should generate hover label info (positive winding case)', function() {
var xval = 11 + 720,
yval = 11;
Expand Down