From 2f56cd46850c9ba272029038ded19adfa5ba2f3b Mon Sep 17 00:00:00 2001 From: eichsjul Date: Thu, 31 Jan 2013 14:32:58 +0100 Subject: [PATCH 1/7] FEATURE: Added support for stepPlot per-series. --- dygraph-canvas.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 89d28b47f..257314770 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -261,7 +261,12 @@ DygraphCanvasRenderer._drawStyledLine = function(e, drawPointCallback, pointSize) { var g = e.dygraph; // TODO(konigsberg): Compute attributes outside this method call. - var stepPlot = g.getOption("stepPlot"); // TODO(danvk): per-series + var stepPlot = g.getOption("stepPlot"); + var seriesStepPlot = g.getOption("stepPlot",e.setName); + if(seriesStepPlot !== undefined){ + stepPlot = seriesStepPlot; + } + if (!Dygraph.isArrayLike(strokePattern)) { strokePattern = null; } From de9a8181064aa767e1c70c31a0027a0324cc33c6 Mon Sep 17 00:00:00 2001 From: "Damien Buhl (alias daminetreg)" Date: Thu, 31 Jan 2013 16:08:30 +0100 Subject: [PATCH 2/7] BUG FIX: Fixed indentation in respect to the jslint rules. --- dygraph-canvas.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 257314770..65678083c 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -263,8 +263,8 @@ DygraphCanvasRenderer._drawStyledLine = function(e, // TODO(konigsberg): Compute attributes outside this method call. var stepPlot = g.getOption("stepPlot"); var seriesStepPlot = g.getOption("stepPlot",e.setName); - if(seriesStepPlot !== undefined){ - stepPlot = seriesStepPlot; + if(seriesStepPlot !== undefined) { + stepPlot = seriesStepPlot; } if (!Dygraph.isArrayLike(strokePattern)) { From 0ce5b19b6346c9e55494997c06f460fedcd48b11 Mon Sep 17 00:00:00 2001 From: eichsjul Date: Thu, 31 Jan 2013 16:42:15 +0100 Subject: [PATCH 3/7] FEATURE: Added stepPlot option per series for all plotters. --- dygraph-canvas.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 65678083c..5305ded52 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -261,11 +261,7 @@ DygraphCanvasRenderer._drawStyledLine = function(e, drawPointCallback, pointSize) { var g = e.dygraph; // TODO(konigsberg): Compute attributes outside this method call. - var stepPlot = g.getOption("stepPlot"); - var seriesStepPlot = g.getOption("stepPlot",e.setName); - if(seriesStepPlot !== undefined) { - stepPlot = seriesStepPlot; - } + var stepPlot = g.getOption("stepPlot", e.setName); if (!Dygraph.isArrayLike(strokePattern)) { strokePattern = null; @@ -596,7 +592,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { var ctx = e.drawingContext; var color = e.color; var fillAlpha = g.getOption('fillAlpha', setName); - var stepPlot = g.getOption('stepPlot'); // TODO(danvk): per-series + var stepPlot = g.getOption("stepPlot", setName); var points = e.points; var iter = Dygraph.createIterator(points, 0, points.length, @@ -696,7 +692,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { var setCount = sets.length; var fillAlpha = g.getOption('fillAlpha'); - var stepPlot = g.getOption('stepPlot'); + var stepPlot = g.getOption('stepPlot', e.setName); var stackedGraph = g.getOption("stackedGraph"); var colors = g.getColors(); From 104d87c50866e6e0c6a877e662b7c08e7bf4d780 Mon Sep 17 00:00:00 2001 From: eichsjul Date: Wed, 6 Feb 2013 13:48:35 +0100 Subject: [PATCH 4/7] BUGFIX: stepPlot per series now also works correctly for the stackedGraph and fillGraph options --- dygraph-canvas.js | 23 +++---- dygraph-options-reference.js | 2 +- tests/steps.html | 112 +++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 11 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 5305ded52..fa0dd800b 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -692,18 +692,19 @@ DygraphCanvasRenderer._fillPlotter = function(e) { var setCount = sets.length; var fillAlpha = g.getOption('fillAlpha'); - var stepPlot = g.getOption('stepPlot', e.setName); var stackedGraph = g.getOption("stackedGraph"); var colors = g.getColors(); var baseline = {}; // for stacked graphs: baseline for filling var currBaseline; + var prevStepPlot; // for different line drawing modes (line/step) per series // process sets in reverse order (needed for stacked graphs) for (var setIdx = setCount - 1; setIdx >= 0; setIdx--) { var setName = setNames[setIdx]; if (!g.getOption('fillGraph', setName)) continue; - + + var stepPlot = g.getOption('stepPlot', setName); var color = colors[setIdx]; var axis = g.axisPropertiesForSeries(setName); var axisY = 1.0 + axis.minyval * axis.yscale; @@ -738,7 +739,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { if (currBaseline === undefined) { lastY = axisY; } else { - if(stepPlot) { + if(prevStepPlot) { lastY = currBaseline[0]; } else { lastY = currBaseline; @@ -763,17 +764,18 @@ DygraphCanvasRenderer._fillPlotter = function(e) { } if (!isNaN(prevX)) { ctx.moveTo(prevX, prevYs[0]); - + + // Move to top fill point if (stepPlot) { ctx.lineTo(point.canvasx, prevYs[0]); - if(currBaseline) { - // Draw to the bottom of the baseline - ctx.lineTo(point.canvasx, currBaseline[1]); - } else { - ctx.lineTo(point.canvasx, newYs[1]); - } } else { ctx.lineTo(point.canvasx, newYs[0]); + } + // Move to bottom fill point + if (prevStepPlot && currBaseline) { + // Draw to the bottom of the baseline + ctx.lineTo(point.canvasx, currBaseline[1]); + } else { ctx.lineTo(point.canvasx, newYs[1]); } @@ -783,6 +785,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { prevYs = newYs; prevX = point.canvasx; } + prevStepPlot = stepPlot; ctx.fill(); } }; diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index 0f601d157..de17decee 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -469,7 +469,7 @@ Dygraph.OPTIONS_REFERENCE = // "default": "false", "labels": ["Data Line display"], "type": "boolean", - "description": "When set, display the graph as a step plot instead of a line plot." + "description": "When set, display the graph as a step plot instead of a line plot. This option may either be set for the whole graph or for single series." }, "labelsKMB": { "default": "false", diff --git a/tests/steps.html b/tests/steps.html index 42b736290..8c5881164 100644 --- a/tests/steps.html +++ b/tests/steps.html @@ -153,6 +153,118 @@ includeZero: true }); + +

9: Mixed mode - step and line:

+
+ + + +

10: Mixed mode - step and line (filled):

+
+ + +

11: Mixed mode - step and line (stacked and filled):

+
+ + +

12: Mixed mode - step and line (errorbars):

+
+ + +

13: Mixed mode - step and line (custombars):

+
+ From 4fa81db559064456958ecbd49176556a2c998a91 Mon Sep 17 00:00:00 2001 From: eichsjul Date: Thu, 7 Feb 2013 10:44:16 +0100 Subject: [PATCH 5/7] FEATURE: Added tests for stepPlot option per series --- auto_tests/misc/local.html | 1 + auto_tests/tests/stepPlot_per_series.js | 429 ++++++++++++++++++++++++ 2 files changed, 430 insertions(+) create mode 100644 auto_tests/tests/stepPlot_per_series.js diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index ea529fec4..d12645391 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -47,6 +47,7 @@ +