]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix monotone cubic interpolation when two adjacent points are at the exact same x...
authoretimberg <evert.timberg@gmail.com>
Sat, 26 Nov 2016 17:29:15 +0000 (12:29 -0500)
committerEvert Timberg <evert.timberg+github@gmail.com>
Mon, 28 Nov 2016 23:28:06 +0000 (18:28 -0500)
src/core/core.helpers.js
test/core.helpers.tests.js

index 542088f610bc31aa581694785d5377aef49390c2..506ad900397f916409387eb4ec24e1bafe6788d2 100644 (file)
@@ -361,7 +361,10 @@ module.exports = function(Chart) {
                        pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
                        pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
                        if (pointAfter && !pointAfter.model.skip) {
-                               pointCurrent.deltaK = (pointAfter.model.y - pointCurrent.model.y) / (pointAfter.model.x - pointCurrent.model.x);
+                               var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
+
+                               // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
+                               pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
                        }
 
                        if (!pointBefore || pointBefore.model.skip) {
index 4cd200ae3b82d8952e09bf4cb685743f127fc2aa..75e0baf900ec88d3dc6e5d3ff65f18ded4475308 100644 (file)
@@ -412,6 +412,7 @@ describe('Core helper tests', function() {
                        {_model: {x: 27, y: 125, skip: false}},
                        {_model: {x: 30, y: 105, skip: false}},
                        {_model: {x: 33, y: 110, skip: false}},
+                       {_model: {x: 33, y: 110, skip: false}},
                        {_model: {x: 36, y: 170, skip: false}}
                ];
                helpers.splineCurveMonotone(dataPoints);
@@ -532,9 +533,20 @@ describe('Core helper tests', function() {
                                y: 110,
                                skip: false,
                                controlPointPreviousX: 32,
-                               controlPointPreviousY: 105,
+                               controlPointPreviousY: 110,
+                               controlPointNextX: 33,
+                               controlPointNextY: 110
+                       }
+               },
+               {
+                       _model: {
+                               x: 33,
+                               y: 110,
+                               skip: false,
+                               controlPointPreviousX: 33,
+                               controlPointPreviousY: 110,
                                controlPointNextX: 34,
-                               controlPointNextY: 115
+                               controlPointNextY: 110
                        }
                },
                {