]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix: don't draw segments out of bounds (#8911)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 16 Apr 2021 21:14:55 +0000 (00:14 +0300)
committerGitHub <noreply@github.com>
Fri, 16 Apr 2021 21:14:55 +0000 (17:14 -0400)
src/elements/element.line.js
test/fixtures/controller.line/issue-8902.js [new file with mode: 0644]
test/fixtures/controller.line/issue-8902.png [new file with mode: 0644]

index e6265a128225ee445829307389a3af4d9304c1ed..985fa0b24e9ef2ed26f739ff8b946e1b279edc49 100644 (file)
@@ -34,17 +34,19 @@ function getLineMethod(options) {
   return lineTo;
 }
 
-function pathVars(points, segment, params) {
-  params = params || {};
+function pathVars(points, segment, params = {}) {
   const count = points.length;
-  const start = Math.max(params.start || 0, segment.start);
-  const end = Math.min(params.end || count - 1, segment.end);
+  const {start: paramsStart = 0, end: paramsEnd = count - 1} = params;
+  const {start: segmentStart, end: segmentEnd} = segment;
+  const start = Math.max(paramsStart, segmentStart);
+  const end = Math.min(paramsEnd, segmentEnd);
+  const outside = paramsStart < segmentStart && paramsEnd < segmentStart || paramsStart > segmentEnd && paramsEnd > segmentEnd;
 
   return {
     count,
     start,
     loop: segment.loop,
-    ilen: end < start ? count + end - start : end - start
+    ilen: end < start && !outside ? count + end - start : end - start
   };
 }
 
diff --git a/test/fixtures/controller.line/issue-8902.js b/test/fixtures/controller.line/issue-8902.js
new file mode 100644 (file)
index 0000000..cb98638
--- /dev/null
@@ -0,0 +1,30 @@
+module.exports = {
+  description: 'https://github.com/chartjs/Chart.js/issues/8902',
+  config: {
+    type: 'line',
+    data: {
+      labels: [1, 2, 3, 4, 5, 6, 7, 8],
+      datasets: [{
+        data: [65, 59, NaN, 48, 56, 57, 40],
+        borderColor: 'rgb(75, 192, 192)',
+      }]
+    },
+    options: {
+      plugins: false,
+      scales: {
+        x: {
+          type: 'linear',
+          min: 1,
+          max: 3
+        }
+      }
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {
+      height: 256,
+      width: 512
+    }
+  }
+};
diff --git a/test/fixtures/controller.line/issue-8902.png b/test/fixtures/controller.line/issue-8902.png
new file mode 100644 (file)
index 0000000..c132c57
Binary files /dev/null and b/test/fixtures/controller.line/issue-8902.png differ