From: Jukka Kurkela Date: Thu, 11 Mar 2021 21:25:16 +0000 (+0200) Subject: Fix autoSkip (#8619) X-Git-Tag: v3.0.0-beta.14~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bedc3f15757c917f12c44770cc7cf827365884d9;p=thirdparty%2FChart.js.git Fix autoSkip (#8619) * Fix autoSkip * Add tests --- diff --git a/src/core/core.scale.js b/src/core/core.scale.js index d985f38c3..d7228c306 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -1162,8 +1162,8 @@ export default class Scale extends Element { */ _autoSkip(ticks) { const me = this; - const tickOpts = me.options.ticks; - const ticksLimit = tickOpts.maxTicksLimit || me._length / me._tickSize(); + const {offset, ticks: tickOpts} = me.options; + const ticksLimit = tickOpts.maxTicksLimit || (me._length / me._tickSize() + (offset ? 0 : 1)); const majorIndices = tickOpts.major.enabled ? getMajorIndices(ticks) : []; const numMajorIndices = majorIndices.length; const first = majorIndices[0]; diff --git a/test/fixtures/core.scale/autoSkip/no-offset.js b/test/fixtures/core.scale/autoSkip/no-offset.js new file mode 100644 index 000000000..a029ee975 --- /dev/null +++ b/test/fixtures/core.scale/autoSkip/no-offset.js @@ -0,0 +1,22 @@ +module.exports = { + description: 'https://github.com/chartjs/Chart.js/issues/8611', + config: { + type: 'line', + data: { + labels: ['Red Red Red', 'Blue Blue Blue', 'Black Black Black', 'Pink Pink Pink'], + datasets: [ + { + label: '# of Votes', + data: [12, 19, 3, 5] + }, + ] + }, + }, + options: { + spriteText: true, + canvas: { + width: 470, + height: 128 + } + } +}; diff --git a/test/fixtures/core.scale/autoSkip/no-offset.png b/test/fixtures/core.scale/autoSkip/no-offset.png new file mode 100644 index 000000000..9a24900a7 Binary files /dev/null and b/test/fixtures/core.scale/autoSkip/no-offset.png differ diff --git a/test/fixtures/core.scale/autoSkip/offset.js b/test/fixtures/core.scale/autoSkip/offset.js new file mode 100644 index 000000000..679a44efc --- /dev/null +++ b/test/fixtures/core.scale/autoSkip/offset.js @@ -0,0 +1,22 @@ +module.exports = { + description: 'https://github.com/chartjs/Chart.js/issues/8611', + config: { + type: 'bar', + data: { + labels: ['Red Red Red', 'Blue Blue Blue', 'Black Black Black', 'Pink Pink Pink'], + datasets: [ + { + label: '# of Votes', + data: [12, 19, 3, 5] + }, + ] + }, + }, + options: { + spriteText: true, + canvas: { + width: 506, + height: 128 + } + } +}; diff --git a/test/fixtures/core.scale/autoSkip/offset.png b/test/fixtures/core.scale/autoSkip/offset.png new file mode 100644 index 000000000..6c1f8c62d Binary files /dev/null and b/test/fixtures/core.scale/autoSkip/offset.png differ