From 104d87c50866e6e0c6a877e662b7c08e7bf4d780 Mon Sep 17 00:00:00 2001 From: eichsjul Date: Wed, 6 Feb 2013 13:48:35 +0100 Subject: [PATCH] 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 5305ded..fa0dd80 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 0f601d1..de17dec 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 42b7362..8c58811 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):

+
+ -- 2.7.4