From: Robert Konigsberg Date: Thu, 14 Jun 2012 18:16:18 +0000 (-0400) Subject: Mild code reduction by eliminating duplication X-Git-Tag: v1.0.0~238^2^2~20 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a401ca8a175db27a032e228c8ced7cc924083210;p=dygraphs.git Mild code reduction by eliminating duplication --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index aff9002..d588b9c 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -725,6 +725,16 @@ DygraphCanvasRenderer.prototype._drawStyledLine = function( ctx.restore(); }; +DygraphCanvasRenderer.prototype._drawPointsOnLine = function(ctx, pointsOnLine, drawPointCallback, setName, color, pointSize) { + for (var idx = 0; idx < pointsOnLine.length; idx++) { + var cb = pointsOnLine[idx]; + ctx.save(); + drawPointCallback( + this.dygraph_, setName, ctx, cb[0], cb[1], color, pointSize); + ctx.restore(); + } +} + DygraphCanvasRenderer.prototype._drawNonTrivialLine = function( ctx, points, setLength, firstIndexInSet, setName, color, strokeWidth, strokePattern, drawPointCallback, pointSize, drawPoints, drawGapPoints, stepPlot) { var prevX = null; @@ -794,13 +804,7 @@ DygraphCanvasRenderer.prototype._drawNonTrivialLine = function( } } } - for (var idx = 0; idx < pointsOnLine.length; idx++) { - var cb = pointsOnLine[idx]; - ctx.save(); - drawPointCallback( - this.dygraph_, setName, ctx, cb[0], cb[1], color, pointSize); - ctx.restore(); - } + this._drawPointsOnLine(ctx, pointsOnLine, drawPointCallback, setName, color, pointSize); }; DygraphCanvasRenderer.prototype._drawTrivialLine = function( @@ -844,13 +848,7 @@ DygraphCanvasRenderer.prototype._drawTrivialLine = function( } } ctx.stroke(); - for (var idx = 0; idx < pointsOnLine.length; idx++) { - var cb = pointsOnLine[idx]; - ctx.save(); - drawPointCallback( - this.dygraph_, setName, ctx, cb[0], cb[1], color, pointSize); - ctx.restore(); - } + this._drawPointsOnLine(ctx, pointsOnLine, drawPointCallback, setName, color, pointSize); }; DygraphCanvasRenderer.prototype._drawLine = function(ctx, i) {