Skip to content

Commit 96a7b12

Browse files
committed
rm bartext element (if any) in update selection
... when tx item is blank or textposition is 'none'
1 parent 253212d commit 96a7b12

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/traces/bar/plot.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
189189
orientation = trace.orientation;
190190

191191
var text = getText(trace, i);
192-
if(!text) return;
193-
194192
textPosition = getTextPosition(trace, i);
195-
if(textPosition === 'none') return;
193+
194+
if(!text || textPosition === 'none') {
195+
bar.select('text').remove();
196+
return;
197+
}
196198

197199
var textFont = getTextFont(trace, i, gd._fullLayout.font),
198200
insideTextFont = getInsideTextFont(trace, i, textFont),

test/jasmine/tests/bar_test.js

+37
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,43 @@ describe('A bar plot', function() {
12941294
.catch(fail)
12951295
.then(done);
12961296
});
1297+
1298+
it('should be able to add/remove text node on restyle', function(done) {
1299+
function _assertNumberOfBarTextNodes(cnt) {
1300+
var sel = d3.select(gd).select('.barlayer').selectAll('text');
1301+
expect(sel.size()).toBe(cnt);
1302+
}
1303+
1304+
Plotly.plot(gd, [{
1305+
type: 'bar',
1306+
x: ['Product A', 'Product B', 'Product C'],
1307+
y: [20, 14, 23],
1308+
text: [20, 14, 23],
1309+
textposition: 'auto'
1310+
}])
1311+
.then(function() {
1312+
_assertNumberOfBarTextNodes(3);
1313+
return Plotly.restyle(gd, 'textposition', 'none');
1314+
})
1315+
.then(function() {
1316+
_assertNumberOfBarTextNodes(0);
1317+
return Plotly.restyle(gd, 'textposition', 'auto');
1318+
})
1319+
.then(function() {
1320+
_assertNumberOfBarTextNodes(3);
1321+
return Plotly.restyle(gd, 'text', [[null, 0, '']]);
1322+
})
1323+
.then(function() {
1324+
// N.B. that '0' should be there!
1325+
_assertNumberOfBarTextNodes(1);
1326+
return Plotly.restyle(gd, 'text', 'yo!');
1327+
})
1328+
.then(function() {
1329+
_assertNumberOfBarTextNodes(3);
1330+
})
1331+
.catch(fail)
1332+
.then(done);
1333+
});
12971334
});
12981335

12991336
describe('bar hover', function() {

0 commit comments

Comments
 (0)