Skip to content
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
18 changes: 9 additions & 9 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
var text = getText(trace, i);
textPosition = getTextPosition(trace, i);

var layoutFont = fullLayout.font;
var barColor = style.getBarColor(calcTrace[i], trace);
var insideTextFont = style.getInsideTextFont(trace, i, layoutFont, barColor);
var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont);

// compute text position
var prefix = trace.type === 'waterfall' ? 'waterfall' : 'bar';
var barmode = fullLayout[prefix + 'mode'];
Expand All @@ -218,16 +213,21 @@ function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
var calcBar = calcTrace[i];
var isOutmostBar = !inStackOrRelativeMode || calcBar._outmost;

// padding excluded
var barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD;
var barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD;

if(!text || textPosition === 'none' ||
(calcBar.isBlank && (textPosition === 'auto' || textPosition === 'inside'))) {
bar.select('text').remove();
return;
}

var layoutFont = fullLayout.font;
var barColor = style.getBarColor(calcTrace[i], trace);
var insideTextFont = style.getInsideTextFont(trace, i, layoutFont, barColor);
var outsideTextFont = style.getOutsideTextFont(trace, i, layoutFont);

// padding excluded
var barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD;
var barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD;

var textSelection;
var textBB;
var textWidth;
Expand Down
14 changes: 14 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,20 @@ describe('A bar plot', function() {
.catch(failTest)
.then(done);
});

it('should not error out when *textfont* is set in traces w/o *text*', function(done) {
Plotly.plot(gd, [{
type: 'bar',
x: ['A', 'K', 'M', 'O', 'Q', 'S', 'T', 'V', 'X', 'Z', 'D', 'F', 'H'],
y: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25],
textfont: {color: 'red'}
}])
.then(function() {
expect(getAllBarNodes(gd).length).toBe(13, '# of bars');
})
.catch(failTest)
.then(done);
});
});

describe('bar visibility toggling:', function() {
Expand Down