]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Sample only if specified option value is smaller than number of ticks (#6572)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Fri, 18 Oct 2019 00:47:00 +0000 (17:47 -0700)
committerEvert Timberg <evert.timberg+github@gmail.com>
Fri, 18 Oct 2019 00:47:00 +0000 (20:47 -0400)
src/core/core.scale.js

index 44ce92505b980e8ae5c284e2d3369ca3e2509850..95a5f5c5f6ca69341ec87bd5f278ca1da73bcd25 100644 (file)
@@ -280,7 +280,7 @@ var Scale = Element.extend({
                var me = this;
                var tickOpts = me.options.ticks;
                var sampleSize = tickOpts.sampleSize;
-               var i, ilen, labels, ticks;
+               var i, ilen, labels, ticks, samplingEnabled;
 
                // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
                me.beforeUpdate();
@@ -345,7 +345,8 @@ var Scale = Element.extend({
 
                // Compute tick rotation and fit using a sampled subset of labels
                // We generally don't need to compute the size of every single label for determining scale size
-               labels = me._convertTicksToLabels(sampleSize ? sample(ticks, sampleSize) : ticks);
+               samplingEnabled = sampleSize > ticks.length;
+               labels = me._convertTicksToLabels(samplingEnabled ? sample(ticks, sampleSize) : ticks);
 
                // _configure is called twice, once here, once from core.controller.updateLayout.
                // Here we haven't been positioned yet, but dimensions are correct.
@@ -365,7 +366,7 @@ var Scale = Element.extend({
                // Auto-skip
                me._ticksToDraw = tickOpts.display && tickOpts.autoSkip ? me._autoSkip(ticks) : ticks;
 
-               if (sampleSize) {
+               if (samplingEnabled) {
                        // Generate labels using all non-skipped ticks
                        labels = me._convertTicksToLabels(me._ticksToDraw);
                }