X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-canvas.js;h=e531ece4ba73566b0a5df54ab391fccd687d6935;hb=34ad56b341279a066dc8bad129501d8d254699c1;hp=5305ded52c66bf80656bbdfff33a4e5e0337b3d0;hpb=0ce5b19b6346c9e55494997c06f460fedcd48b11;p=dygraphs.git diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 5305ded..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 @@ -475,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]; @@ -692,18 +699,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 +746,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { if (currBaseline === undefined) { lastY = axisY; } else { - if(stepPlot) { + if(prevStepPlot) { lastY = currBaseline[0]; } else { lastY = currBaseline; @@ -763,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]); } @@ -783,6 +792,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { prevYs = newYs; prevX = point.canvasx; } + prevStepPlot = stepPlot; ctx.fill(); } };