Skip to content

Commit

Permalink
Merge pull request #3715 from plotly/bar-textfont-wo-fix
Browse files Browse the repository at this point in the history
Don't try to access textfont when bar has no text
  • Loading branch information
etpinard committed Apr 2, 2019
2 parents e8b9009 + e975e99 commit e8d300b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
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

0 comments on commit e8d300b

Please sign in to comment.