From: Dan Vanderkam Date: Sun, 21 Jul 2013 12:54:16 +0000 (-0400) Subject: Some cleanup of symbols that should not be exported X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=dc5bf373eb235376729f9432a352d3d48b429941;p=dygraphs.git Some cleanup of symbols that should not be exported --- diff --git a/chopping-block.txt b/chopping-block.txt index b43d2b4..12162fe 100644 --- a/chopping-block.txt +++ b/chopping-block.txt @@ -16,6 +16,7 @@ Things to do to make dygraph-combine.js smaller: x (3942) Remove rgbcolor.js x (1983) Remove stacktrace.js from dygraph-combined.js x (1431) Remove srtftime, which is only minimally used. +- (????) Move symbols which shouldn't be exported out of Dygraph namespace. To measure size: $ ./generate-combined.sh cat_minified | wc -c @@ -32,6 +33,7 @@ $ make test-combined 122185 consolidate findPos{X,Y} 120905 move custom circles into extras/circles.js 115027 switch to uglifyjs + 113418 don't export ticker enum symbols. TODO: diff --git a/dygraph-tickers.js b/dygraph-tickers.js index f4778b1..31b485f 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -58,6 +58,8 @@ * middle of the years. */ +(function() { + /*jshint globalstrict:true, sub:true */ /*global Dygraph:false */ "use strict"; @@ -98,20 +100,20 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { // TODO(danvk): factor this log-scale block out into a separate function. if (opts("logscale")) { nTicks = Math.floor(pixels / pixels_per_tick); - var minIdx = Dygraph.binarySearch(a, Dygraph.PREFERRED_LOG_TICK_VALUES, 1); - var maxIdx = Dygraph.binarySearch(b, Dygraph.PREFERRED_LOG_TICK_VALUES, -1); + var minIdx = Dygraph.binarySearch(a, PREFERRED_LOG_TICK_VALUES, 1); + var maxIdx = Dygraph.binarySearch(b, PREFERRED_LOG_TICK_VALUES, -1); if (minIdx == -1) { minIdx = 0; } if (maxIdx == -1) { - maxIdx = Dygraph.PREFERRED_LOG_TICK_VALUES.length - 1; + maxIdx = PREFERRED_LOG_TICK_VALUES.length - 1; } // Count the number of tick values would appear, if we can get at least // nTicks / 4 accept them. var lastDisplayed = null; if (maxIdx - minIdx >= nTicks / 4) { for (var idx = maxIdx; idx >= minIdx; idx--) { - var tickValue = Dygraph.PREFERRED_LOG_TICK_VALUES[idx]; + var tickValue = PREFERRED_LOG_TICK_VALUES[idx]; var pixel_coord = Math.log(tickValue / a) / Math.log(b / a) * pixels; var tick = { v: tickValue }; if (lastDisplayed === null) { @@ -218,46 +220,46 @@ Dygraph.dateTicker = function(a, b, pixels, opts, dygraph, vals) { // Time granularity enumeration // TODO(danvk): make this an @enum -Dygraph.SECONDLY = 0; -Dygraph.TWO_SECONDLY = 1; -Dygraph.FIVE_SECONDLY = 2; -Dygraph.TEN_SECONDLY = 3; -Dygraph.THIRTY_SECONDLY = 4; -Dygraph.MINUTELY = 5; -Dygraph.TWO_MINUTELY = 6; -Dygraph.FIVE_MINUTELY = 7; -Dygraph.TEN_MINUTELY = 8; -Dygraph.THIRTY_MINUTELY = 9; -Dygraph.HOURLY = 10; -Dygraph.TWO_HOURLY = 11; -Dygraph.SIX_HOURLY = 12; -Dygraph.DAILY = 13; -Dygraph.WEEKLY = 14; -Dygraph.MONTHLY = 15; -Dygraph.QUARTERLY = 16; -Dygraph.BIANNUAL = 17; -Dygraph.ANNUAL = 18; -Dygraph.DECADAL = 19; -Dygraph.CENTENNIAL = 20; -Dygraph.NUM_GRANULARITIES = 21; +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.} */ -Dygraph.SHORT_SPACINGS = []; -Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY] = 1000 * 1; -Dygraph.SHORT_SPACINGS[Dygraph.TWO_SECONDLY] = 1000 * 2; -Dygraph.SHORT_SPACINGS[Dygraph.FIVE_SECONDLY] = 1000 * 5; -Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY] = 1000 * 10; -Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY] = 1000 * 30; -Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY] = 1000 * 60; -Dygraph.SHORT_SPACINGS[Dygraph.TWO_MINUTELY] = 1000 * 60 * 2; -Dygraph.SHORT_SPACINGS[Dygraph.FIVE_MINUTELY] = 1000 * 60 * 5; -Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY] = 1000 * 60 * 10; -Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY] = 1000 * 60 * 30; -Dygraph.SHORT_SPACINGS[Dygraph.HOURLY] = 1000 * 3600; -Dygraph.SHORT_SPACINGS[Dygraph.TWO_HOURLY] = 1000 * 3600 * 2; -Dygraph.SHORT_SPACINGS[Dygraph.SIX_HOURLY] = 1000 * 3600 * 6; -Dygraph.SHORT_SPACINGS[Dygraph.DAILY] = 1000 * 86400; -Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY] = 1000 * 604800; +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; /** * A collection of objects specifying where it is acceptable to place tick @@ -266,28 +268,28 @@ Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY] = 1000 * 604800; * 'year_mod' ticks are placed when year % year_mod = 0. * @type {Array.} */ -Dygraph.LONG_TICK_PLACEMENTS = []; -Dygraph.LONG_TICK_PLACEMENTS[Dygraph.MONTHLY] = { +var LONG_TICK_PLACEMENTS = []; +LONG_TICK_PLACEMENTS[MONTHLY] = { months : [0,1,2,3,4,5,6,7,8,9,10,11], year_mod : 1 }; -Dygraph.LONG_TICK_PLACEMENTS[Dygraph.QUARTERLY] = { +LONG_TICK_PLACEMENTS[QUARTERLY] = { months: [0,3,6,9], year_mod: 1 }; -Dygraph.LONG_TICK_PLACEMENTS[Dygraph.BIANNUAL] = { +LONG_TICK_PLACEMENTS[BIANNUAL] = { months: [0,6], year_mod: 1 }; -Dygraph.LONG_TICK_PLACEMENTS[Dygraph.ANNUAL] = { +LONG_TICK_PLACEMENTS[ANNUAL] = { months: [0], year_mod: 1 }; -Dygraph.LONG_TICK_PLACEMENTS[Dygraph.DECADAL] = { +LONG_TICK_PLACEMENTS[DECADAL] = { months: [0], year_mod: 10 }; -Dygraph.LONG_TICK_PLACEMENTS[Dygraph.CENTENNIAL] = { +LONG_TICK_PLACEMENTS[CENTENNIAL] = { months: [0], year_mod: 100 }; @@ -299,7 +301,7 @@ Dygraph.LONG_TICK_PLACEMENTS[Dygraph.CENTENNIAL] = { * NOTE: this assumes that Dygraph.LOG_SCALE = 10. * @type {Array.} */ -Dygraph.PREFERRED_LOG_TICK_VALUES = function() { +var PREFERRED_LOG_TICK_VALUES = function() { var vals = []; for (var power = -39; power <= 39; power++) { var range = Math.pow(10, power); @@ -324,7 +326,7 @@ Dygraph.PREFERRED_LOG_TICK_VALUES = function() { */ Dygraph.pickDateTickGranularity = function(a, b, pixels, opts) { var pixels_per_tick = /** @type{number} */(opts('pixelsPerLabel')); - for (var i = 0; i < Dygraph.NUM_GRANULARITIES; i++) { + for (var i = 0; i < NUM_GRANULARITIES; i++) { var num_ticks = Dygraph.numDateTicks(a, b, i); if (pixels / num_ticks >= pixels_per_tick) { return i; @@ -340,12 +342,12 @@ 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 < Dygraph.MONTHLY) { + if (granularity < MONTHLY) { // Generate one tick mark for every fixed interval of time. - var spacing = Dygraph.SHORT_SPACINGS[granularity]; + var spacing = SHORT_SPACINGS[granularity]; return Math.floor(0.5 + 1.0 * (end_time - start_time) / spacing); } else { - var tickPlacement = Dygraph.LONG_TICK_PLACEMENTS[granularity]; + var tickPlacement = LONG_TICK_PLACEMENTS[granularity]; var msInYear = 365.2524 * 24 * 3600 * 1000; var num_years = 1.0 * (end_time - start_time) / msInYear; @@ -367,9 +369,9 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { var ticks = []; var t; - if (granularity < Dygraph.MONTHLY) { + if (granularity < MONTHLY) { // Generate one tick mark for every fixed interval of time. - var spacing = Dygraph.SHORT_SPACINGS[granularity]; + var spacing = SHORT_SPACINGS[granularity]; // Find a time less than start_time which occurs on a "nice" time boundary // for this granularity. @@ -410,7 +412,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 >= Dygraph.SHORT_SPACINGS[Dygraph.TWO_HOURLY]); + var check_dst = (spacing >= SHORT_SPACINGS[TWO_HOURLY]); for (t = start_time; t <= end_time; t += spacing) { d = new Date(t); @@ -447,9 +449,9 @@ 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 < Dygraph.NUM_GRANULARITIES) { - months = Dygraph.LONG_TICK_PLACEMENTS[granularity].months; - year_mod = Dygraph.LONG_TICK_PLACEMENTS[granularity].year_mod; + if (granularity < NUM_GRANULARITIES) { + months = LONG_TICK_PLACEMENTS[granularity].months; + year_mod = LONG_TICK_PLACEMENTS[granularity].year_mod; } else { Dygraph.warn("Span of dates is too long"); } @@ -485,3 +487,5 @@ if (Dygraph && Dygraph.DEFAULT_ATTRS['axes']['y']['ticker'] = Dygraph.numericTicks; Dygraph.DEFAULT_ATTRS['axes']['y2']['ticker'] = Dygraph.numericTicks; } + +})(); diff --git a/tests/exported-symbols.html b/tests/exported-symbols.html index 8365905..8b9e32d 100644 --- a/tests/exported-symbols.html +++ b/tests/exported-symbols.html @@ -8,19 +8,26 @@ -

This page lists the set of symbols that dygraphs exports.

+

dygraphs exports these symbols into the global namespace:

+

It exports these symbols inside each of those symbols:

+
    +
+ + +