Skip to content

Commit

Permalink
Merge pull request #2689 from plotly/fixup-bar-text-removal
Browse files Browse the repository at this point in the history
Fixup bartext removal in update selections
  • Loading branch information
etpinard committed Jun 4, 2018
2 parents 253212d + 96a7b12 commit da193d7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
orientation = trace.orientation;

var text = getText(trace, i);
if(!text) return;

textPosition = getTextPosition(trace, i);
if(textPosition === 'none') return;

if(!text || textPosition === 'none') {
bar.select('text').remove();
return;
}

var textFont = getTextFont(trace, i, gd._fullLayout.font),
insideTextFont = getInsideTextFont(trace, i, textFont),
Expand Down
37 changes: 37 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,43 @@ describe('A bar plot', function() {
.catch(fail)
.then(done);
});

it('should be able to add/remove text node on restyle', function(done) {
function _assertNumberOfBarTextNodes(cnt) {
var sel = d3.select(gd).select('.barlayer').selectAll('text');
expect(sel.size()).toBe(cnt);
}

Plotly.plot(gd, [{
type: 'bar',
x: ['Product A', 'Product B', 'Product C'],
y: [20, 14, 23],
text: [20, 14, 23],
textposition: 'auto'
}])
.then(function() {
_assertNumberOfBarTextNodes(3);
return Plotly.restyle(gd, 'textposition', 'none');
})
.then(function() {
_assertNumberOfBarTextNodes(0);
return Plotly.restyle(gd, 'textposition', 'auto');
})
.then(function() {
_assertNumberOfBarTextNodes(3);
return Plotly.restyle(gd, 'text', [[null, 0, '']]);
})
.then(function() {
// N.B. that '0' should be there!
_assertNumberOfBarTextNodes(1);
return Plotly.restyle(gd, 'text', 'yo!');
})
.then(function() {
_assertNumberOfBarTextNodes(3);
})
.catch(fail)
.then(done);
});
});

describe('bar hover', function() {
Expand Down

0 comments on commit da193d7

Please sign in to comment.