From 984b8fbf5c18eb51b75aaa63b9e990c5f1a2bf4f Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 21 Jul 2013 10:15:35 -0400 Subject: [PATCH] consolidate to static logging functions; hide more symbols --- auto_tests/misc/local.js | 1 - dygraph-canvas.js | 2 +- dygraph-layout.js | 10 +-- dygraph-utils.js | 46 ++++++-------- dygraph.js | 152 ++++++++++++++++++++++++---------------------- plugins/legend.js | 4 +- plugins/range-selector.js | 2 +- 7 files changed, 105 insertions(+), 112 deletions(-) diff --git a/auto_tests/misc/local.js b/auto_tests/misc/local.js index ae3e3df..3c7b1c6 100644 --- a/auto_tests/misc/local.js +++ b/auto_tests/misc/local.js @@ -34,7 +34,6 @@ DygraphsLocalTester.prototype.overrideWarn = function() { } throw 'Warnings not permitted: ' + msg; } - Dygraph.prototype.warn = Dygraph.warn; }; DygraphsLocalTester.prototype.processVariables = function() { diff --git a/dygraph-canvas.js b/dygraph-canvas.js index c43b6e2..e1f97fa 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -590,7 +590,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { var fillGraph = g.getOption("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; diff --git a/dygraph-layout.js b/dygraph-layout.js index e766e8f..7b1bc7a 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -153,13 +153,13 @@ DygraphLayout.prototype.setAnnotations = function(ann) { for (var i = 0; i < ann.length; i++) { var a = {}; if (!ann[i].xval && ann[i].x === undefined) { - this.dygraph_.error("Annotations must have an 'x' property"); + Dygraph.error("Annotations must have an 'x' property"); return; } if (ann[i].icon && !(ann[i].hasOwnProperty('width') && ann[i].hasOwnProperty('height'))) { - this.dygraph_.error("Must set width and height when setting " + + Dygraph.error("Must set width and height when setting " + "annotation.icon property"); return; } @@ -203,9 +203,9 @@ DygraphLayout.prototype._evaluateLimits = function() { axis.ylogrange = Dygraph.log10(axis.maxyval) - Dygraph.log10(axis.minyval); axis.ylogscale = (axis.ylogrange !== 0 ? 1.0 / axis.ylogrange : 1.0); if (!isFinite(axis.ylogrange) || isNaN(axis.ylogrange)) { - axis.g.error('axis ' + i + ' of graph at ' + axis.g + - ' can\'t be displayed in log scale for range [' + - axis.minyval + ' - ' + axis.maxyval + ']'); + Dygraph.error('axis ' + i + ' of graph at ' + axis.g + + ' can\'t be displayed in log scale for range [' + + axis.minyval + ' - ' + axis.maxyval + ']'); } } } diff --git a/dygraph-utils.js b/dygraph-utils.js index 24e4bb6..7366bae 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -11,12 +11,13 @@ * search) and generic DOM-manipulation functions. */ +(function() { + /*jshint globalstrict: true */ /*global Dygraph:false, G_vmlCanvasManager:false, Node:false, printStackTrace: false */ "use strict"; -Dygraph.LOG_SCALE = 10; -Dygraph.LN_TEN = Math.log(Dygraph.LOG_SCALE); +Dygraph.LN_TEN = Math.log(10); /** * @private @@ -28,10 +29,10 @@ Dygraph.log10 = function(x) { }; // Various logging levels. -Dygraph.DEBUG = 1; -Dygraph.INFO = 2; -Dygraph.WARNING = 3; -Dygraph.ERROR = 3; +var DEBUG = 1; +var INFO = 2; +var WARNING = 3; +var ERROR = 3; // Set this to log stack traces on warnings, etc. // This requires stacktrace.js, which is up to you to provide. @@ -48,7 +49,7 @@ Dygraph.DOT_DASH_LINE = [7, 2, 2, 2]; /** * Log an error on the JS console at the given severity. - * @param {number} severity One of Dygraph.{DEBUG,INFO,WARNING,ERROR} + * @param {number} severity One of {DEBUG,INFO,WARNING,ERROR} * @param {string} message The message to log. * @private */ @@ -89,16 +90,16 @@ Dygraph.log = function(severity, message) { }; switch (severity) { - case Dygraph.DEBUG: + case DEBUG: log(console, console.debug, 'dygraphs: ' + message); break; - case Dygraph.INFO: + case INFO: log(console, console.info, 'dygraphs: ' + message); break; - case Dygraph.WARNING: + case WARNING: log(console, console.warn, 'dygraphs: ' + message); break; - case Dygraph.ERROR: + case ERROR: log(console, console.error, 'dygraphs: ' + message); break; } @@ -116,38 +117,23 @@ Dygraph.log = function(severity, message) { * @private */ Dygraph.info = function(message) { - Dygraph.log(Dygraph.INFO, message); + Dygraph.log(INFO, message); }; -/** - * @param {string} message - * @private - */ -Dygraph.prototype.info = Dygraph.info; /** * @param {string} message * @private */ Dygraph.warn = function(message) { - Dygraph.log(Dygraph.WARNING, message); + Dygraph.log(WARNING, message); }; -/** - * @param {string} message - * @private - */ -Dygraph.prototype.warn = Dygraph.warn; /** * @param {string} message */ Dygraph.error = function(message) { - Dygraph.log(Dygraph.ERROR, message); + Dygraph.log(ERROR, message); }; -/** - * @param {string} message - * @private - */ -Dygraph.prototype.error = Dygraph.error; /** * Return the 2d context for a dygraph canvas. @@ -1203,3 +1189,5 @@ Dygraph.toRGB_ = function(color_str) { b: parseInt(bits[3], 10) }; }; + +})(); diff --git a/dygraph.js b/dygraph.js index 41b6f28..96a2999 100644 --- a/dygraph.js +++ b/dygraph.js @@ -43,6 +43,8 @@ */ +var Dygraph = (function() { + /*jshint globalstrict: true */ /*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false */ "use strict"; @@ -66,7 +68,7 @@ var Dygraph = function(div, data, opts, opt_fourth_param) { // Old versions of dygraphs took in the series labels as a constructor // parameter. This doesn't make sense anymore, but it's easy to continue // to support this usage. - this.warn("Using deprecated four-argument dygraph constructor"); + Dygraph.warn("Using deprecated four-argument dygraph constructor"); this.__old_init__(div, data, opts, opt_fourth_param); } else { this.__init__(div, data, opts); @@ -87,19 +89,19 @@ Dygraph.toString = function() { }; // Various default values -Dygraph.DEFAULT_ROLL_PERIOD = 1; -Dygraph.DEFAULT_WIDTH = 480; -Dygraph.DEFAULT_HEIGHT = 320; +var DEFAULT_ROLL_PERIOD = 1; +var DEFAULT_WIDTH = 480; +var DEFAULT_HEIGHT = 320; // For max 60 Hz. animation: -Dygraph.ANIMATION_STEPS = 12; -Dygraph.ANIMATION_DURATION = 200; +var ANIMATION_STEPS = 12; +var ANIMATION_DURATION = 200; // Label constants for the labelsKMB and labelsKMG2 options. // (i.e. '100000' -> '100K') -Dygraph.KMB_LABELS = [ 'K', 'M', 'B', 'T', 'Q' ]; -Dygraph.KMG2_BIG_LABELS = [ 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' ]; -Dygraph.KMG2_SMALL_LABELS = [ 'm', 'u', 'n', 'p', 'f', 'a', 'z', 'y' ]; +var KMB_LABELS = [ 'K', 'M', 'B', 'T', 'Q' ]; +var KMG2_BIG_LABELS = [ 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' ]; +var KMG2_SMALL_LABELS = [ 'm', 'u', 'n', 'p', 'f', 'a', 'z', 'y' ]; // These are defined before DEFAULT_ATTRS so that it can refer to them. /** @@ -142,13 +144,13 @@ Dygraph.numberValueFormatter = function(x, opts, pt, g) { var m_labels = []; if (kmb) { k = 1000; - k_labels = Dygraph.KMB_LABELS; + k_labels = KMB_LABELS; } if (kmg2) { if (kmb) Dygraph.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); k = 1024; - k_labels = Dygraph.KMG2_BIG_LABELS; - m_labels = Dygraph.KMG2_SMALL_LABELS; + k_labels = KMG2_BIG_LABELS; + m_labels = KMG2_SMALL_LABELS; } var absx = Math.abs(x); @@ -188,9 +190,8 @@ Dygraph.numberAxisLabelFormatter = function(x, granularity, opts, g) { /** * @type {!Array.} - * @private */ -Dygraph.shortMonthNames_ = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; +var SHORT_MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; /** * Convert a JS date to a string appropriate to display on an axis that @@ -206,13 +207,13 @@ Dygraph.dateAxisFormatter = function(date, granularity) { return '' + date.getFullYear(); } else if (granularity >= Dygraph.MONTHLY) { // e.g. 'Jan 13' (%b %y) - return Dygraph.shortMonthNames_[date.getMonth()] + ' ' + date.getFullYear(); + return SHORT_MONTH_NAMES[date.getMonth()] + ' ' + date.getFullYear(); } else { var frac = date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds() + date.getMilliseconds(); if (frac === 0 || granularity >= Dygraph.DAILY) { // e.g. '21Jan' (%d%b) var nd = new Date(date.getTime() + 3600*1000); - return Dygraph.zeropad(nd.getDate()) + Dygraph.shortMonthNames_[nd.getMonth()]; + return Dygraph.zeropad(nd.getDate()) + SHORT_MONTH_NAMES[nd.getMonth()]; } else { return Dygraph.hmsString_(date.getTime()); } @@ -356,8 +357,8 @@ Dygraph.DEFAULT_ATTRS = { // Directions for panning and zooming. Use bit operations when combined // values are possible. -Dygraph.HORIZONTAL = 1; -Dygraph.VERTICAL = 2; +var HORIZONTAL = 1; +var VERTICAL = 2; // Installed plugins, in order of precedence (most-general to most-specific). // Plugins are installed after they are defined, in plugins/install.js. @@ -365,7 +366,7 @@ Dygraph.PLUGINS = [ ]; // Used for initializing annotation CSS rules only once. -Dygraph.addedAnnotationCSS = false; +var addedAnnotationCSS = false; Dygraph.prototype.__old_init__ = function(div, file, labels, attrs) { // Labels is no longer a constructor parameter, since it's typically set @@ -420,7 +421,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { // TODO(danvk): most of these should just stay in the attrs_ dictionary. this.maindiv_ = div; this.file_ = file; - this.rollPeriod_ = attrs.rollPeriod || Dygraph.DEFAULT_ROLL_PERIOD; + this.rollPeriod_ = attrs.rollPeriod || DEFAULT_ROLL_PERIOD; this.previousVerticalX_ = -1; this.fractions_ = attrs.fractions || false; this.dateWindow_ = attrs.dateWindow || null; @@ -447,9 +448,9 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { div.style.height = attrs.height + "px"; } if (div.style.height === '' && div.clientHeight === 0) { - div.style.height = Dygraph.DEFAULT_HEIGHT + "px"; + div.style.height = DEFAULT_HEIGHT + "px"; if (div.style.width === '') { - div.style.width = Dygraph.DEFAULT_WIDTH + "px"; + div.style.width = DEFAULT_WIDTH + "px"; } } // These will be zero if the dygraph's div is hidden. In that case, @@ -617,10 +618,10 @@ Dygraph.prototype.toString = function() { Dygraph.prototype.attr_ = function(name, seriesName) { // if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') { - this.error('Must include options reference JS for testing'); + Dygraph.error('Must include options reference JS for testing'); } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) { - this.error('Dygraphs is using property ' + name + ', which has no entry ' + - 'in the Dygraphs.OPTIONS_REFERENCE listing.'); + Dygraph.error('Dygraphs is using property ' + name + ', which has no ' + + 'entry in the Dygraphs.OPTIONS_REFERENCE listing.'); // Only log this error once. Dygraph.OPTIONS_REFERENCE[name] = true; } @@ -863,7 +864,7 @@ Dygraph.prototype.toDataYCoord = function(y, axis) { var logr1 = Dygraph.log10(yRange[1]); var exponent = logr1 - (pct * (logr1 - Dygraph.log10(yRange[0]))); - var value = Math.pow(Dygraph.LOG_SCALE, exponent); + var value = Math.pow(10, exponent); return value; } }; @@ -1375,7 +1376,7 @@ Dygraph.prototype.createDragInterface_ = function() { * dots. * * @param {Number} direction the direction of the zoom rectangle. Acceptable - * values are Dygraph.HORIZONTAL and Dygraph.VERTICAL. + * values are HORIZONTAL and VERTICAL. * @param {Number} startX The X position where the drag started, in canvas * coordinates. * @param {Number} endX The current X position of the drag, in canvas coords. @@ -1396,22 +1397,22 @@ Dygraph.prototype.drawZoomRect_ = function(direction, startX, endX, startY, var ctx = this.canvas_ctx_; // Clean up from the previous rect if necessary - if (prevDirection == Dygraph.HORIZONTAL) { + if (prevDirection == HORIZONTAL) { ctx.clearRect(Math.min(startX, prevEndX), this.layout_.getPlotArea().y, Math.abs(startX - prevEndX), this.layout_.getPlotArea().h); - } else if (prevDirection == Dygraph.VERTICAL) { + } else if (prevDirection == VERTICAL) { ctx.clearRect(this.layout_.getPlotArea().x, Math.min(startY, prevEndY), this.layout_.getPlotArea().w, Math.abs(startY - prevEndY)); } // Draw a light-grey rectangle to show the new viewing area - if (direction == Dygraph.HORIZONTAL) { + if (direction == HORIZONTAL) { if (endX && startX) { ctx.fillStyle = "rgba(128,128,128,0.33)"; ctx.fillRect(Math.min(startX, endX), this.layout_.getPlotArea().y, Math.abs(endX - startX), this.layout_.getPlotArea().h); } - } else if (direction == Dygraph.VERTICAL) { + } else if (direction == VERTICAL) { if (endY && startY) { ctx.fillStyle = "rgba(128,128,128,0.33)"; ctx.fillRect(this.layout_.getPlotArea().x, Math.min(startY, endY), @@ -1611,7 +1612,7 @@ Dygraph.prototype.resetZoom = function() { * @private */ Dygraph.prototype.doAnimatedZoom = function(oldXRange, newXRange, oldYRanges, newYRanges, callback) { - var steps = this.attr_("animatedZooms") ? Dygraph.ANIMATION_STEPS : 1; + var steps = this.attr_("animatedZooms") ? ANIMATION_STEPS : 1; var windows = []; var valueRanges = []; @@ -1649,7 +1650,7 @@ Dygraph.prototype.doAnimatedZoom = function(oldXRange, newXRange, oldYRanges, ne that.dateWindow_ = windows[step]; } that.drawGraph_(); - }, steps, Dygraph.ANIMATION_DURATION / steps, callback); + }, steps, ANIMATION_DURATION / steps, callback); }; /** @@ -3134,7 +3135,7 @@ Dygraph.prototype.parseFloat_ = function(x, opt_line_no, opt_line) { if (opt_line !== null && opt_line_no !== null) { msg += " on line " + (1+opt_line_no) + " ('" + opt_line + "') of CSV."; } - this.error(msg); + Dygraph.error(msg); return null; }; @@ -3203,9 +3204,10 @@ Dygraph.prototype.parseCSV_ = function(data) { // TODO(danvk): figure out an appropriate way to flag parse errors. vals = inFields[j].split("/"); if (vals.length != 2) { - this.error('Expected fractional "num/den" values in CSV data ' + - "but found a value '" + inFields[j] + "' on line " + - (1 + i) + " ('" + line + "') which is not of this form."); + Dygraph.error('Expected fractional "num/den" values in CSV data ' + + "but found a value '" + inFields[j] + "' on line " + + (1 + i) + " ('" + line + "') which is not of this " + + "form."); fields[j] = [0, 0]; } else { fields[j] = [this.parseFloat_(vals[0], i, line), @@ -3215,9 +3217,9 @@ Dygraph.prototype.parseCSV_ = function(data) { } else if (this.attr_("errorBars")) { // If there are error bars, values are (value, stddev) pairs if (inFields.length % 2 != 1) { - this.error('Expected alternating (value, stdev.) pairs in CSV data ' + - 'but line ' + (1 + i) + ' has an odd number of values (' + - (inFields.length - 1) + "): '" + line + "'"); + Dygraph.error('Expected alternating (value, stdev.) pairs in CSV ' + + 'data but line ' + (1 + i) + ' has an odd number of ' + + 'values (' + (inFields.length - 1) + "): '" + line + "'"); } for (j = 1; j < inFields.length; j += 2) { fields[(j + 1) / 2] = [this.parseFloat_(inFields[j], i, line), @@ -3236,7 +3238,7 @@ Dygraph.prototype.parseCSV_ = function(data) { this.parseFloat_(vals[1], i, line), this.parseFloat_(vals[2], i, line) ]; } else { - this.warn('When using customBars, values must be either blank ' + + Dygraph.warn('When using customBars, values must be either blank ' + 'or "low;center;high" tuples (got "' + val + '" on line ' + (1+i)); } @@ -3253,9 +3255,9 @@ Dygraph.prototype.parseCSV_ = function(data) { } if (fields.length != expectedCols) { - this.error("Number of columns in line " + i + " (" + fields.length + - ") does not agree with number of labels (" + expectedCols + - ") " + line); + Dygraph.error("Number of columns in line " + i + " (" + fields.length + + ") does not agree with number of labels (" + expectedCols + + ") " + line); } // If the user specified the 'labels' option and none of the cells of the @@ -3268,7 +3270,7 @@ Dygraph.prototype.parseCSV_ = function(data) { if (fields[j]) all_null = false; } if (all_null) { - this.warn("The dygraphs 'labels' option is set, but the first row of " + + Dygraph.warn("The dygraphs 'labels' option is set, but the first row of " + "CSV data ('" + line + "') appears to also contain labels. " + "Will drop the CSV labels and use the option labels."); continue; @@ -3278,7 +3280,7 @@ Dygraph.prototype.parseCSV_ = function(data) { } if (outOfOrder) { - this.warn("CSV is out of order; order it correctly to speed loading."); + Dygraph.warn("CSV is out of order; order it correctly to speed loading."); ret.sort(function(a,b) { return a[0] - b[0]; }); } @@ -3296,17 +3298,17 @@ Dygraph.prototype.parseCSV_ = function(data) { Dygraph.prototype.parseArray_ = function(data) { // Peek at the first x value to see if it's numeric. if (data.length === 0) { - this.error("Can't plot empty data set"); + Dygraph.error("Can't plot empty data set"); return null; } if (data[0].length === 0) { - this.error("Data set cannot contain an empty row"); + Dygraph.error("Data set cannot contain an empty row"); return null; } var i; if (this.attr_("labels") === null) { - this.warn("Using default labels. Set labels explicitly via 'labels' " + + Dygraph.warn("Using default labels. Set labels explicitly via 'labels' " + "in the options parameter"); this.attrs_.labels = [ "X" ]; for (i = 1; i < data[0].length; i++) { @@ -3316,8 +3318,8 @@ Dygraph.prototype.parseArray_ = function(data) { } else { var num_labels = this.attr_("labels"); if (num_labels.length != data[0].length) { - this.error("Mismatch between number of labels (" + num_labels + - ") and number of columns in array (" + data[0].length + ")"); + Dygraph.error("Mismatch between number of labels (" + num_labels + ") " + + "and number of columns in array (" + data[0].length + ")"); return null; } } @@ -3332,13 +3334,13 @@ Dygraph.prototype.parseArray_ = function(data) { var parsedData = Dygraph.clone(data); for (i = 0; i < data.length; i++) { if (parsedData[i].length === 0) { - this.error("Row " + (1 + i) + " of data is empty"); + Dygraph.error("Row " + (1 + i) + " of data is empty"); return null; } if (parsedData[i][0] === null || typeof(parsedData[i][0].getTime) != 'function' || isNaN(parsedData[i][0].getTime())) { - this.error("x value in row " + (1 + i) + " is not a Date"); + Dygraph.error("x value in row " + (1 + i) + " is not a Date"); return null; } parsedData[i][0] = parsedData[i][0].getTime(); @@ -3392,8 +3394,8 @@ Dygraph.prototype.parseDataTable_ = function(data) { this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter; } else { - this.error("only 'date', 'datetime' and 'number' types are supported for " + - "column 1 of DataTable input (Got '" + indepType + "')"); + Dygraph.error("only 'date', 'datetime' and 'number' types are supported for " + + "column 1 of DataTable input (Got '" + indepType + "')"); return null; } @@ -3416,8 +3418,9 @@ Dygraph.prototype.parseDataTable_ = function(data) { } hasAnnotations = true; } else { - this.error("Only 'number' is supported as a dependent type with Gviz." + - " 'string' is only supported if displayAnnotations is true"); + Dygraph.error("Only 'number' is supported as a dependent type with " + + "Gviz. 'string' is only supported if displayAnnotations " + + "is true"); } } @@ -3438,8 +3441,8 @@ Dygraph.prototype.parseDataTable_ = function(data) { var row = []; if (typeof(data.getValue(i, 0)) === 'undefined' || data.getValue(i, 0) === null) { - this.warn("Ignoring row " + i + - " of DataTable because of undefined or null first column."); + Dygraph.warn("Ignoring row " + i + + " of DataTable because of undefined or null first column."); continue; } @@ -3484,7 +3487,7 @@ Dygraph.prototype.parseDataTable_ = function(data) { } if (outOfOrder) { - this.warn("DataTable is out of order; order it correctly to speed loading."); + Dygraph.warn("DataTable is out of order; order it correctly to speed loading."); ret.sort(function(a,b) { return a[0] - b[0]; }); } this.rawData_ = ret; @@ -3537,7 +3540,7 @@ Dygraph.prototype.start_ = function() { req.send(null); } } else { - this.error("Unknown data format: " + (typeof data)); + Dygraph.error("Unknown data format: " + (typeof data)); } }; @@ -3666,8 +3669,8 @@ Dygraph.prototype.resize = function(width, height) { this.resize_lock = true; if ((width === null) != (height === null)) { - this.warn("Dygraph.resize() should be called with zero parameters or " + - "two non-NULL parameters. Pretending it was zero."); + Dygraph.warn("Dygraph.resize() should be called with zero parameters or " + + "two non-NULL parameters. Pretending it was zero."); width = height = null; } @@ -3726,7 +3729,7 @@ Dygraph.prototype.visibility = function() { Dygraph.prototype.setVisibility = function(num, value) { var x = this.visibility(); if (num < 0 || num >= x.length) { - this.warn("invalid series number in setVisibility: " + num); + Dygraph.warn("invalid series number in setVisibility: " + num); } else { x[num] = value; this.predraw_(); @@ -3751,12 +3754,12 @@ Dygraph.prototype.size = function() { */ Dygraph.prototype.setAnnotations = function(ann, suppressDraw) { // Only add the annotation CSS rule once we know it will be used. - Dygraph.addAnnotationRule(); + addAnnotationRule(); this.annotations_ = ann; if (!this.layout_) { - this.warn("Tried to setAnnotations before dygraph was ready. " + - "Try setting them in a drawCallback. See " + - "dygraphs.com/tests/annotation.html"); + Dygraph.warn("Tried to setAnnotations before dygraph was ready. " + + "Try setting them in a drawCallback. See " + + "dygraphs.com/tests/annotation.html"); return; } @@ -3793,14 +3796,13 @@ Dygraph.prototype.indexFromSetName = function(name) { }; /** - * @private * 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. */ -Dygraph.addAnnotationRule = function() { +var addAnnotationRule = function() { // TODO(danvk): move this function into plugins/annotations.js? - if (Dygraph.addedAnnotationCSS) return; + if (addedAnnotationCSS) return; var rule = "border: 1px solid black; " + "background-color: white; " + @@ -3824,12 +3826,16 @@ Dygraph.addAnnotationRule = function() { } else if (mysheet.addRule) { // IE mysheet.addRule(".dygraphDefaultAnnotation", rule); } - Dygraph.addedAnnotationCSS = true; + addedAnnotationCSS = true; return; } catch(err) { // Was likely a security exception. } } - this.warn("Unable to add default annotation CSS rule; display may be off."); + Dygraph.warn("Unable to add default annotation CSS rule; display may be off."); }; + +return Dygraph; + +})(); diff --git a/plugins/legend.js b/plugins/legend.js index 7406f82..4c37d75 100644 --- a/plugins/legend.js +++ b/plugins/legend.js @@ -88,8 +88,8 @@ legend.prototype.activate = function(g) { try { div.style[name] = messagestyle[name]; } catch (e) { - this.warn("You are using unsupported css properties for your " + - "browser in labelsDivStyles"); + Dygraph.warn("You are using unsupported css properties for your " + + "browser in labelsDivStyles"); } } diff --git a/plugins/range-selector.js b/plugins/range-selector.js index 089e64a..e3f0755 100644 --- a/plugins/range-selector.js +++ b/plugins/range-selector.js @@ -74,7 +74,7 @@ rangeSelector.prototype.createInterface_ = function() { // Range selector and animatedZooms have a bad interaction. See issue 359. if (this.getOption_('animatedZooms')) { - this.dygraph_.warn('Animated zooms and range selector are not compatible; disabling animatedZooms.'); + Dygraph.warn('Animated zooms and range selector are not compatible; disabling animatedZooms.'); this.dygraph_.updateOptions({animatedZooms: false}, true); } -- 2.7.4