From ffc87757e04ec8b25df5cf701b26d13df97bd4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Wed, 2 Mar 2016 16:10:50 -0500 Subject: [PATCH 1/3] Add check for array of text labels --- src/plots/cartesian/graph_interact.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index b84eb742273..ea28207d0eb 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -933,7 +933,7 @@ function createHoverText(hoverData, opts) { else if(d.yLabel===undefined) text = d.xLabel; else text = '('+d.xLabel+', '+d.yLabel+')'; - if(d.text) text += (text ? '
' : '') + d.text; + if(d.text && !Array.isArray(d.text)) text += (text ? '
' : '') + d.text; // if 'text' is empty at this point, // put 'name' in main label and don't show secondary label From 08d2e06664018af5848b3a1d106b5075d78571d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Wed, 2 Mar 2016 16:55:44 -0500 Subject: [PATCH 2/3] Add tests for hover label text --- test/jasmine/tests/hover_label_test.js | 49 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index ee1395464ba..4ea18f1e224 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -8,7 +8,7 @@ var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); -describe('hover info', function() { +fdescribe('hover info', function() { 'use strict'; var mock = require('@mocks/14.json'), @@ -257,7 +257,7 @@ describe('hover info', function() { }; beforeEach(function() { - this. gd = createGraphDiv(); + this.gd = createGraphDiv(); }); it('should display the correct format when ticklabels true', function() { @@ -281,4 +281,49 @@ describe('hover info', function() { expect(hovers.select('text')[0][0].textContent).toEqual('0.23'); }); }); + + describe('textmode', function() { + + var data = [{ + x: [1,2,3,4], + y: [2,3,4,5], + mode: 'text', + hoverinfo: 'text', + text: ['test', null, 42, undefined] + }], + layout = { + width: 600, + height: 400 + }; + + beforeEach(function(done) { + Plotly.plot(createGraphDiv(), data, layout).then(done); + }); + + it('should show text labels', function() { + mouseEvent('mousemove', 115, 310); + var hovers = d3.selectAll('g.hovertext'); + expect(hovers.size()).toEqual(1); + expect(hovers.select('text')[0][0].textContent).toEqual('test'); + }); + + it('should show number labels', function() { + mouseEvent('mousemove', 370, 180); + var hovers = d3.selectAll('g.hovertext'); + expect(hovers.size()).toEqual(1); + expect(hovers.select('text')[0][0].textContent).toEqual('42'); + }); + + it('should not show null text labels', function() { + mouseEvent('mousemove', 236, 246); + var hovers = d3.selectAll('g.hovertext'); + expect(hovers.size()).toEqual(0); + }); + + it('should not show undefined text labels', function() { + mouseEvent('mousemove', 500, 115); + var hovers = d3.selectAll('g.hovertext'); + expect(hovers.size()).toEqual(0); + }); + }); }); From 07367437e8b39d301c4d18ed041026bd11ec7d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Tusz?= Date: Wed, 2 Mar 2016 16:56:34 -0500 Subject: [PATCH 3/3] Remove fdescribe block --- test/jasmine/tests/hover_label_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index 4ea18f1e224..55ae4642b07 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -8,7 +8,7 @@ var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var mouseEvent = require('../assets/mouse_event'); -fdescribe('hover info', function() { +describe('hover info', function() { 'use strict'; var mock = require('@mocks/14.json'),