Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd9cb3f

Browse files
committed
fix scattermapbox handling of '' text items
1 parent fc6dfe1 commit fd9cb3f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/traces/scattermapbox/hover.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ function getExtraText(trace, di) {
8686
else if(hasLat) text.push('lat: ' + format(lonlat[1]));
8787

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

9293
return text.join('<br>');

test/jasmine/tests/scattermapbox_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,36 @@ describe('scattermapbox hover', function() {
494494
expect(out.color).toEqual('#1f77b4');
495495
});
496496

497+
it('should skip over blank and non-string text items', function(done) {
498+
var xval = 11,
499+
yval = 11,
500+
out;
501+
502+
Plotly.restyle(gd, 'text', [['', 'B', 'C']]).then(function() {
503+
out = hoverPoints(getPointData(gd), xval, yval)[0];
504+
expect(out.extraText).toEqual('(10°, 10°)');
505+
506+
return Plotly.restyle(gd, 'text', [[null, 'B', 'C']]);
507+
})
508+
.then(function() {
509+
out = hoverPoints(getPointData(gd), xval, yval)[0];
510+
expect(out.extraText).toEqual('(10°, 10°)');
511+
512+
return Plotly.restyle(gd, 'text', [[false, 'B', 'C']]);
513+
})
514+
.then(function() {
515+
out = hoverPoints(getPointData(gd), xval, yval)[0];
516+
expect(out.extraText).toEqual('(10°, 10°)');
517+
518+
return Plotly.restyle(gd, 'text', [['A', 'B', 'C']]);
519+
})
520+
.then(function() {
521+
out = hoverPoints(getPointData(gd), xval, yval)[0];
522+
expect(out.extraText).toEqual('(10°, 10°)<br>A');
523+
})
524+
.then(done);
525+
});
526+
497527
it('should generate hover label info (positive winding case)', function() {
498528
var xval = 11 + 720,
499529
yval = 11;

0 commit comments

Comments
 (0)