X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-canvas.js;h=e531ece4ba73566b0a5df54ab391fccd687d6935;hb=34ad56b341279a066dc8bad129501d8d254699c1;hp=65678083c63ab7e202b390142c4d6e118ea64296;hpb=de9a8181064aa767e1c70c31a0027a0324cc33c6;p=dygraphs.git diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 6567808..e531ece 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -57,6 +57,8 @@ var DygraphCanvasRenderer = function(dygraph, element, elementContext, layout) { this.height = this.element.height; this.width = this.element.width; + this.elementContext.save(); + // --- check whether everything is ok before we return if (!this.isIE && !(DygraphCanvasRenderer.isSupported(this.element))) throw "Canvas is not supported."; @@ -125,6 +127,11 @@ DygraphCanvasRenderer.prototype.clear = function() { context.clearRect(0, 0, this.width, this.height); }; +DygraphCanvasRenderer.prototype.onDoneDrawing = function() { + // balances the save called in the constructor. + this.elementContext.restore(); +} + /** * Checks whether the browser supports the <canvas> tag. * @private @@ -261,11 +268,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; @@ -479,7 +482,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ for (var j = 0; j < sets.length; j++) { setName = setNames[j]; - if (opt_seriesName && setName != opt_seriesName) continue; + if (opt_seriesName && !(is_last && setName == opt_seriesName)) continue; var points = sets[j]; @@ -596,7 +599,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,18 +699,19 @@ DygraphCanvasRenderer._fillPlotter = function(e) { var setCount = sets.length; var fillAlpha = g.getOption('fillAlpha'); - var stepPlot = g.getOption('stepPlot'); 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; @@ -742,7 +746,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { if (currBaseline === undefined) { lastY = axisY; } else { - if(stepPlot) { + if(prevStepPlot) { lastY = currBaseline[0]; } else { lastY = currBaseline; @@ -767,17 +771,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]); } @@ -787,6 +792,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { prevYs = newYs; prevX = point.canvasx; } + prevStepPlot = stepPlot; ctx.fill(); } };