]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Simplify code for capping bezier control points. Cap the X direction as well.
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 14 Nov 2015 03:15:23 +0000 (22:15 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 14 Nov 2015 03:15:23 +0000 (22:15 -0500)
src/controllers/controller.line.js
src/controllers/controller.radar.js

index 954686e06af39fffff5e006f0aca43db6e68ff5e..c22df9f97e1eea0a53984b0f1e4eb96d0a3e865f 100644 (file)
                                        point._model.tension
                                );
 
-                               point._model.controlPointPreviousX = controlPoints.previous.x;
-                               point._model.controlPointNextX = controlPoints.next.x;
-
                                // Prevent the bezier going outside of the bounds of the graph
+                               point._model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, this.chart.chartArea.right), this.chart.chartArea.left);
+                               point._model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, this.chart.chartArea.bottom), this.chart.chartArea.bottom);
 
-                               // Cap outer bezier handles to the upper/lower scale bounds
-                               if (controlPoints.next.y > this.chart.chartArea.bottom) {
-                                       point._model.controlPointNextY = this.chart.chartArea.bottom;
-                               } else if (controlPoints.next.y < this.chart.chartArea.top) {
-                                       point._model.controlPointNextY = this.chart.chartArea.top;
-                               } else {
-                                       point._model.controlPointNextY = controlPoints.next.y;
-                               }
-
-                               // Cap inner bezier handles to the upper/lower scale bounds
-                               if (controlPoints.previous.y > this.chart.chartArea.bottom) {
-                                       point._model.controlPointPreviousY = this.chart.chartArea.bottom;
-                               } else if (controlPoints.previous.y < this.chart.chartArea.top) {
-                                       point._model.controlPointPreviousY = this.chart.chartArea.top;
-                               } else {
-                                       point._model.controlPointPreviousY = controlPoints.previous.y;
-                               }
+                               point._model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, this.chart.chartArea.right), this.chart.chartArea.left);
+                               point._model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
 
                                // Now pivot the point for animation
                                point.pivot();
index b8bcf1441e826e1e124d9c60408a7975c608abbe..5e452820db9648a3ab805bde49d6c4ab9de34a36 100644 (file)
                                        point._model.tension
                                );
 
-                               point._model.controlPointPreviousX = controlPoints.previous.x;
-                               point._model.controlPointNextX = controlPoints.next.x;
-
                                // Prevent the bezier going outside of the bounds of the graph
+                               point._model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, this.chart.chartArea.right), this.chart.chartArea.left);
+                               point._model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, this.chart.chartArea.bottom), this.chart.chartArea.bottom);
 
-                               // Cap outer bezier handles to the upper/lower scale bounds
-                               if (controlPoints.next.y > this.chart.chartArea.bottom) {
-                                       point._model.controlPointNextY = this.chart.chartArea.bottom;
-                               } else if (controlPoints.next.y < this.chart.chartArea.top) {
-                                       point._model.controlPointNextY = this.chart.chartArea.top;
-                               } else {
-                                       point._model.controlPointNextY = controlPoints.next.y;
-                               }
-
-                               // Cap inner bezier handles to the upper/lower scale bounds
-                               if (controlPoints.previous.y > this.chart.chartArea.bottom) {
-                                       point._model.controlPointPreviousY = this.chart.chartArea.bottom;
-                               } else if (controlPoints.previous.y < this.chart.chartArea.top) {
-                                       point._model.controlPointPreviousY = this.chart.chartArea.top;
-                               } else {
-                                       point._model.controlPointPreviousY = controlPoints.previous.y;
-                               }
+                               point._model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, this.chart.chartArea.right), this.chart.chartArea.left);
+                               point._model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
 
                                // Now pivot the point for animation
                                point.pivot();