*/
+var Dygraph = (function() {
+
/*jshint globalstrict: true */
/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false */
"use strict";
// 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);
};
// 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.
/**
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);
/**
* @type {!Array.<string>}
- * @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
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());
}
// 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.
];
// 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
// 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;
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,
Dygraph.prototype.attr_ = function(name, seriesName) {
// <REMOVE_FOR_COMBINED>
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;
}
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;
}
};
* 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.
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),
* @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 = [];
that.dateWindow_ = windows[step];
}
that.drawGraph_();
- }, steps, Dygraph.ANIMATION_DURATION / steps, callback);
+ }, steps, ANIMATION_DURATION / steps, callback);
};
/**
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;
};
// 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),
} 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),
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));
}
}
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
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;
}
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]; });
}
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++) {
} 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;
}
}
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();
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;
}
}
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");
}
}
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;
}
}
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;
req.send(null);
}
} else {
- this.error("Unknown data format: " + (typeof data));
+ Dygraph.error("Unknown data format: " + (typeof data));
}
};
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;
}
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_();
*/
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;
}
};
/**
- * @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; " +
} 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;
+
+})();