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

Skip to content

Commit 9df444d

Browse files
committed
fix scattergeo handling of '' text items
1 parent fd9cb3f commit 9df444d

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/traces/scattergeo/hover.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ function getExtraText(trace, pt, axis) {
102102
else if(hasLon) text.push('lon: ' + format(pt.lonlat[0]));
103103
else if(hasLat) text.push('lat: ' + format(pt.lonlat[1]));
104104

105-
if(hasText) text.push(pt.tx || trace.text);
105+
if(hasText) {
106+
var tx = pt.tx || trace.text;
107+
if(!Array.isArray(tx)) text.push(tx);
108+
}
106109

107110
return text.join('<br>');
108111
}

test/jasmine/tests/geo_test.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,25 +420,54 @@ describe('Test geo interactions', function() {
420420
});
421421

422422
describe('scattergeo hover labels', function() {
423-
beforeEach(function() {
424-
mouseEventScatterGeo('mousemove');
425-
});
426-
427423
it('should show one hover text group', function() {
424+
mouseEventScatterGeo('mousemove');
428425
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
429426
});
430427

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

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

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

438+
var node = d3.selectAll('g.hovertext').selectAll('text')[0][0];
440439
expect(node.innerHTML).toEqual('trace 0');
441440
});
441+
442+
it('should show *text* (case 1)', function(done) {
443+
Plotly.restyle(gd, 'text', [['A', 'B']]).then(function() {
444+
mouseEventScatterGeo('mousemove');
445+
446+
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
447+
expect(node.innerHTML).toEqual('A');
448+
})
449+
.then(done);
450+
});
451+
452+
it('should show *text* (case 2)', function(done) {
453+
Plotly.restyle(gd, 'text', [[null, 'B']]).then(function() {
454+
mouseEventScatterGeo('mousemove');
455+
456+
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
457+
expect(node).toBeUndefined();
458+
})
459+
.then(done);
460+
});
461+
462+
it('should show *text* (case 3)', function(done) {
463+
Plotly.restyle(gd, 'text', [['', 'B']]).then(function() {
464+
mouseEventScatterGeo('mousemove');
465+
466+
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
467+
expect(node).toBeUndefined();
468+
})
469+
.then(done);
470+
});
442471
});
443472

444473
describe('scattergeo hover events', function() {

0 commit comments

Comments
 (0)