From: Dan Vanderkam Date: Sun, 21 Jul 2013 15:06:03 +0000 (-0400) Subject: export fewer symbols from DygraphCanvasRenderer X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=76d753d3e53d8dbbf8fa05a35f2d239449280fed;p=dygraphs.git export fewer symbols from DygraphCanvasRenderer --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index e1f97fa..c7fed05 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -24,10 +24,22 @@ * @constructor */ +var DygraphCanvasRenderer = (function() { + /*jshint globalstrict: true */ /*global Dygraph:false,RGBColorParser:false */ "use strict"; +// Utility methods for this file. +var isCanvasSupported_, + getIteratorPredicate_, + predicateThatSkipsEmptyPoints_, + drawSeries_, + drawPointsOnLine_, + linePlotter_, + fillPlotter_, + errorPlotter_; + /** * @constructor @@ -59,7 +71,7 @@ var DygraphCanvasRenderer = function(dygraph, element, elementContext, layout) { // --- 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 && !(isCanvasSupported_(this.element))) throw "Canvas is not supported."; // internal state @@ -89,15 +101,6 @@ var DygraphCanvasRenderer = function(dygraph, element, elementContext, layout) { }; /** - * This just forwards to dygraph.attr_. - * TODO(danvk): remove this? - * @private - */ -DygraphCanvasRenderer.prototype.attr_ = function(name, opt_seriesName) { - return this.dygraph_.attr_(name, opt_seriesName); -}; - -/** * Clears out all chart content and DOM elements. * This is called immediately before render() on every frame, including * during zooms and pans. @@ -128,9 +131,8 @@ DygraphCanvasRenderer.prototype.clear = function() { /** * Checks whether the browser supports the <canvas> tag. - * @private */ -DygraphCanvasRenderer.isSupported = function(canvasName) { +isCanvasSupported_ = function(canvasName) { var canvas = null; try { if (typeof(canvasName) == 'undefined' || canvasName === null) { @@ -241,14 +243,11 @@ DygraphCanvasRenderer.prototype._createIEClipArea = function() { * connectSeparatedPoints is true. When it's false, the predicate will * skip over points with missing yVals. */ -DygraphCanvasRenderer._getIteratorPredicate = function(connectSeparatedPoints) { - return connectSeparatedPoints ? - DygraphCanvasRenderer._predicateThatSkipsEmptyPoints : - null; +getIteratorPredicate_ = function(connectSeparatedPoints) { + return connectSeparatedPoints ? predicateThatSkipsEmptyPoints_ : null; }; -DygraphCanvasRenderer._predicateThatSkipsEmptyPoints = - function(array, idx) { +predicateThatSkipsEmptyPoints_ = function(array, idx) { return array[idx].yval !== null; }; @@ -257,7 +256,7 @@ DygraphCanvasRenderer._predicateThatSkipsEmptyPoints = * @param {Object} e The dictionary passed to the plotter function. * @private */ -DygraphCanvasRenderer._drawStyledLine = function(e, +var drawStyledLine_ = function(e, color, strokeWidth, strokePattern, drawPoints, drawPointCallback, pointSize) { var g = e.dygraph; @@ -272,7 +271,7 @@ DygraphCanvasRenderer._drawStyledLine = function(e, var points = e.points; var iter = Dygraph.createIterator(points, 0, points.length, - DygraphCanvasRenderer._getIteratorPredicate( + getIteratorPredicate_( g.getOption("connectSeparatedPoints"))); // TODO(danvk): per-series? var stroking = strokePattern && (strokePattern.length >= 2); @@ -283,10 +282,9 @@ DygraphCanvasRenderer._drawStyledLine = function(e, ctx.installPattern(strokePattern); } - var pointsOnLine = DygraphCanvasRenderer._drawSeries( + var pointsOnLine = drawSeries_( e, iter, strokeWidth, pointSize, drawPoints, drawGapPoints, stepPlot, color); - DygraphCanvasRenderer._drawPointsOnLine( - e, pointsOnLine, drawPointCallback, color, pointSize); + drawPointsOnLine_(e, pointsOnLine, drawPointCallback, color, pointSize); if (stroking) { ctx.uninstallPattern(); @@ -301,9 +299,8 @@ DygraphCanvasRenderer._drawStyledLine = function(e, * drawPointCallback should be fired. These include isolated points, or all * points if drawPoints=true. * @param {Object} e The dictionary passed to the plotter function. - * @private */ -DygraphCanvasRenderer._drawSeries = function(e, +drawSeries_ = function(e, iter, strokeWidth, pointSize, drawPoints, drawGapPoints, stepPlot, color) { var prevCanvasX = null; @@ -392,7 +389,7 @@ DygraphCanvasRenderer._drawSeries = function(e, * @param {Object} e The dictionary passed to the plotter function. * @private */ -DygraphCanvasRenderer._drawPointsOnLine = function( +drawPointsOnLine_ = function( e, pointsOnLine, drawPointCallback, color, pointSize) { var ctx = e.drawingContext; for (var idx = 0; idx < pointsOnLine.length; idx++) { @@ -457,7 +454,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ this.colors = this.dygraph_.colorsMap_; // Determine which series have specialized plotters. - var plotter_attr = this.attr_("plotter"); + var plotter_attr = this.dygraph_.attr_("plotter"); var plotters = plotter_attr; if (!Dygraph.isArrayLike(plotters)) { plotters = [plotters]; @@ -466,7 +463,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ var setPlotters = {}; // series name -> plotter fn. for (i = 0; i < setNames.length; i++) { setName = setNames[i]; - var setPlotter = this.attr_("plotter", setName); + var setPlotter = this.dygraph_.attr_("plotter", setName); if (setPlotter == plotter_attr) continue; // not specialized. setPlotters[setName] = setPlotter; @@ -519,34 +516,16 @@ DygraphCanvasRenderer.prototype._renderLineChart = function(opt_seriesName, opt_ }; /** - * Standard plotters. These may be used by clients via Dygraph.Plotters. - * See comments there for more details. - */ -DygraphCanvasRenderer._Plotters = { - linePlotter: function(e) { - DygraphCanvasRenderer._linePlotter(e); - }, - - fillPlotter: function(e) { - DygraphCanvasRenderer._fillPlotter(e); - }, - - errorPlotter: function(e) { - DygraphCanvasRenderer._errorPlotter(e); - } -}; - -/** * Plotter which draws the central lines for a series. * @private */ -DygraphCanvasRenderer._linePlotter = function(e) { +linePlotter_ = function(e) { var g = e.dygraph; var setName = e.setName; var strokeWidth = e.strokeWidth; // TODO(danvk): Check if there's any performance impact of just calling - // getOption() inside of _drawStyledLine. Passing in so many parameters makes + // getOption() inside of drawStyledLine_. Passing in so many parameters makes // this code a bit nasty. var borderWidth = g.getOption("strokeBorderWidth", setName); var drawPointCallback = g.getOption("drawPointCallback", setName) || @@ -556,7 +535,7 @@ DygraphCanvasRenderer._linePlotter = function(e) { var pointSize = g.getOption("pointSize", setName); if (borderWidth && strokeWidth) { - DygraphCanvasRenderer._drawStyledLine(e, + drawStyledLine_(e, g.getOption("strokeBorderColor", setName), strokeWidth + 2 * borderWidth, strokePattern, @@ -566,7 +545,7 @@ DygraphCanvasRenderer._linePlotter = function(e) { ); } - DygraphCanvasRenderer._drawStyledLine(e, + drawStyledLine_(e, e.color, strokeWidth, strokePattern, @@ -582,7 +561,7 @@ DygraphCanvasRenderer._linePlotter = function(e) { * need to be drawn on top of the error bars for all series. * @private */ -DygraphCanvasRenderer._errorPlotter = function(e) { +errorPlotter_ = function(e) { var g = e.dygraph; var setName = e.setName; var errorBars = g.getOption("errorBars") || g.getOption("customBars"); @@ -600,8 +579,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { var points = e.points; var iter = Dygraph.createIterator(points, 0, points.length, - DygraphCanvasRenderer._getIteratorPredicate( - g.getOption("connectSeparatedPoints"))); + getIteratorPredicate_(g.getOption("connectSeparatedPoints"))); var newYs; @@ -667,7 +645,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { * * @private */ -DygraphCanvasRenderer._fillPlotter = function(e) { +fillPlotter_ = function(e) { // Skip if we're drawing a single series for interactive highlight overlay. if (e.singleSeriesName) return; @@ -728,8 +706,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { var points = sets[setIdx]; var iter = Dygraph.createIterator(points, 0, points.length, - DygraphCanvasRenderer._getIteratorPredicate( - g.getOption("connectSeparatedPoints"))); + getIteratorPredicate_(g.getOption("connectSeparatedPoints"))); // setup graphics context var prevX = NaN; @@ -814,3 +791,17 @@ DygraphCanvasRenderer._fillPlotter = function(e) { ctx.fill(); } }; + +/** + * Standard plotters. These may be used by clients via Dygraph.Plotters. + * See comments there for more details. + */ +DygraphCanvasRenderer._Plotters = { + linePlotter: linePlotter_, + fillPlotter: fillPlotter_, + errorPlotter: errorPlotter_ +}; + +return DygraphCanvasRenderer; + +})(); diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 31b485f..2e8178c 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -64,8 +64,11 @@ /*global Dygraph:false */ "use strict"; +// Constants, defined below. +var PREFERRED_LOG_TICK_VALUES; + /** @typedef {Array.<{v:number, label:string, label_v:(string|undefined)}>} */ -Dygraph.TickList = undefined; // the ' = undefined' keeps jshint happy. +var TickList; /** @typedef {function( * number, @@ -74,11 +77,11 @@ Dygraph.TickList = undefined; // the ' = undefined' keeps jshint happy. * function(string):*, * Dygraph=, * Array.= - * ): Dygraph.TickList} + * ): TickList} */ -Dygraph.Ticker = undefined; // the ' = undefined' keeps jshint happy. +var Ticker; -/** @type {Dygraph.Ticker} */ +/** @type {Ticker} */ Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) { var nonLogscaleOpts = function(opt) { if (opt === 'logscale') return false; @@ -87,7 +90,7 @@ Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) { return Dygraph.numericTicks(a, b, pixels, nonLogscaleOpts, dygraph, vals); }; -/** @type {Dygraph.Ticker} */ +/** @type {Ticker} */ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { var pixels_per_tick = /** @type{number} */(opts('pixelsPerLabel')); var ticks = []; @@ -206,7 +209,7 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { }; -/** @type {Dygraph.Ticker} */ +/** @type {Ticker} */ Dygraph.dateTicker = function(a, b, pixels, opts, dygraph, vals) { var chosen = Dygraph.pickDateTickGranularity(a, b, pixels, opts); @@ -301,7 +304,7 @@ LONG_TICK_PLACEMENTS[CENTENNIAL] = { * NOTE: this assumes that Dygraph.LOG_SCALE = 10. * @type {Array.} */ -var PREFERRED_LOG_TICK_VALUES = function() { +PREFERRED_LOG_TICK_VALUES = function() { var vals = []; for (var power = -39; power <= 39; power++) { var range = Math.pow(10, power); @@ -361,7 +364,7 @@ Dygraph.numDateTicks = function(start_time, end_time, granularity) { * @param {number} granularity (one of the granularities enumerated above) * @param {function(string):*} opts Function mapping from option name -> value. * @param {Dygraph=} dg - * @return {!Dygraph.TickList} + * @return {!TickList} */ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { var formatter = /** @type{AxisLabelFormatter} */( diff --git a/dygraph-utils.js b/dygraph-utils.js index ac147e5..4db8fcd 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -1180,7 +1180,7 @@ Dygraph.toRGB_ = function(color_str) { div.style.backgroundColor = color_str; div.style.visibility = 'hidden'; document.body.appendChild(div); - var rgb_str = window.getComputedStyle(div)['backgroundColor']; + var rgb_str = window.getComputedStyle(div).backgroundColor; document.body.removeChild(div); var bits = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(rgb_str); return { diff --git a/dygraph.js b/dygraph.js index 96a2999..bc5d4b6 100644 --- a/dygraph.js +++ b/dygraph.js @@ -3747,6 +3747,48 @@ Dygraph.prototype.size = function() { }; /** + * Adds a default style for the annotation CSS classes to the document. This is + * only executed when annotations are actually used. It is designed to only be + * called once -- all calls after the first will return immediately. + */ +var addAnnotationRule_ = function() { + // TODO(danvk): move this function into plugins/annotations.js? + if (addedAnnotationCSS) return; + + var rule = "border: 1px solid black; " + + "background-color: white; " + + "text-align: center;"; + + var styleSheetElement = document.createElement("style"); + styleSheetElement.type = "text/css"; + document.getElementsByTagName("head")[0].appendChild(styleSheetElement); + + // Find the first style sheet that we can access. + // We may not add a rule to a style sheet from another domain for security + // reasons. This sometimes comes up when using gviz, since the Google gviz JS + // adds its own style sheets from google.com. + for (var i = 0; i < document.styleSheets.length; i++) { + if (document.styleSheets[i].disabled) continue; + var mysheet = document.styleSheets[i]; + try { + if (mysheet.insertRule) { // Firefox + var idx = mysheet.cssRules ? mysheet.cssRules.length : 0; + mysheet.insertRule(".dygraphDefaultAnnotation { " + rule + " }", idx); + } else if (mysheet.addRule) { // IE + mysheet.addRule(".dygraphDefaultAnnotation", rule); + } + addedAnnotationCSS = true; + return; + } catch(err) { + // Was likely a security exception. + } + } + + Dygraph.warn("Unable to add default annotation CSS rule; display may be off."); +}; + + +/** * Update the list of annotations and redraw the chart. * See dygraphs.com/annotations.html for more info on how to use annotations. * @param ann {Array} An array of annotation objects. @@ -3754,7 +3796,7 @@ Dygraph.prototype.size = function() { */ Dygraph.prototype.setAnnotations = function(ann, suppressDraw) { // Only add the annotation CSS rule once we know it will be used. - addAnnotationRule(); + addAnnotationRule_(); this.annotations_ = ann; if (!this.layout_) { Dygraph.warn("Tried to setAnnotations before dygraph was ready. " + @@ -3795,47 +3837,6 @@ Dygraph.prototype.indexFromSetName = function(name) { return this.setIndexByName_[name]; }; -/** - * Adds a default style for the annotation CSS classes to the document. This is - * only executed when annotations are actually used. It is designed to only be - * called once -- all calls after the first will return immediately. - */ -var addAnnotationRule = function() { - // TODO(danvk): move this function into plugins/annotations.js? - if (addedAnnotationCSS) return; - - var rule = "border: 1px solid black; " + - "background-color: white; " + - "text-align: center;"; - - var styleSheetElement = document.createElement("style"); - styleSheetElement.type = "text/css"; - document.getElementsByTagName("head")[0].appendChild(styleSheetElement); - - // Find the first style sheet that we can access. - // We may not add a rule to a style sheet from another domain for security - // reasons. This sometimes comes up when using gviz, since the Google gviz JS - // adds its own style sheets from google.com. - for (var i = 0; i < document.styleSheets.length; i++) { - if (document.styleSheets[i].disabled) continue; - var mysheet = document.styleSheets[i]; - try { - if (mysheet.insertRule) { // Firefox - var idx = mysheet.cssRules ? mysheet.cssRules.length : 0; - mysheet.insertRule(".dygraphDefaultAnnotation { " + rule + " }", idx); - } else if (mysheet.addRule) { // IE - mysheet.addRule(".dygraphDefaultAnnotation", rule); - } - addedAnnotationCSS = true; - return; - } catch(err) { - // Was likely a security exception. - } - } - - Dygraph.warn("Unable to add default annotation CSS rule; display may be off."); -}; - return Dygraph; })();