Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
@@ -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 ? '<br>' : '') + d.text;
if(d.text && !Array.isArray(d.text)) text += (text ? '<br>' : '') + d.text;

// if 'text' is empty at this point,
// put 'name' in main label and don't show secondary label
47 changes: 46 additions & 1 deletion test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});