X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-canvas.js;h=17908e396d7848edf5214beed29d84e17ccf0c23;hb=3b9a354de8087bcfb5a95f5ac2b58f67909d6a21;hp=78c0464e7b0ea29ef06582900e32cd0089ec0e95;hpb=70d47e7c9564e190f29f6a8bb1f4c547bef8781a;p=dygraphs.git diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 78c0464..17908e3 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -25,7 +25,7 @@ */ /*jshint globalstrict: true */ -/*global Dygraph:false,RGBColorParser:false */ +/*global Dygraph:false */ "use strict"; @@ -52,20 +52,17 @@ var DygraphCanvasRenderer = function(dygraph, element, elementContext, layout) { this.layout = layout; this.element = element; this.elementContext = elementContext; - this.container = this.element.parentNode; this.height = this.element.height; this.width = this.element.width; // --- check whether everything is ok before we return // NOTE(konigsberg): isIE is never defined in this object. Bug of some sort. - if (!this.isIE && !(DygraphCanvasRenderer.isSupported(this.element))) + if (!this.isIE && !(Dygraph.isCanvasSupported(this.element))) throw "Canvas is not supported."; // internal state this.area = layout.getPlotArea(); - this.container.style.position = "relative"; - this.container.style.width = this.width + "px"; // Set up a clipping area for the canvas (and the interaction canvas). // This ensures that we don't overdraw. @@ -118,30 +115,6 @@ DygraphCanvasRenderer.prototype.clear = function() { }; /** - * Checks whether the browser supports the <canvas> tag. - * @private - */ -DygraphCanvasRenderer.isSupported = function(canvasName) { - var canvas = null; - try { - if (typeof(canvasName) == 'undefined' || canvasName === null) { - canvas = document.createElement("canvas"); - } else { - canvas = canvasName; - } - canvas.getContext("2d"); - } - catch (e) { - var ie = navigator.appVersion.match(/MSIE (\d\.\d)/); - var opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); - if ((!ie) || (ie[1] < 6) || (opera)) - return false; - return true; - } - return true; -}; - -/** * This method is responsible for drawing everything on the chart, including * lines, error bars, fills and axes. * It is called immediately after clear() on every frame, including during pans @@ -586,7 +559,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { var fillGraph = g.getBooleanOption("fillGraph", setName); if (fillGraph) { - g.warn("Can't use fillGraph option with error bars"); + Dygraph.warn("Can't use fillGraph option with error bars"); } var ctx = e.drawingContext; @@ -606,7 +579,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { var prevY = NaN; var prevYs = [-1, -1]; // should be same color as the lines but only 15% opaque. - var rgb = new RGBColorParser(color); + var rgb = Dygraph.toRGB_(color); var err_color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + fillAlpha + ')'; ctx.fillStyle = err_color; @@ -732,7 +705,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { var prevYs = [-1, -1]; var newYs; // should be same color as the lines but only 15% opaque. - var rgb = new RGBColorParser(color); + var rgb = Dygraph.toRGB_(color); var err_color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + fillAlpha + ')'; ctx.fillStyle = err_color; @@ -740,7 +713,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { var last_x, is_first = true; while (iter.hasNext) { var point = iter.next(); - if (!Dygraph.isOK(point.y)) { + if (!Dygraph.isOK(point.y) && !stepPlot) { prevX = NaN; if (point.y_stacked !== null && !isNaN(point.y_stacked)) { baseline[point.canvasx] = area.h * point.y_stacked + area.y; @@ -781,7 +754,11 @@ DygraphCanvasRenderer._fillPlotter = function(e) { } } else { - newYs = [ point.canvasy, axisY ]; + if (isNaN(point.canvasy) && stepPlot) { + newYs = [ area.y + area.h, axisY ]; + } else { + newYs = [ point.canvasy, axisY ]; + } } if (!isNaN(prevX)) { ctx.moveTo(prevX, prevYs[0]);