(function() {
-/*jshint globalstrict:true, sub:true */
+/*jshint sub:true */
/*global Dygraph:false */
"use strict";
}
};
-// 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.<number>} */
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
* @type {Array.<Object>}
*/
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
};
*/
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;
* @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);
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];
// 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);
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 {
attrs = Dygraph.mapLegacyOptions_(attrs);
if (typeof(div) == 'string') {
- div = document.getElementById(div);
+ div = /**@type{!HTMLDivElement}*/(document.getElementById(div));
}
if (!div) {
this.is_initial_draw_ = true;
- /** @type {number} */
+ /** @type {number|undefined} */
this.lastx_ = undefined;
/** @type {!Array.<DygraphAnnotationType>} */
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,
// 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) {
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;
* @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()];