From: Evert Timberg Date: Sun, 15 Nov 2015 03:06:37 +0000 (-0500) Subject: some duplicate code cleanup X-Git-Tag: 2.0.0-beta1~25^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bd9120a3a10d5ce510c5ccc66a66a485eeb78ae;p=thirdparty%2FChart.js.git some duplicate code cleanup --- diff --git a/src/elements/element.line.js b/src/elements/element.line.js index d31d8657f..dc1f1d635 100644 --- a/src/elements/element.line.js +++ b/src/elements/element.line.js @@ -52,12 +52,30 @@ }, 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. @@ -91,20 +109,7 @@ // 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); @@ -147,20 +152,7 @@ }, 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();