From: Dan Vanderkam Date: Fri, 6 Jul 2012 01:05:41 +0000 (-0400) Subject: add some comments X-Git-Tag: v1.0.0~259 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=8cfe592f75ebfe39460a51558488aa7b12ccc87c;p=dygraphs.git add some comments --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 4a29848..f1e3c8c 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -29,6 +29,23 @@ "use strict"; +/** + * @constructor + * + * This gets called when there are "new points" to chart. This is generally the + * case when the underlying data being charted has changed. It is _not_ called + * in the common case that the user has zoomed or is panning the view. + * + * The chart canvas has already been created by the Dygraph object. The + * renderer simply gets a drawing context. + * + * @param {Dyraph} dygraph The chart to which this renderer belongs. + * @param {Canvas} element The <canvas> DOM element on which to draw. + * @param {CanvasRenderingContext2D} elementContext The drawing context. + * @param {DygraphLayout} layout The chart's DygraphLayout object. + * + * TODO(danvk): remove the elementContext property. + */ var DygraphCanvasRenderer = function(dygraph, element, elementContext, layout) { this.dygraph_ = dygraph; @@ -79,6 +96,12 @@ DygraphCanvasRenderer.prototype.attr_ = function(x) { return this.dygraph_.attr_(x); }; +/** + * Clears out all chart content and DOM elements. + * This is called immediately before render() on every frame, including + * during zooms and pans. + * @private + */ DygraphCanvasRenderer.prototype.clear = function() { var context; if (this.isIE) { @@ -123,7 +146,10 @@ DygraphCanvasRenderer.prototype.clear = function() { this.chartLabels = {}; }; - +/** + * Checks whether the browser supports the <canvas> tag. + * @private + */ DygraphCanvasRenderer.isSupported = function(canvasName) { var canvas = null; try { @@ -153,7 +179,11 @@ DygraphCanvasRenderer.prototype.setColors = function(colors) { }; /** - * Draw an X/Y grid on top of the existing plot + * 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 + * and zooms. + * @private */ DygraphCanvasRenderer.prototype.render = function() { // Draw the new X/Y grid. Lines appear crisper when pixels are rounded to diff --git a/dygraph.js b/dygraph.js index abd2973..8979c6f 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2332,6 +2332,9 @@ Dygraph.prototype.drawGraph_ = function() { Dygraph.prototype.renderGraph_ = function(is_initial_draw) { this.plotter_.clear(); this.plotter_.render(); + + // TODO(danvk): is this a performance bottleneck when panning? + // The interaction canvas should already be empty in that situation. this.canvas_.getContext('2d').clearRect(0, 0, this.canvas_.width, this.canvas_.height);