]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Linear: Respect bounds option in tick generation (#9181)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sat, 29 May 2021 21:32:03 +0000 (00:32 +0300)
committerGitHub <noreply@github.com>
Sat, 29 May 2021 21:32:03 +0000 (17:32 -0400)
* Linear: Respect bounds option in tick generation
* Remove leftover _filterBetween

src/scales/scale.linearbase.js
test/fixtures/controller.line/stacking/bounds-data.js [new file with mode: 0644]
test/fixtures/controller.line/stacking/bounds-data.png [new file with mode: 0644]

index ab2c4b91e5cd4f2de880190a7cc69068d96cea5f..8bd3c7e1fef83fd150822ec0ab1df9aec7e9ed4e 100644 (file)
@@ -29,7 +29,7 @@ function generateTicks(generationOptions, dataRange) {
   // for details.
 
   const MIN_SPACING = 1e-14;
-  const {step, min, max, precision, count, maxTicks, maxDigits, includeBounds} = generationOptions;
+  const {bounds, step, min, max, precision, count, maxTicks, maxDigits, includeBounds} = generationOptions;
   const unit = step || 1;
   const maxSpaces = maxTicks - 1;
   const {min: rmin, max: rmax} = dataRange;
@@ -58,8 +58,13 @@ function generateTicks(generationOptions, dataRange) {
     spacing = Math.ceil(spacing * factor) / factor;
   }
 
-  niceMin = Math.floor(rmin / spacing) * spacing;
-  niceMax = Math.ceil(rmax / spacing) * spacing;
+  if (bounds === 'ticks') {
+    niceMin = Math.floor(rmin / spacing) * spacing;
+    niceMax = Math.ceil(rmax / spacing) * spacing;
+  } else {
+    niceMin = rmin;
+    niceMax = rmax;
+  }
 
   if (minDefined && maxDefined && step && almostWhole((max - min) / step, spacing / 1000)) {
     // Case 1: If min, max and stepSize are set and they make an evenly spaced scale use it.
@@ -241,6 +246,7 @@ export default class LinearScaleBase extends Scale {
 
     const numericGeneratorOptions = {
       maxTicks,
+      bounds: opts.bounds,
       min: opts.min,
       max: opts.max,
       precision: tickOpts.precision,
diff --git a/test/fixtures/controller.line/stacking/bounds-data.js b/test/fixtures/controller.line/stacking/bounds-data.js
new file mode 100644 (file)
index 0000000..413af18
--- /dev/null
@@ -0,0 +1,29 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: ['a', 'b'],
+      datasets: [{
+        borderColor: 'red',
+        data: [50, 75],
+      }, {
+        borderColor: 'blue',
+        data: [25, 50],
+      }]
+    },
+    options: {
+      scales: {
+        x: {
+          display: false
+        },
+        y: {
+          stacked: true,
+          bounds: 'data'
+        }
+      }
+    }
+  },
+  options: {
+    spriteText: true
+  }
+};
diff --git a/test/fixtures/controller.line/stacking/bounds-data.png b/test/fixtures/controller.line/stacking/bounds-data.png
new file mode 100644 (file)
index 0000000..90ce6a3
Binary files /dev/null and b/test/fixtures/controller.line/stacking/bounds-data.png differ