]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
fix #11503, autoskipping 0 ticks when min is below 0 (#11682)
authorMegaemce <1651451+Megaemce@users.noreply.github.com>
Sat, 24 Feb 2024 19:30:35 +0000 (02:30 +0700)
committerGitHub <noreply@github.com>
Sat, 24 Feb 2024 19:30:35 +0000 (20:30 +0100)
src/scales/scale.radialLinear.js
test/fixtures/scale.radialLinear/ticks-below-zero.js [new file with mode: 0644]
test/fixtures/scale.radialLinear/ticks-below-zero.png [new file with mode: 0644]

index 23e207bd5d9fd0c08e2cb24c83abf35fa5c30602..1e3f796909386c21358f80f06b870bb0b0c526e2 100644 (file)
@@ -578,7 +578,7 @@ export default class RadialLinearScale extends LinearScaleBase {
 
     if (grid.display) {
       this.ticks.forEach((tick, index) => {
-        if (index !== 0) {
+        if (index !== 0 || (index === 0 && this.min < 0)) {
           offset = this.getDistanceFromCenterForValue(tick.value);
           const context = this.getContext(index);
           const optsAtIndex = grid.setContext(context);
@@ -645,7 +645,7 @@ export default class RadialLinearScale extends LinearScaleBase {
     ctx.textBaseline = 'middle';
 
     this.ticks.forEach((tick, index) => {
-      if (index === 0 && !opts.reverse) {
+      if ((index === 0 && this.min >= 0) && !opts.reverse) {
         return;
       }
 
diff --git a/test/fixtures/scale.radialLinear/ticks-below-zero.js b/test/fixtures/scale.radialLinear/ticks-below-zero.js
new file mode 100644 (file)
index 0000000..7564781
--- /dev/null
@@ -0,0 +1,45 @@
+module.exports = {
+  config: {
+    type: 'radar',
+    data: {
+      labels: ['A', 'B', 'C', 'D', 'E']
+    },
+    options: {
+      responsive: false,
+      scales: {
+        r: {
+          min: -1,
+          max: 1,
+          grid: {
+            display: true,
+            color: 'blue',
+            lineWidth: 2
+          },
+          angleLines: {
+            color: 'rgba(255, 255, 255, 0.5)',
+            lineWidth: 2
+          },
+          pointLabels: {
+            display: false
+          },
+          ticks: {
+            display: true,
+            autoSkip: false,
+            stepSize: 0.2,
+            callback: function(value) {
+              if (value === 0.8) {
+                return 'Strong';
+              }
+              if (value === 0.4) {
+                return 'Weak';
+              }
+              if (value === 0) {
+                return 'No';
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+};
diff --git a/test/fixtures/scale.radialLinear/ticks-below-zero.png b/test/fixtures/scale.radialLinear/ticks-below-zero.png
new file mode 100644 (file)
index 0000000..36435fd
Binary files /dev/null and b/test/fixtures/scale.radialLinear/ticks-below-zero.png differ