Skip to content

Commit daafbc7

Browse files
benmccannetimberg
authored andcommitted
Sample only if specified option value is smaller than number of ticks (#6572)
1 parent fc76610 commit daafbc7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/core/core.scale.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ var Scale = Element.extend({
280280
var me = this;
281281
var tickOpts = me.options.ticks;
282282
var sampleSize = tickOpts.sampleSize;
283-
var i, ilen, labels, ticks;
283+
var i, ilen, labels, ticks, samplingEnabled;
284284

285285
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
286286
me.beforeUpdate();
@@ -345,7 +345,8 @@ var Scale = Element.extend({
345345

346346
// Compute tick rotation and fit using a sampled subset of labels
347347
// We generally don't need to compute the size of every single label for determining scale size
348-
labels = me._convertTicksToLabels(sampleSize ? sample(ticks, sampleSize) : ticks);
348+
samplingEnabled = sampleSize > ticks.length;
349+
labels = me._convertTicksToLabels(samplingEnabled ? sample(ticks, sampleSize) : ticks);
349350

350351
// _configure is called twice, once here, once from core.controller.updateLayout.
351352
// Here we haven't been positioned yet, but dimensions are correct.
@@ -365,7 +366,7 @@ var Scale = Element.extend({
365366
// Auto-skip
366367
me._ticksToDraw = tickOpts.display && tickOpts.autoSkip ? me._autoSkip(ticks) : ticks;
367368

368-
if (sampleSize) {
369+
if (samplingEnabled) {
369370
// Generate labels using all non-skipped ticks
370371
labels = me._convertTicksToLabels(me._ticksToDraw);
371372
}

0 commit comments

Comments
 (0)