From fd9cb3ff0c4e58320732de25656b31efef946eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 4 Jan 2017 17:31:08 -0500 Subject: [PATCH 1/2] fix scattermapbox handling of '' text items --- src/traces/scattermapbox/hover.js | 3 ++- test/jasmine/tests/scattermapbox_test.js | 30 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/traces/scattermapbox/hover.js b/src/traces/scattermapbox/hover.js index d59a05219e0..088d35f6dc5 100644 --- a/src/traces/scattermapbox/hover.js +++ b/src/traces/scattermapbox/hover.js @@ -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('
'); diff --git a/test/jasmine/tests/scattermapbox_test.js b/test/jasmine/tests/scattermapbox_test.js index 80fede37ff6..1e9556f44cd 100644 --- a/test/jasmine/tests/scattermapbox_test.js +++ b/test/jasmine/tests/scattermapbox_test.js @@ -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°)
A'); + }) + .then(done); + }); + it('should generate hover label info (positive winding case)', function() { var xval = 11 + 720, yval = 11; From 9df444da8f270ad514451f015122b4a6f35ed7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Wed, 4 Jan 2017 17:31:16 -0500 Subject: [PATCH 2/2] fix scattergeo handling of '' text items --- src/traces/scattergeo/hover.js | 5 ++++- test/jasmine/tests/geo_test.js | 41 +++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/traces/scattergeo/hover.js b/src/traces/scattergeo/hover.js index 0f09791f714..3e3c54f5bd7 100644 --- a/src/traces/scattergeo/hover.js +++ b/src/traces/scattergeo/hover.js @@ -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('
'); } diff --git a/test/jasmine/tests/geo_test.js b/test/jasmine/tests/geo_test.js index 09c0ab37f65..244db755d2c 100644 --- a/test/jasmine/tests/geo_test.js +++ b/test/jasmine/tests/geo_test.js @@ -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() {