Skip to content

Commit

Permalink
Properly initialize variables if ticks aren't being displayed (#6100)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored and simonbrunel committed Mar 4, 2019
1 parent 344628b commit 858cc80
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ module.exports = Element.extend({
top: 0,
bottom: 0
}, margins);

me._maxLabelLines = 0;
me.longestLabelWidth = 0;
me.longestTextCache = me.longestTextCache || {};

// Dimensions
Expand Down Expand Up @@ -419,20 +422,18 @@ module.exports = Element.extend({
}
}

// Don't bother fitting the ticks if we are not showing them
// Don't bother fitting the ticks if we are not showing the labels
if (tickOpts.display && display) {
var largestTextWidth = helpers.longestText(me.ctx, tickFont.string, labels, me.longestTextCache);
var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
var lineSpace = tickFont.size * 0.5;
var tickPadding = me.options.ticks.padding;

// Store max number of lines used in labels for _autoSkip
// Store max number of lines and widest label for _autoSkip
me._maxLabelLines = tallestLabelHeightInLines;
me.longestLabelWidth = largestTextWidth;

if (isHorizontal) {
// A horizontal axis is more constrained by the height.
me.longestLabelWidth = largestTextWidth;

var angleRadians = helpers.toRadians(me.labelRotation);
var cosRotation = Math.cos(angleRadians);
var sinRotation = Math.sin(angleRadians);
Expand Down Expand Up @@ -679,11 +680,11 @@ module.exports = Element.extend({
var cos = Math.abs(Math.cos(rot));
var sin = Math.abs(Math.sin(rot));

var padding = optionTicks.autoSkipPadding;
var w = me.longestLabelWidth + padding || 0;
var padding = optionTicks.autoSkipPadding || 0;
var w = (me.longestLabelWidth + padding) || 0;

var tickFont = helpers.options._parseFont(optionTicks);
var h = me._maxLabelLines * tickFont.lineHeight + padding;
var h = (me._maxLabelLines * tickFont.lineHeight + padding) || 0;

// Calculate space needed for 1 tick in axis direction.
return isHorizontal
Expand Down Expand Up @@ -744,7 +745,7 @@ module.exports = Element.extend({
var isHorizontal = me.isHorizontal();

var parseFont = helpers.options._parseFont;
var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
var ticks = optionTicks.display && optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
var tickFontColor = valueOrDefault(optionTicks.fontColor, defaultFontColor);
var tickFont = parseFont(optionTicks);
var lineHeight = tickFont.lineHeight;
Expand Down

0 comments on commit 858cc80

Please sign in to comment.