From 2eb432533ff5f27c06356ca7d9bcab8c376174e0 Mon Sep 17 00:00:00 2001 From: Sonali Sharma Date: Wed, 15 Apr 2026 20:03:55 +0530 Subject: [PATCH] fix: disable autoSkip when stepSize is explicitly set When a user sets ticks.stepSize, they expect every tick to be shown at that exact interval. However, autoSkip (enabled by default) can still hide ticks, forcing users to manually set autoSkip: false. This adds a check to skip the autoSkip logic when stepSize is set, since an explicit step size implies the user wants all ticks visible. Fixes #4048 --- src/core/core.scale.js | 4 ++-- test/specs/scale.linear.tests.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index e81b6b933bf..73a4e63f3ed 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -453,8 +453,8 @@ export default class Scale extends Element { this.calculateLabelRotation(); // Preconditions: number of ticks and sizes of largest labels must be calculated beforehand this.afterCalculateLabelRotation(); - // Auto-skip - if (tickOpts.display && (tickOpts.autoSkip || tickOpts.source === 'auto')) { + // Auto-skip — disabled when stepSize is explicitly set + if (tickOpts.display && !tickOpts.stepSize && (tickOpts.autoSkip || tickOpts.source === 'auto')) { this.ticks = autoSkip(this, this.ticks); this._labelSizes = null; this.afterAutoSkip(); diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index a8ad53995b1..3136db47caa 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -684,6 +684,37 @@ describe('Linear Scale', function() { expect(getLabels(chart.scales.y)).toEqual(['1', '3', '5', '7', '9', '11']); }); + it('Should not autoSkip ticks when stepSize is set', function() { + var chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [{ + yAxisID: 'y', + data: [10, 3, 6, 8, 3, 1] + }], + labels: ['a', 'b', 'c', 'd', 'e', 'f'] + }, + options: { + scales: { + y: { + type: 'linear', + min: 0, + max: 10, + ticks: { + stepSize: 1 + } + } + } + } + }); + + var ticks = chart.scales.y.ticks; + var visibleTicks = ticks.filter(t => !t.skip); + + expect(visibleTicks.length).toBe(ticks.length); + expect(getLabels(chart.scales.y)).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']); + }); + it('Should not generate any ticks > max if max is specified', function() { var chart = window.acquireChart({ type: 'line',