Skip to content

Commit 81dcfd9

Browse files
committed
Merge pull request #310 from plotly/bug-hover-text-labels
Bug hover text labels
2 parents 7d3dce7 + 0736743 commit 81dcfd9

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/plots/cartesian/graph_interact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ function createHoverText(hoverData, opts) {
933933
else if(d.yLabel===undefined) text = d.xLabel;
934934
else text = '('+d.xLabel+', '+d.yLabel+')';
935935

936-
if(d.text) text += (text ? '<br>' : '') + d.text;
936+
if(d.text && !Array.isArray(d.text)) text += (text ? '<br>' : '') + d.text;
937937

938938
// if 'text' is empty at this point,
939939
// put 'name' in main label and don't show secondary label

test/jasmine/tests/hover_label_test.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe('hover info', function() {
257257
};
258258

259259
beforeEach(function() {
260-
this. gd = createGraphDiv();
260+
this.gd = createGraphDiv();
261261
});
262262

263263
it('should display the correct format when ticklabels true', function() {
@@ -281,4 +281,49 @@ describe('hover info', function() {
281281
expect(hovers.select('text')[0][0].textContent).toEqual('0.23');
282282
});
283283
});
284+
285+
describe('textmode', function() {
286+
287+
var data = [{
288+
x: [1,2,3,4],
289+
y: [2,3,4,5],
290+
mode: 'text',
291+
hoverinfo: 'text',
292+
text: ['test', null, 42, undefined]
293+
}],
294+
layout = {
295+
width: 600,
296+
height: 400
297+
};
298+
299+
beforeEach(function(done) {
300+
Plotly.plot(createGraphDiv(), data, layout).then(done);
301+
});
302+
303+
it('should show text labels', function() {
304+
mouseEvent('mousemove', 115, 310);
305+
var hovers = d3.selectAll('g.hovertext');
306+
expect(hovers.size()).toEqual(1);
307+
expect(hovers.select('text')[0][0].textContent).toEqual('test');
308+
});
309+
310+
it('should show number labels', function() {
311+
mouseEvent('mousemove', 370, 180);
312+
var hovers = d3.selectAll('g.hovertext');
313+
expect(hovers.size()).toEqual(1);
314+
expect(hovers.select('text')[0][0].textContent).toEqual('42');
315+
});
316+
317+
it('should not show null text labels', function() {
318+
mouseEvent('mousemove', 236, 246);
319+
var hovers = d3.selectAll('g.hovertext');
320+
expect(hovers.size()).toEqual(0);
321+
});
322+
323+
it('should not show undefined text labels', function() {
324+
mouseEvent('mousemove', 500, 115);
325+
var hovers = d3.selectAll('g.hovertext');
326+
expect(hovers.size()).toEqual(0);
327+
});
328+
});
284329
});

0 commit comments

Comments
 (0)