]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
some duplicate code cleanup
authorEvert Timberg <evert.timberg@gmail.com>
Sun, 15 Nov 2015 03:06:37 +0000 (22:06 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sun, 15 Nov 2015 03:06:37 +0000 (22:06 -0500)
src/elements/element.line.js

index d31d8657f39c2e52fd680aad391fe0cb35f529e4..dc1f1d635a527fd3e0bac55e6066b88d5be9bd8d 100644 (file)
                },
 
                draw: function() {
+                       var _this = this;
 
                        var vm = this._view;
                        var ctx = this._chart.ctx;
                        var first = this._children[0];
                        var last = this._children[this._children.length - 1];
 
+                       function loopBackToStart() {
+                               if (!first._view.skip) {
+                                       // Draw a bezier line from last to first
+                                       ctx.bezierCurveTo(
+                                               last._view.controlPointNextX,
+                                               last._view.controlPointNextY,
+                                               first._view.controlPointPreviousX,
+                                               first._view.controlPointPreviousY,
+                                               first._view.x,
+                                               first._view.y
+                                       );
+                               } else {
+                                       // Go to center
+                                       ctx.lineTo(_this._view.scaleZero.x, _this._view.scaleZero.y);
+                               }
+                       }
+
                        ctx.save();
 
                        // If we had points and want to fill this line, do so.
 
                                // For radial scales, loop back around to the first point
                                if (this._loop) {
-                                       if (!first._view.skip) {
-                                               // Draw a bezier line
-                                               ctx.bezierCurveTo(
-                                                       last._view.controlPointNextX,
-                                                       last._view.controlPointNextY,
-                                                       first._view.controlPointPreviousX,
-                                                       first._view.controlPointPreviousY,
-                                                       first._view.x,
-                                                       first._view.y
-                                               );
-                                       } else {
-                                               // Go to center
-                                               ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
-                                       }
+                                       loopBackToStart();
                                } else {
                                        //Round off the line by going to the base of the chart, back to the start, then fill.
                                        ctx.lineTo(this._children[this._children.length - 1]._view.x, vm.scaleZero);
                        }, this);
 
                        if (this._loop) {
-                               if (!first._view.skip) {
-                                       // Draw a bezier line
-                                       ctx.bezierCurveTo(
-                                               last._view.controlPointNextX,
-                                               last._view.controlPointNextY,
-                                               first._view.controlPointPreviousX,
-                                               first._view.controlPointPreviousY,
-                                               first._view.x,
-                                               first._view.y
-                                       );
-                               } else {
-                                       // Go to center
-                                       ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
-                               }
+                               loopBackToStart();
                        }
 
                        ctx.stroke();