]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix curve path if scale limits are set for line chart (#11377)
authorstockiNail <stocki.nail@gmail.com>
Mon, 24 Jul 2023 17:58:23 +0000 (19:58 +0200)
committerGitHub <noreply@github.com>
Mon, 24 Jul 2023 17:58:23 +0000 (19:58 +0200)
* Fix curve path if scale limits are set for line chart

* add scale limits test case

src/controllers/controller.line.js
src/helpers/helpers.extras.ts
test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.js [new file with mode: 0644]
test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.png [new file with mode: 0644]
test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.js [new file with mode: 0644]
test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.png [new file with mode: 0644]

index fddd5ce9889c6b0b21947623f4ea670a09c8592e..8c5977e19579527079d3c4ed479d9f6a5dd0623b 100644 (file)
@@ -57,7 +57,7 @@ export default class LineController extends DatasetController {
     line._chart = this.chart;
     line._datasetIndex = this.index;
     line._decimated = !!_dataset._decimated;
-    line.points = points;
+    line.points = points.slice(Math.max(this._drawStart - 1, 0), this._drawStart + this._drawCount);
 
     const options = this.resolveDatasetElementOptions(mode);
     if (!this.options.showLine) {
index 1428419119ebfddef9d0d4c81125240394c246c3..dc34ecf07f904fccab749bf8bd0ef10d6471f5e1 100644 (file)
@@ -98,7 +98,7 @@ export function _getStartAndCountOfVisiblePoints(meta: ChartMeta<'line' | 'scatt
     if (minDefined) {
       start = _limitValue(Math.min(
         // @ts-expect-error Need to type _parsed
-        _lookupByKey(_parsed, iScale.axis, min).lo,
+        _lookupByKey(_parsed, axis, min).lo,
         // @ts-expect-error Need to fix types on _lookupByKey
         animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo),
       0, pointCount - 1);
diff --git a/test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.js b/test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.js
new file mode 100644 (file)
index 0000000..605ac18
--- /dev/null
@@ -0,0 +1,35 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [
+        {
+          data: [
+            {x: -10, y: 150},
+            {x: 0, y: 81},
+            {x: 10, y: 49},
+            {x: 20, y: 32},
+            {x: 30, y: 21},
+            {x: 35, y: 1},
+            {x: 40, y: 16},
+            {x: 45, y: 13},
+          ],
+          borderColor: '#ff0000',
+          cubicInterpolationMode: 'monotone'
+        }
+      ]
+    },
+    options: {
+      scales: {
+        x: {display: false, type: 'linear', min: 5, max: 37},
+        y: {display: false}
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 256,
+      width: 512
+    }
+  }
+};
diff --git a/test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.png b/test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.png
new file mode 100644 (file)
index 0000000..056d451
Binary files /dev/null and b/test/fixtures/controller.line/cubicInterpolationMode/scaleMInMaxLimits.png differ
diff --git a/test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.js b/test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.js
new file mode 100644 (file)
index 0000000..6bae22d
--- /dev/null
@@ -0,0 +1,35 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [
+        {
+          data: [
+            {x: -10, y: 150},
+            {x: 0, y: 81},
+            {x: 10, y: 49},
+            {x: 20, y: 32},
+            {x: 30, y: 21},
+            {x: 35, y: 1},
+            {x: 40, y: 16},
+            {x: 45, y: 13},
+          ],
+          borderColor: '#ff0000',
+          cubicInterpolationMode: 'monotone'
+        }
+      ]
+    },
+    options: {
+      scales: {
+        x: {display: false, type: 'linear', max: 30},
+        y: {display: false}
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 256,
+      width: 512
+    }
+  }
+};
diff --git a/test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.png b/test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.png
new file mode 100644 (file)
index 0000000..048c8c3
Binary files /dev/null and b/test/fixtures/controller.line/cubicInterpolationMode/scaleMaxLimit.png differ