diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 41606d91bcf..e1fc07302ef 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 00000000000..a029ee97599 --- /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 00000000000..9a24900a7f7 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 00000000000..679a44efc03 --- /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 00000000000..6c1f8c62d1e Binary files /dev/null and b/test/fixtures/core.scale/autoSkip/offset.png differ