]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Properly initialize variables if ticks aren't being displayed (#6100)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Mon, 4 Mar 2019 08:15:29 +0000 (00:15 -0800)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Mon, 4 Mar 2019 08:15:29 +0000 (09:15 +0100)
src/core/core.scale.js

index 5384e323613c7220cf6e2dc7b0ba0182fdadc109..1f65bc564b6e39f0eafe285a3ea85875025840ea 100644 (file)
@@ -171,6 +171,9 @@ module.exports = Element.extend({
                        top: 0,
                        bottom: 0
                }, margins);
+
+               me._maxLabelLines = 0;
+               me.longestLabelWidth = 0;
                me.longestTextCache = me.longestTextCache || {};
 
                // Dimensions
@@ -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);
@@ -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
@@ -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;