From: Dan Vanderkam Date: Thu, 29 Aug 2013 14:14:02 +0000 (-0400) Subject: 52 warnings X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=78a3a915f4d1febc5256a1735b5f21eb62fff18d;p=dygraphs.git 52 warnings --- diff --git a/closure-todo.txt b/closure-todo.txt index 94940ea..4d794e7 100644 --- a/closure-todo.txt +++ b/closure-todo.txt @@ -9,6 +9,7 @@ This file tracks which files have been fully "closurized", i.e. compile under the Closure Compiler without any errors or warnings. Core: +x dygraph-constants.js x dygraph-canvas.js x dygraph-interaction-model.js x dygraph-layout.js @@ -41,7 +42,7 @@ Datahandler: Here's a command that can be used to build dygraphs using the closure compiler: -java -jar ../../closure-compiler-read-only/build/compiler.jar --js ../../closure-library-read-only/closure/goog/base.js --js=dygraph-utils.js --js=dashed-canvas.js --js=dygraph-tickers.js --js=dygraph-canvas.js --js=dygraph.js --js=dygraph-gviz.js --js=dygraph-options-reference.js --js=dygraph-options.js --js=dygraph-layout.js --js=dygraph-interaction-model.js --js=dygraph-plugin-base.js --js=dygraph-exports.js --js_output_file=/tmp/out.js --compilation_level ADVANCED_OPTIMIZATIONS --warning_level VERBOSE --externs dygraph-externs.js --externs gviz-api.js --output_wrapper='(function() {%output%})();' +java -jar ../../closure-compiler-read-only/build/compiler.jar --js ../../closure-library-read-only/closure/goog/base.js --js=dygraph-constants.js --js=dygraph-utils.js --js=dashed-canvas.js --js=dygraph-tickers.js --js=dygraph-canvas.js --js=dygraph.js --js=dygraph-gviz.js --js=dygraph-options-reference.js --js=dygraph-options.js --js=dygraph-layout.js --js=dygraph-interaction-model.js --js=dygraph-plugin-base.js --js=dygraph-exports.js --js_output_file=/tmp/out.js --compilation_level ADVANCED_OPTIMIZATIONS --warning_level VERBOSE --externs dygraph-externs.js --externs gviz-api.js --output_wrapper='(function() {%output%})();' As each file is closurized, it can be added as a "--js" parameter. diff --git a/dygraph-dev.js b/dygraph-dev.js index 6adfa51..e05fd75 100644 --- a/dygraph-dev.js +++ b/dygraph-dev.js @@ -18,6 +18,7 @@ var source_files = [ "stacktrace.js", "dashed-canvas.js", + "dygraph-constants.js", "dygraph-options.js", "dygraph-layout.js", "dygraph-canvas.js", diff --git a/dygraph-externs.js b/dygraph-externs.js index e2153ae..85a535d 100644 --- a/dygraph-externs.js +++ b/dygraph-externs.js @@ -140,3 +140,23 @@ var DygraphPlotterType; * }} */ var DygraphInteractionContext; + + +/** + * @constructor + */ +var DygraphPluginType; + +/** + * @param {!Dygraph} dygraph + * TODO(danvk): be more specific than Object + * @return {Object.} Mapping from event -> callback. + */ +DygraphPluginType.prototype.activate = function(dygraph) {}; + +/** + * @return {string} + */ +DygraphPluginType.prototype.toString = function() {}; + +DygraphPluginType.prototype.destroy = function() {}; diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 9340d78..cfe76cd 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -60,7 +60,7 @@ (function() { -/*jshint globalstrict:true, sub:true */ +/*jshint sub:true */ /*global Dygraph:false */ "use strict"; @@ -224,48 +224,23 @@ Dygraph.dateTicker = function(a, b, pixels, opts, dygraph, vals) { } }; -// Time granularity enumeration -// TODO(danvk): make this an @enum -var SECONDLY = 0; -var TWO_SECONDLY = 1; -var FIVE_SECONDLY = 2; -var TEN_SECONDLY = 3; -var THIRTY_SECONDLY = 4; -var MINUTELY = 5; -var TWO_MINUTELY = 6; -var FIVE_MINUTELY = 7; -var TEN_MINUTELY = 8; -var THIRTY_MINUTELY = 9; -var HOURLY = 10; -var TWO_HOURLY = 11; -var SIX_HOURLY = 12; -var DAILY = 13; -var WEEKLY = 14; -var MONTHLY = 15; -var QUARTERLY = 16; -var BIANNUAL = 17; -var ANNUAL = 18; -var DECADAL = 19; -var CENTENNIAL = 20; -var NUM_GRANULARITIES = 21; - /** @type {Array.} */ var SHORT_SPACINGS = []; -SHORT_SPACINGS[SECONDLY] = 1000 * 1; -SHORT_SPACINGS[TWO_SECONDLY] = 1000 * 2; -SHORT_SPACINGS[FIVE_SECONDLY] = 1000 * 5; -SHORT_SPACINGS[TEN_SECONDLY] = 1000 * 10; -SHORT_SPACINGS[THIRTY_SECONDLY] = 1000 * 30; -SHORT_SPACINGS[MINUTELY] = 1000 * 60; -SHORT_SPACINGS[TWO_MINUTELY] = 1000 * 60 * 2; -SHORT_SPACINGS[FIVE_MINUTELY] = 1000 * 60 * 5; -SHORT_SPACINGS[TEN_MINUTELY] = 1000 * 60 * 10; -SHORT_SPACINGS[THIRTY_MINUTELY] = 1000 * 60 * 30; -SHORT_SPACINGS[HOURLY] = 1000 * 3600; -SHORT_SPACINGS[TWO_HOURLY] = 1000 * 3600 * 2; -SHORT_SPACINGS[SIX_HOURLY] = 1000 * 3600 * 6; -SHORT_SPACINGS[DAILY] = 1000 * 86400; -SHORT_SPACINGS[WEEKLY] = 1000 * 604800; +SHORT_SPACINGS[DygraphGranularities.SECONDLY] = 1000 * 1; +SHORT_SPACINGS[DygraphGranularities.TWO_SECONDLY] = 1000 * 2; +SHORT_SPACINGS[DygraphGranularities.FIVE_SECONDLY] = 1000 * 5; +SHORT_SPACINGS[DygraphGranularities.TEN_SECONDLY] = 1000 * 10; +SHORT_SPACINGS[DygraphGranularities.THIRTY_SECONDLY] = 1000 * 30; +SHORT_SPACINGS[DygraphGranularities.MINUTELY] = 1000 * 60; +SHORT_SPACINGS[DygraphGranularities.TWO_MINUTELY] = 1000 * 60 * 2; +SHORT_SPACINGS[DygraphGranularities.FIVE_MINUTELY] = 1000 * 60 * 5; +SHORT_SPACINGS[DygraphGranularities.TEN_MINUTELY] = 1000 * 60 * 10; +SHORT_SPACINGS[DygraphGranularities.THIRTY_MINUTELY] = 1000 * 60 * 30; +SHORT_SPACINGS[DygraphGranularities.HOURLY] = 1000 * 3600; +SHORT_SPACINGS[DygraphGranularities.TWO_HOURLY] = 1000 * 3600 * 2; +SHORT_SPACINGS[DygraphGranularities.SIX_HOURLY] = 1000 * 3600 * 6; +SHORT_SPACINGS[DygraphGranularities.DAILY] = 1000 * 86400; +SHORT_SPACINGS[DygraphGranularities.WEEKLY] = 1000 * 604800; /** * A collection of objects specifying where it is acceptable to place tick @@ -275,27 +250,27 @@ SHORT_SPACINGS[WEEKLY] = 1000 * 604800; * @type {Array.} */ var LONG_TICK_PLACEMENTS = []; -LONG_TICK_PLACEMENTS[MONTHLY] = { +LONG_TICK_PLACEMENTS[DygraphGranularities.MONTHLY] = { months : [0,1,2,3,4,5,6,7,8,9,10,11], year_mod : 1 }; -LONG_TICK_PLACEMENTS[QUARTERLY] = { +LONG_TICK_PLACEMENTS[DygraphGranularities.QUARTERLY] = { months: [0,3,6,9], year_mod: 1 }; -LONG_TICK_PLACEMENTS[BIANNUAL] = { +LONG_TICK_PLACEMENTS[DygraphGranularities.BIANNUAL] = { months: [0,6], year_mod: 1 }; -LONG_TICK_PLACEMENTS[ANNUAL] = { +LONG_TICK_PLACEMENTS[DygraphGranularities.ANNUAL] = { months: [0], year_mod: 1 }; -LONG_TICK_PLACEMENTS[DECADAL] = { +LONG_TICK_PLACEMENTS[DygraphGranularities.DECADAL] = { months: [0], year_mod: 10 }; -LONG_TICK_PLACEMENTS[CENTENNIAL] = { +LONG_TICK_PLACEMENTS[DygraphGranularities.CENTENNIAL] = { months: [0], year_mod: 100 }; @@ -313,7 +288,7 @@ LONG_TICK_PLACEMENTS[CENTENNIAL] = { */ Dygraph.pickDateTickGranularity = function(a, b, pixels, opts) { var pixels_per_tick = /** @type{number} */(opts('pixelsPerLabel')); - for (var i = 0; i < NUM_GRANULARITIES; i++) { + for (var i = 0; i < DygraphGranularities.NUM_GRANULARITIES; i++) { var num_ticks = Dygraph.numDateTicks(a, b, i); if (pixels / num_ticks >= pixels_per_tick) { return i; @@ -329,7 +304,7 @@ Dygraph.pickDateTickGranularity = function(a, b, pixels, opts) { * @return {number} Number of ticks that would result. */ Dygraph.numDateTicks = function(start_time, end_time, granularity) { - if (granularity < MONTHLY) { + if (granularity < DygraphGranularities.MONTHLY) { // Generate one tick mark for every fixed interval of time. var spacing = SHORT_SPACINGS[granularity]; return Math.floor(0.5 + 1.0 * (end_time - start_time) / spacing); @@ -356,7 +331,7 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { var ticks = []; var t; - if (granularity < MONTHLY) { + if (granularity < DygraphGranularities.MONTHLY) { // Generate one tick mark for every fixed interval of time. var spacing = SHORT_SPACINGS[granularity]; @@ -399,7 +374,7 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { // savings transitions to get consistent ticks. For finer-grained ticks, // it's essential to show the DST transition in all its messiness. var start_offset_min = new Date(start_time).getTimezoneOffset(); - var check_dst = (spacing >= SHORT_SPACINGS[TWO_HOURLY]); + var check_dst = (spacing >= SHORT_SPACINGS[DygraphGranularities.TWO_HOURLY]); for (t = start_time; t <= end_time; t += spacing) { d = new Date(t); @@ -436,7 +411,7 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { var months; var year_mod = 1; // e.g. to only print one point every 10 years. - if (granularity < NUM_GRANULARITIES) { + if (granularity < DygraphGranularities.NUM_GRANULARITIES) { months = LONG_TICK_PLACEMENTS[granularity].months; year_mod = LONG_TICK_PLACEMENTS[granularity].year_mod; } else { diff --git a/dygraph.js b/dygraph.js index 66a8bb3..1bfe873 100644 --- a/dygraph.js +++ b/dygraph.js @@ -94,7 +94,7 @@ function Dygraph(div, file, opt_attrs) { attrs = Dygraph.mapLegacyOptions_(attrs); if (typeof(div) == 'string') { - div = document.getElementById(div); + div = /**@type{!HTMLDivElement}*/(document.getElementById(div)); } if (!div) { @@ -115,7 +115,7 @@ function Dygraph(div, file, opt_attrs) { this.is_initial_draw_ = true; - /** @type {number} */ + /** @type {number|undefined} */ this.lastx_ = undefined; /** @type {!Array.} */ @@ -204,6 +204,7 @@ function Dygraph(div, file, opt_attrs) { var plugins = Dygraph.PLUGINS.concat(this.getOption('plugins')); for (var i = 0; i < plugins.length; i++) { var Plugin = plugins[i]; + /** @type{!DygraphPluginType} */ var pluginInstance = new Plugin(); var pluginDict = { plugin: pluginInstance, @@ -273,15 +274,14 @@ 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. /** - * @private * Return a string version of a number. This respects the digitsAfterDecimal * and maxNumberWidth options. * @param {number} x The number to be formatted * @param {function(string)} opts An options view - * @param {string} name The name of the point's data series * @param {!Dygraph} g The dygraph object + * @private */ -var numberValueFormatter_ = function(x, opts, pt, g) { +var numberValueFormatter_ = function(x, opts, g) { var sigFigs = opts('sigFigs'); if (sigFigs !== null) { @@ -313,8 +313,7 @@ var numberValueFormatter_ = function(x, opts, pt, g) { if (kmb) { k = 1000; k_labels = KMB_LABELS; - } - if (kmg2) { + } else { if (kmb) Dygraph.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); k = 1024; k_labels = KMG2_BIG_LABELS; @@ -370,15 +369,15 @@ var SHORT_MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', * @private */ var dateAxisFormatter_ = function(date, granularity) { - if (granularity >= Dygraph.DECADAL) { + if (granularity >= DygraphGranularities.DECADAL) { // e.g. '2013' (%Y) return '' + date.getFullYear(); - } else if (granularity >= Dygraph.MONTHLY) { + } else if (granularity >= DygraphGranularities.MONTHLY) { // e.g. 'Jan 13' (%b %y) 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) { + if (frac === 0 || granularity >= DygraphGranularities.DAILY) { // e.g. '21Jan' (%d%b) var nd = new Date(date.getTime() + 3600*1000); return Dygraph.zeropad(nd.getDate()) + SHORT_MONTH_NAMES[nd.getMonth()]; diff --git a/generate-combined.sh b/generate-combined.sh index b1f0c79..f1d146d 100755 --- a/generate-combined.sh +++ b/generate-combined.sh @@ -6,6 +6,7 @@ GetSources () { # and the one in jsTestDriver.conf. Order matters, except for the plugins. for F in \ dashed-canvas.js \ + dygraph-constants.js \ dygraph-options.js \ dygraph-layout.js \ dygraph-canvas.js \