Skip to content

Fix for number 0 treated as invalid in hover (#1) #2682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
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/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ drawing.textPointStyle = function(s, trace, gd) {
var p = d3.select(this);
var text = Lib.extractOption(d, trace, 'tx', 'text');

if(!text) {
if(!text && text !== 0) {
p.remove();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ function createHoverText(hoverData, opts, gd) {
else if(d.yLabel === undefined) text = d.xLabel;
else text = '(' + d.xLabel + ', ' + d.yLabel + ')';

if(d.text && !Array.isArray(d.text)) {
if((d.text || d.text === 0) && !Array.isArray(d.text)) {
text += (text ? '<br>' : '') + d.text;
}

Expand Down
40 changes: 40 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,46 @@ describe('hover info', function() {
});
});

describe('hover info text with 0', function() {
var mockCopy = Lib.extendDeep({}, mock);

mockCopy.data[0].text = [];
// we treat number 0 as valid text
// see https://github.com/plotly/plotly.js/issues/2660
mockCopy.data[0].text[17] = 0;
mockCopy.data[0].hoverinfo = 'text';
mockCopy.data[0].mode = 'lines+markers+text';

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
});

it('responds to hover text', function() {
var gd = document.getElementById('graph');
Fx.hover('graph', evt, 'xy');

var hoverTrace = gd._hoverdata[0];

expect(hoverTrace.curveNumber).toBe(0);
expect(hoverTrace.pointNumber).toBe(17);
expect(hoverTrace.x).toBe(0.388);
expect(hoverTrace.y).toBe(1);
expect(hoverTrace.text).toBe(0);

var txs = d3.select(gd).selectAll('.textpoint text');

expect(txs.size()).toBe(1);

txs.each(function() {
expect(d3.select(this).text()).toBe('0');
});

assertHoverLabelContent({
nums: '0'
});
});
});

describe('hover info all', function() {
var mockCopy = Lib.extendDeep({}, mock);

Expand Down