]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix for enabling monotone cubicInterpolationMode when tension is 0 (#9008)
authorAkihiko Kusanagi <nagi@nagi-p.com>
Fri, 30 Apr 2021 12:14:13 +0000 (20:14 +0800)
committerGitHub <noreply@github.com>
Fri, 30 Apr 2021 12:14:13 +0000 (08:14 -0400)
13 files changed:
src/elements/element.line.js
test/fixtures/element.line/cubicInterpolationMode/monotone.js [new file with mode: 0644]
test/fixtures/element.line/cubicInterpolationMode/monotone.png [new file with mode: 0644]
test/fixtures/plugin.filler/line/before-dataset-draw.png
test/fixtures/plugin.filler/line/before-datasets-draw.png
test/fixtures/plugin.filler/line/boundary/origin-spline-above.png
test/fixtures/plugin.filler/line/boundary/origin-spline-span.png
test/fixtures/plugin.filler/line/boundary/origin-spline.png
test/fixtures/plugin.filler/line/dataset/span-dual.png
test/fixtures/plugin.filler/line/dataset/spline-span-above.png
test/fixtures/plugin.filler/line/dataset/spline-span-below.png
test/fixtures/plugin.filler/line/dataset/spline-span.png
test/fixtures/plugin.filler/line/dataset/spline.png

index 985fa0b24e9ef2ed26f739ff8b946e1b279edc49..6cb13703eda2f294baa5f82333e7f88d465a6480 100644 (file)
@@ -27,7 +27,7 @@ function getLineMethod(options) {
     return _steppedLineTo;
   }
 
-  if (options.tension) {
+  if (options.tension || options.cubicInterpolationMode === 'monotone') {
     return _bezierCurveTo;
   }
 
@@ -182,7 +182,7 @@ function fastPathSegment(ctx, line, segment, params) {
 function _getSegmentMethod(line) {
   const opts = line.options;
   const borderDash = opts.borderDash && opts.borderDash.length;
-  const useFastPath = !line._decimated && !line._loop && !opts.tension && !opts.stepped && !borderDash;
+  const useFastPath = !line._decimated && !line._loop && !opts.tension && opts.cubicInterpolationMode !== 'monotone' && !opts.stepped && !borderDash;
   return useFastPath ? fastPathSegment : pathSegment;
 }
 
@@ -194,7 +194,7 @@ function _getInterpolationMethod(options) {
     return _steppedInterpolation;
   }
 
-  if (options.tension) {
+  if (options.tension || options.cubicInterpolationMode === 'monotone') {
     return _bezierInterpolation;
   }
 
@@ -260,7 +260,7 @@ export default class LineElement extends Element {
   updateControlPoints(chartArea) {
     const me = this;
     const options = me.options;
-    if (options.tension && !options.stepped && !me._pointsUpdated) {
+    if ((options.tension || options.cubicInterpolationMode === 'monotone') && !options.stepped && !me._pointsUpdated) {
       const loop = options.spanGaps ? me._loop : me._fullLoop;
       _updateBezierControlPoints(me._points, options, chartArea, loop);
       me._pointsUpdated = true;
diff --git a/test/fixtures/element.line/cubicInterpolationMode/monotone.js b/test/fixtures/element.line/cubicInterpolationMode/monotone.js
new file mode 100644 (file)
index 0000000..29f68c9
--- /dev/null
@@ -0,0 +1,27 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [
+        {
+          data: [{x: 1, y: 10}, {x: 5, y: 0}, {x: 15, y: -10}, {x: 19, y: -5}],
+          borderColor: 'red',
+          fill: false,
+          cubicInterpolationMode: 'monotone'
+        }
+      ]
+    },
+    options: {
+      scales: {
+        x: {type: 'linear', display: false, min: 0, max: 20},
+        y: {display: false, min: -15, max: 15}
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 256,
+      width: 512
+    }
+  }
+};
diff --git a/test/fixtures/element.line/cubicInterpolationMode/monotone.png b/test/fixtures/element.line/cubicInterpolationMode/monotone.png
new file mode 100644 (file)
index 0000000..6c79efd
Binary files /dev/null and b/test/fixtures/element.line/cubicInterpolationMode/monotone.png differ
index b69852d2d78709891916d349199f3b679a11b435..6ed2fe4c0761421f4f5e8d980b950dac3f82b040 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/before-dataset-draw.png and b/test/fixtures/plugin.filler/line/before-dataset-draw.png differ
index 9178b85283558b7ec3e5ed739b82f9a9278d1fc0..54c9517b85eb6a95983c00e96b9f02c8de8d991b 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/before-datasets-draw.png and b/test/fixtures/plugin.filler/line/before-datasets-draw.png differ
index 3b3caff7391f48f39b134bcebc23902a43f6a5bf..2d875467fb67869750970244e2fcbaba55164fec 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/boundary/origin-spline-above.png and b/test/fixtures/plugin.filler/line/boundary/origin-spline-above.png differ
index a93784a2a0eaea5d9fb388bc1c875f32bac54d61..fd54df60ccab8fb12a697378d0c8c8739b451c02 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/boundary/origin-spline-span.png and b/test/fixtures/plugin.filler/line/boundary/origin-spline-span.png differ
index 4d67822d5d838fa15f17d0a4f6a3fefae9386ada..94035713e563a8c1e65122c28615b1c593e8b98d 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/boundary/origin-spline.png and b/test/fixtures/plugin.filler/line/boundary/origin-spline.png differ
index a7b705ced47118cb460117e178f250ff045aeccd..158759d348963b2beb72fb8e7f7583bc90589f03 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/dataset/span-dual.png and b/test/fixtures/plugin.filler/line/dataset/span-dual.png differ
index 4814932317189f94d8dc8c883534a72f7aa2c4d6..2c8dbd2a7794fe63d1a253d6f3fac94b9c1ae9f5 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/dataset/spline-span-above.png and b/test/fixtures/plugin.filler/line/dataset/spline-span-above.png differ
index 5eb6663b778306ae4ff83b27d2a3a41e5b6d7bd3..68a20e2eeeae72d6ff5d2447df65eb11d70e7aab 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/dataset/spline-span-below.png and b/test/fixtures/plugin.filler/line/dataset/spline-span-below.png differ
index feb4fefb9a4658dcdaf70c51ac8d5c6ab3a62c25..07716a2f2106110af98b3b41c583bae46c30ca18 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/dataset/spline-span.png and b/test/fixtures/plugin.filler/line/dataset/spline-span.png differ
index ed02242e339713a17043316d2dccf10d367c51da..a66f356488798c00ad0aac50092c79ae4567414a 100644 (file)
Binary files a/test/fixtures/plugin.filler/line/dataset/spline.png and b/test/fixtures/plugin.filler/line/dataset/spline.png differ