]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix autoSkip (#8619)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Thu, 11 Mar 2021 21:25:16 +0000 (23:25 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Mar 2021 21:25:16 +0000 (16:25 -0500)
* Fix autoSkip
* Add tests

src/core/core.scale.js
test/fixtures/core.scale/autoSkip/no-offset.js [new file with mode: 0644]
test/fixtures/core.scale/autoSkip/no-offset.png [new file with mode: 0644]
test/fixtures/core.scale/autoSkip/offset.js [new file with mode: 0644]
test/fixtures/core.scale/autoSkip/offset.png [new file with mode: 0644]

index d985f38c33e6cc7a404b676903bfe5cab5438674..d7228c3063b1c23b27fd1f93a8d4494e058484b8 100644 (file)
@@ -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 (file)
index 0000000..a029ee9
--- /dev/null
@@ -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 (file)
index 0000000..9a24900
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 (file)
index 0000000..679a44e
--- /dev/null
@@ -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 (file)
index 0000000..6c1f8c6
Binary files /dev/null and b/test/fixtures/core.scale/autoSkip/offset.png differ