]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
radialLinear: fix getIndexAngle when there are no labels (left) (#10020)
authorJacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Thu, 23 Dec 2021 07:48:21 +0000 (08:48 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Dec 2021 07:48:21 +0000 (09:48 +0200)
* Resolve animation if indexAngle is NaN

* make it private

* add test

* use chart.js helper instead of own logic

* implement feedback

* remove extra line

* my precious bits

src/scales/scale.radialLinear.js
test/fixtures/controller.polarArea/last-slice-animate.js [new file with mode: 0644]
test/fixtures/controller.polarArea/last-slice-animate.png [new file with mode: 0644]

index 2c3763bc1eb0bf7cf6c98d9153ef0fb38ff61f33..a453b59814fd5a37a0a530a4f0a651a9868adaf2 100644 (file)
@@ -371,8 +371,9 @@ export default class RadialLinearScale extends LinearScaleBase {
   }
 
   getIndexAngle(index) {
-    const angleMultiplier = TAU / this._pointLabels.length;
+    const angleMultiplier = TAU / (this._pointLabels.length || 1);
     const startAngle = this.options.startAngle || 0;
+
     return _normalizeAngle(index * angleMultiplier + toRadians(startAngle));
   }
 
diff --git a/test/fixtures/controller.polarArea/last-slice-animate.js b/test/fixtures/controller.polarArea/last-slice-animate.js
new file mode 100644 (file)
index 0000000..43e3e86
--- /dev/null
@@ -0,0 +1,70 @@
+const canvas = document.createElement('canvas');
+canvas.width = 512;
+canvas.height = 512;
+const ctx = canvas.getContext('2d');
+
+module.exports = {
+  config: {
+    type: 'polarArea',
+    data: {
+      labels: ['A'],
+      datasets: [{
+        data: [20],
+        backgroundColor: 'red',
+      }]
+    },
+    options: {
+      animation: {
+        duration: 0,
+        easing: 'linear'
+      },
+      responsive: false,
+      plugins: {
+        legend: false,
+        title: false,
+        tooltip: false,
+        filler: false
+      },
+      scales: {
+        r: {
+          ticks: {
+            display: false,
+          }
+        }
+      }
+    },
+  },
+  options: {
+    canvas: {
+      height: 512,
+      width: 512
+    },
+    run: function(chart) {
+      chart.options.animation.duration = 8000;
+      chart.toggleDataVisibility(0);
+      chart.update();
+      const animator = Chart.animator;
+      // disable animator
+      const backup = animator._refresh;
+      animator._refresh = function() { };
+
+      return new Promise((resolve) => {
+        window.requestAnimationFrame(() => {
+          const anims = animator._getAnims(chart);
+          const start = anims.items[0]._start;
+          for (let i = 0; i < 16; i++) {
+            animator._update(start + i * 500);
+            let x = i % 4 * 128;
+            let y = Math.floor(i / 4) * 128;
+            ctx.drawImage(chart.canvas, x, y, 128, 128);
+          }
+          Chart.helpers.clearCanvas(chart.canvas);
+          chart.ctx.drawImage(canvas, 0, 0);
+
+          animator._refresh = backup;
+          resolve();
+        });
+      });
+    }
+  }
+};
diff --git a/test/fixtures/controller.polarArea/last-slice-animate.png b/test/fixtures/controller.polarArea/last-slice-animate.png
new file mode 100644 (file)
index 0000000..f655703
Binary files /dev/null and b/test/fixtures/controller.polarArea/last-slice-animate.png differ