From afdc483f63032d8bba075b5a424ab48b32f9d332 Mon Sep 17 00:00:00 2001 From: Neal Nelson Date: Tue, 15 Jun 2010 17:42:14 +0200 Subject: [PATCH] Added stepPlot option. Missed files due to git. --- dygraph-canvas.js | 31 +++++++++++++++++++++++++++---- dygraph.js | 4 +++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index e661d7e..09ce16b 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -455,6 +455,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var errorBars = this.layout.options.errorBars; var fillGraph = this.layout.options.fillGraph; var stackedGraph = this.layout.options.stackedGraph; + var stepPlot = this.layout.options.stepPlot; var setNames = []; for (var name in this.layout.datasets) { @@ -493,6 +494,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { // setup graphics context ctx.save(); var prevX = NaN; + var prevY = NaN; var prevYs = [-1, -1]; var yscale = this.layout.yscale; // should be same color as the lines but only 15% opaque. @@ -509,15 +511,29 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { continue; } // TODO(danvk): here - var newYs = [ point.y - point.errorPlus * yscale, + if (stepPlot) { + var newYs = [ prevY - point.errorPlus * yscale, + prevY + point.errorMinus * yscale ]; + prevY = point.y; + } else { + var newYs = [ point.y - point.errorPlus * yscale, point.y + point.errorMinus * yscale ]; + } newYs[0] = this.area.h * newYs[0] + this.area.y; newYs[1] = this.area.h * newYs[1] + this.area.y; if (!isNaN(prevX)) { - ctx.moveTo(prevX, prevYs[0]); + if (stepPlot) { + ctx.moveTo(prevX, newYs[0]); + } else { + ctx.moveTo(prevX, prevYs[0]); + } ctx.lineTo(point.canvasx, newYs[0]); ctx.lineTo(point.canvasx, newYs[1]); - ctx.lineTo(prevX, prevYs[1]); + if (stepPlot) { + ctx.lineTo(prevX, newYs[1]); + } else { + ctx.lineTo(prevX, prevYs[1]); + } ctx.closePath(); } prevYs = newYs; @@ -568,7 +584,11 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { } if (!isNaN(prevX)) { ctx.moveTo(prevX, prevYs[0]); - ctx.lineTo(point.canvasx, newYs[0]); + if (stepPlot) { + ctx.lineTo(point.canvasx, prevYs[0]); + } else { + ctx.lineTo(point.canvasx, newYs[0]); + } ctx.lineTo(point.canvasx, newYs[1]); ctx.lineTo(prevX, prevYs[1]); ctx.closePath(); @@ -612,6 +632,9 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { ctx.strokeStyle = color; ctx.lineWidth = this.options.strokeWidth; ctx.moveTo(prevX, prevY); + if (stepPlot) { + ctx.lineTo(point.canvasx, prevY); + } prevX = point.canvasx; prevY = point.canvasy; ctx.lineTo(prevX, prevY); diff --git a/dygraph.js b/dygraph.js index cbaa002..ee5306c 100644 --- a/dygraph.js +++ b/dygraph.js @@ -123,7 +123,9 @@ Dygraph.DEFAULT_ATTRS = { connectSeparatedPoints: false, stackedGraph: false, - hideOverlayOnMouseOut: true + hideOverlayOnMouseOut: true, + + stepPlot: false }; // Various logging levels. -- 2.7.4