this.colors = this.dygraph_.colorsMap_;
// Determine which series have specialized plotters.
- var plotter_attr = /** @type{!Array.<!Dygraph.PlotterType>|!Dygraph.PlotterType}*/(this.dygraph_.getOption("plotter"));
+ var plotter_attr = /** @type{!Array.<!DygraphPlotterType>|!DygraphPlotterType}*/(this.dygraph_.getOption("plotter"));
- /** @type{!Array.<!Dygraph.PlotterType>} */
+ /** @type{!Array.<!DygraphPlotterType>} */
var plotters;
if (!Dygraph.isArrayLike(plotters)) {
plotters = [plotters];
} else {
- plotters = /** @type {!Array.<!Dygraph.PlotterType>} */(plotter_attr);
+ plotters = /** @type {!Array.<!DygraphPlotterType>} */(plotter_attr);
}
- /** @type {Object.<!Dygraph.PlotterType>} */
+ /** @type {Object.<!DygraphPlotterType>} */
var setPlotters = {}; // series name -> plotter fn.
for (i = 0; i < setNames.length; i++) {
setName = setNames[i];
var setPlotter = this.dygraph_.getOption("plotter", setName);
if (setPlotter == plotter_attr) continue; // not specialized.
- setPlotters[setName] = /** @type {!Dygraph.PlotterType} */(setPlotter);
+ setPlotters[setName] = /** @type {!DygraphPlotterType} */(setPlotter);
}
for (i = 0; i < plotters.length; i++) {
/**
* @typedef {{
- * idx: number,
- * name: string,
- * x: ?number,
- * xval: ?number,
- * y_bottom: ?number,
- * y: ?number,
- * y_stacked: ?number,
- * y_top: ?number,
- * yval_minus: ?number,
- * yval: ?number,
- * yval_plus: ?number,
- * yval_stacked
- * }}
- */
-Dygraph.PointType;
-
-// /**
-// * @constructor
-// */
-// function DygraphLayout() {}
-//
-// /**
-// * @type {Array.<Array.<Dygraph.PointType>>}
-// */
-// DygraphLayout.prototype.points;
-
-// TODO: DygraphOptions should not reach inside Dygraph private data like this.
-/** @type {Object} */
-Dygraph.prototype.attrs_;
-/** @type {Object} */
-Dygraph.prototype.user_attrs_;
-/** @type {Array.<Object>} */
-Dygraph.prototype.selPoints_; // TODO(danvk): type actually has .canvasx, ...
-
-/**
- * @param {string} name the name of the option.
- */
-Dygraph.prototype.attr_ = function(name) {};
-
-/**
- * @return {{width: number, height: number}} object.
- */
-Dygraph.prototype.size = function() {};
-
-/**
- * @return {Dygraph.Rect}
- */
-Dygraph.prototype.getArea = function() {};
-
-/**
- * @return {!Array.<number>}
- */
-Dygraph.prototype.xAxisExtremes = function() {};
-
-/**
- * @param {?number} x The data x-value.
- * @return {?number} The DOM coordinate, or null if the input is null.
- */
-Dygraph.prototype.toDomXCoord = function(x) {};
-
-/**
- * @param {?number} y The data y-value.
- * @param {number=} opt_axis The axis number (0=primary).
- * @return {?number} The DOM coordinate, or null if the input is null.
- */
-Dygraph.prototype.toDomYCoord = function(y, opt_axis) {};
-
-/**
- * @param {?number} x The DOM x-coordinate.
- * @return {?number} The data x-coordinate, or null if the input is null.
- */
-Dygraph.prototype.toDataXCoord = function(x) {};
-
-/**
- * @param {?number} y The DOM y-coordinate.
- * @param {number=} opt_axis The axis number (0=primary).
- * @return {?number} The data y-value, or null if the input is null.
- */
-Dygraph.prototype.toDataYCoord = function(y, opt_axis) {};
-
-/**
- * @type {DygraphLayout}
- */
-Dygraph.prototype.layout_;
-
-/**
- * @type {!HTMLDivElement}
- */
-Dygraph.prototype.graphDiv;
-
-/**
- * @type {!DygraphOptions}
- */
-Dygraph.prototype.attributes_;
-
-/** @type {function(): string} */
-Dygraph.prototype.getHighlightSeries;
-
-/**
- * @param {string} name Event name.
- * @param {Object} extra_props Event-specific properties.
- * @return {boolean} Whether to perform the default action.
- */
-Dygraph.prototype.cascadeEvents_ = function(name, extra_props) {};
-
-/**
- * @type {Array.<{
- * elem: !Element,
- * type: string,
- * fn: function(?Event):(boolean|undefined)
- * }>}
- */
-Dygraph.prototype.registeredEvents_;
-
-/**
- * @type {CanvasRenderingContext2D}
- */
-Dygraph.prototype.canvas_ctx_;
-
-/**
- * @type {CanvasRenderingContext2D}
- */
-Dygraph.prototype.hidden_ctx_;
-
-/**
- * @type {Object.<string>}
- */
-Dygraph.prototype.colorsMap_;
-
-/**
- * TODO(danvk): be more specific
- * @type {Array.<Object>}
- */
-Dygraph.prototype.axes_;
-
-/**
- * @type {number}
- */
-Dygraph.prototype.lastx_;
-
-/**
- * @return {!Array.<number>} two element [left, right] array.
- */
-Dygraph.prototype.xAxisRange = function() {};
-
-/**
- * @param {number=} opt_axis Optional axis (0=primary).
- * @return {Array.<number>} A two-element array: [bottom, top].
- */
-Dygraph.prototype.yAxisRange = function(opt_axis) {};
-
-/**
- * @return {!Array.<!Array.<number>>}
- */
-Dygraph.prototype.yAxisRanges = function() {};
-
-/**
- * @param {string} setName Set name.
- * @return {Object} axis properties for the series.
- */
-Dygraph.prototype.axisPropertiesForSeries = function(setName) {};
-
-/**
- * @param {number} y The data y-coordinate.
- * @param {number} axis The axis number on which the data coordinate lives.
- * @return {number} A fraction in [0, 1] where 0 = the top edge.
- */
-Dygraph.prototype.toPercentYCoord = function(y, axis) {};
-
-/**
- * @param {string} name The name of the option (e.g. 'strokeWidth')
- * @param {string=} opt_seriesName Series name to get per-series values.
- * @return {*} The value of the option.
- */
-Dygraph.prototype.getOption = function(name, opt_seriesName) {};
-
-/**
- * @return {?Array.<string>} The names of each series (including the x-axis),
- * or null if they haven't been defined yet.
- */
-Dygraph.prototype.getLabels = function() {};
-
-/**
- * @return {Array.<string>} The list of colors.
- */
-Dygraph.prototype.getColors = function() {};
-
-/**
- */
-Dygraph.prototype.drawGraph_ = function() {};
-
-/**
- * @param {number} direction
- * @param {number} startX
- * @param {number} endX
- * @param {number} startY
- * @param {number} endY
- * @param {number} prevDirection
- * @param {number} prevEndX
- * @param {number} prevEndY
- * @private
- */
-Dygraph.prototype.drawZoomRect_ = function(direction, startX, endX, startY,
- endY, prevDirection, prevEndX,
- prevEndY) {};
-
-
-Dygraph.prototype.clearZoomRect_ = function() {};
-Dygraph.prototype.resetZoom = function() {};
-
-/**
- * @param {number} lowX
- * @param {number} highX
- */
-Dygraph.prototype.doZoomX_ = function(lowX, highX) {};
-
-/**
- * @param {number} lowY
- * @param {number} highY
- */
-Dygraph.prototype.doZoomY_ = function(lowY, highY) {};
-
-/** @type {number} */
-Dygraph.HORIZONTAL;
-/** @type {number} */
-Dygraph.VERTICAL;
-
-/** @type {{axes: Object}} */
-Dygraph.DEFAULT_ATTRS;
-
-/**
- * @typedef {{
* xval: (number|undefined),
* x: string,
* series: string,
* text: (string|undefined)
* }}
*/
-Dygraph.AnnotationType;
+var DygraphAnnotationType;
/**
* @typedef {Array.<{
* label_v:(string|undefined)
* }>}
*/
-Dygraph.TickList;
+var DygraphTickList;
/**
* @typedef {(function(
* function(string):*,
* Dygraph=,
* Array.<number>=
- * ): Dygraph.TickList)}
+ * ): DygraphTickList)}
*/
-Dygraph.Ticker;
+var DygraphTicker;
/**
* @typedef {{
* h: number
* }}
*/
-Dygraph.Rect;
+var DygraphRect;
/**
* @typedef {{
* computedValueRange: Array.<number>
* }}
*/
-Dygraph.AxisType;
+var DygraphAxisType;
/**
* TODO(danvk): be more specific than "Object".
* @typedef {function(Object)}
*/
-Dygraph.PlotterType;
+var DygraphPlotterType;
/**
* function(!Event, !Dygraph, !Dygraph.InteractionContext)
* }}
*/
-Dygraph.InteractionContext;
+var DygraphsInteractionContext;
*
* @param {!Event} event the event object which led to the startPan call.
* @param {!Dygraph} g The dygraph on which to act.
- * @param {!Dygraph.InteractionContext} context The dragging context object
+ * @param {!DygraphInteractionContext} context The dragging context object
* (with dragStartX/dragStartY/etc. properties). This function modifies the
* context.
*/
*
* @param {!Event} event the event object which led to the movePan call.
* @param {!Dygraph} g The dygraph on which to act.
- * @param {!Dygraph.InteractionContext} context The dragging context object
+ * @param {!DygraphInteractionContext} context The dragging context object
* (with dragStartX/dragStartY/etc. properties). This function modifies the
* context.
*/
*
* @param {!Event} event the event object which led to the endPan call.
* @param {!Dygraph} g The dygraph on which to act.
- * @param {!Dygraph.InteractionContext} context The dragging context object
+ * @param {!DygraphInteractionContext} context The dragging context object
* (with dragStartX/dragStartY/etc. properties). This function modifies the
* context.
*/
*
* @param {!Event} event the event object which led to the startZoom call.
* @param {!Dygraph} g The dygraph on which to act.
- * @param {!Dygraph.InteractionContext} context The dragging context object
+ * @param {!DygraphInteractionContext} context The dragging context object
* (with dragStartX/dragStartY/etc. properties). This function modifies the
* context.
*/
*
* @param {!Event} event the event object which led to the moveZoom call.
* @param {!Dygraph} g The dygraph on which to act.
- * @param {!Dygraph.InteractionContext} context The dragging context object
+ * @param {!DygraphInteractionContext} context The dragging context object
* (with dragStartX/dragStartY/etc. properties). This function modifies the
* context.
*/
/**
* @param {!Dygraph} g
* @param {!Event} event
- * @param {!Dygraph.InteractionContext} context
+ * @param {!DygraphInteractionContext} context
*/
Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) {
var clickCallback = g.attr_('clickCallback');
*
* @param {!Event} event the event object which led to the endZoom call.
* @param {!Dygraph} g The dygraph on which to end the zoom.
- * @param {!Dygraph.InteractionContext} context The dragging context object
+ * @param {!DygraphInteractionContext} context The dragging context object
* (with dragStartX/dragStartY/etc. properties). This function modifies the
* context.
*/
/** @type {Array.<!Dygraph.AnnotationType>} */
this.annotations = [];
- /** @type {Array.<Dygraph.AxisType>} */
+ /** @type {Array.<DygraphAxisType>} */
this.yAxes_ = null;
// TODO(danvk): it's odd that xTicks_ and yTicks_ are inputs, but xticks and
/** @type {Dygraph.TickList} */
this.yTicks_ = null;
- /** @type {?Dygraph.Rect} */
+ /** @type {?DygraphRect} */
this.area_ = null;
// TODO(danvk): these fields should be objects, not arrays of arrays, which
* Returns the box which the chart should be drawn in. This is the canvas's
* box, less space needed for the axis and chart labels.
*
- * @return {?Dygraph.Rect}
+ * @return {?DygraphRect}
*/
DygraphLayout.prototype.getPlotArea = function() {
return this.area_;
};
/**
- * @param {Array.<Dygraph.AxisType>} yAxes The y-axes.
+ * @param {Array.<DygraphAxisType>} yAxes The y-axes.
*/
DygraphLayout.prototype.setYAxes = function (yAxes) {
this.yAxes_ = yAxes;
/*global Dygraph:false */
"use strict";
-/** @type {Dygraph.Ticker} */
+/** @type {DygraphTicker} */
Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) {
var nonLogscaleOpts = function(opt) {
if (opt === 'logscale') return false;
})();
-/** @type {Dygraph.Ticker} */
+/** @type {DygraphTicker} */
Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) {
var pixels_per_tick = /** @type{number} */(opts('pixelsPerLabel'));
var ticks = [];
};
-/** @type {Dygraph.Ticker} */
+/** @type {DygraphTicker} */
Dygraph.dateTicker = function(a, b, pixels, opts, dygraph, vals) {
var chosen = Dygraph.pickDateTickGranularity(a, b, pixels, opts);
* @param {number} granularity (one of the granularities enumerated above)
* @param {function(string):*} opts Function mapping from option name -> value.
* @param {Dygraph=} dg
- * @return {!Dygraph.TickList}
+ * @return {!DygraphTickList}
*/
Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) {
var formatter = /** @type{AxisLabelFormatter} */(
this.is_initial_draw_ = true;
- /** @type {!Array.<Dygraph.AnnotationType>} */
+ /** @type {number} */
+ this.lastx_ = undefined;
+
+ /** @type {!Array.<DygraphAnnotationType>} */
this.annotations_ = [];
// Zoomed indicators - These indicate when the graph has been zoomed and on what axis.
this.setIndexByName_ = {};
this.datasetIndex_ = [];
+ /**
+ * @type {Array.<{
+ * elem: !Element,
+ * type: string,
+ * fn: function(?Event):(boolean|undefined)
+ * }>}
+ */
this.registeredEvents_ = [];
this.eventListeners_ = {};
+ /** @type {!DygraphOptions} */
this.attributes_ = new DygraphOptions(this);
+ /** @type {Array.<Dygraph.PointType>} */
+ this.selPoints_ = [];
+
// Create the containing DIV and other interactive elements
this.createInterface_();
Dygraph.NAME = "Dygraph";
Dygraph.VERSION = "1.2";
Dygraph.__repr__ = function() {
- return "[" + this.NAME + " " + this.VERSION + "]";
+ return "[" + Dygraph.NAME + " " + Dygraph.VERSION + "]";
};
/**
* Returns information about the Dygraph class.
*/
Dygraph.toString = function() {
- return this.__repr__();
+ return Dygraph.__repr__();
};
// Various default values
// Default attribute values.
+/** @type {{axes: Object}} */
Dygraph.DEFAULT_ATTRS = {
highlightCircleSize: 3,
highlightSeriesOpts: null,
// Directions for panning and zooming. Use bit operations when combined
// values are possible.
+/** @const */
Dygraph.HORIZONTAL = 1;
+/** @const */
Dygraph.VERTICAL = 2;
// Installed plugins, in order of precedence (most-general to most-specific).
* Triggers a cascade of events to the various plugins which are interested in them.
* Returns true if the "default behavior" should be performed, i.e. if none of
* the event listeners called event.preventDefault().
+ * @param {string} name Event name.
+ * @param {Object} extra_props Event-specific properties.
+ * @return {boolean} Whether to perform the default action.
* @private
*/
Dygraph.prototype.cascadeEvents_ = function(name, extra_props) {
* Returns the value of an option. This may be set by the user (either in the
* constructor or by calling updateOptions) or by dygraphs, and may be set to a
* per-series value.
- * @param { String } name The name of the option, e.g. 'rollPeriod'.
- * @param { String } [seriesName] The name of the series to which the option
+ * @param {string} name The name of the option, e.g. 'rollPeriod'.
+ * @param {string} opt_seriesName The name of the series to which the option
* will be applied. If no per-series value of this option is available, then
* the global value is returned. This is optional.
- * @return { ... } The value of the option.
+ * @return {*} The value of the option.
*/
-Dygraph.prototype.attr_ = function(name, seriesName) {
+Dygraph.prototype.attr_ = function(name, opt_seriesName) {
// <REMOVE_FOR_COMBINED>
if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
Dygraph.error('Must include options reference JS for testing');
Dygraph.OPTIONS_REFERENCE[name] = true;
}
// </REMOVE_FOR_COMBINED>
- return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
+ return opt_seriesName ? this.attributes_.getForSeries(name, opt_seriesName) : this.attributes_.get(name);
};
/**
/**
* @private
* @param {string} axis The name of the axis (i.e. 'x', 'y' or 'y2')
- * @return { ... } A function mapping string -> option value
+ * @return {function(string)} A function mapping string -> option value
*/
Dygraph.prototype.optionsViewForAxis_ = function(axis) {
var self = this;
* panning or a call to updateOptions.
* Returns a two-element array: [left, right].
* If the Dygraph has dates on the x-axis, these will be millis since epoch.
+ * @return {!Array.<number>} two element [left, right] array.
*/
Dygraph.prototype.xAxisRange = function() {
return this.dateWindow_ ? this.dateWindow_ : this.xAxisExtremes();
// Create the all-enclosing graph div
var enclosing = this.maindiv_;
+ /** @type {!HTMLDivElement} */
this.graphDiv = document.createElement("div");
// TODO(danvk): any other styles that are useful to set here?
this.resizeElements_();
+ /** @type {CanvasRenderingContext2D} */
this.canvas_ctx_ = Dygraph.getContext(this.canvas_);
+ /** @type {CanvasRenderingContext2D} */
this.hidden_ctx_ = Dygraph.getContext(this.hidden_);
// The interactive parts of the graph are drawn on top of the chart.
this.graphDiv.appendChild(this.canvas_);
this.mouseEventElement_ = this.createMouseEventElement_();
- // Create the grapher
+ /** @type {DygraphLayout} */
this.layout_ = new DygraphLayout(this);
var dygraph = this;
var labels = this.getLabels();
var num = labels.length - 1;
this.colors_ = [];
+ /** @type {Object.<string>} */
this.colorsMap_ = {};
var colors = this.attr_('colors');
var i;
/**
* Get the current graph's area object.
*
- * @return {Dygraph.Rect} An {x, y, w, h} object.
+ * @return {DygraphRect} An {x, y, w, h} object.
*/
Dygraph.prototype.getArea = function() {
return this.plotter_.area;
* Manually set the selected points and display information about them in the
* legend. The selection can be cleared using clearSelection() and queried
* using getSelection().
- * @param { Integer } row number that should be highlighted (i.e. appear with
- * hover dots on the chart). Set to false to clear any selection.
- * @param { seriesName } optional series name to highlight that series with the
- * the highlightSeriesOpts setting.
- * @param { locked } optional If true, keep seriesName selected when mousing
- * over the graph, disabling closest-series highlighting. Call clearSelection()
- * to unlock it.
+ *
+ * @param {number} row number that should be highlighted (i.e. appear with
+ * hover dots on the chart). Set to false to clear any selection.
+ * @param {string=} opt_seriesName series name to highlight that series with
+ * the the highlightSeriesOpts setting.
+ * @param {boolean=} opt_locked If true, keep seriesName selected when mousing
+ * over the graph, disabling closest-series highlighting. Call
+ * clearSelection() to unlock it.
*/
Dygraph.prototype.setSelection = function(row, opt_seriesName, opt_locked) {
// Extract the points we've selected
/**
* Returns the name of the currently-highlighted series.
* Only available when the highlightSeriesOpts option is in use.
+ * @return {string} The name of the highlighted series.
*/
Dygraph.prototype.getHighlightSeries = function() {
return this.highlightSet_;
* Converts a series to a Point array.
*
* @private
- * @param {Array.<Array.<(?number|Array<?number>)>} series Array where
+ * @param {Array.<Array.<(?number|Array.<?number>)>>} series Array where
* series[row] = [x,y] or [x, [y, err]] or [x, [y, yplus, yminus]].
* @param {boolean} bars True if error bars or custom bars are being drawn.
* @param {string} setName Name of the series.
* extreme values "speculatively", i.e. without actually setting state on the
* dygraph.
*
- * @param {Array.<Array.<Array.<(number|Array<number>)>>} rolledSeries, where
+ * @param {Array.<Array.<Array.<(number|Array.<number>)>>>} rolledSeries, where
* rolledSeries[seriesIndex][row] = raw point, where
* seriesIndex is the column number starting with 1, and
* rawPoint is [x,y] or [x, [y, err]] or [x, [y, yminus, yplus]].
// this.axes_ doesn't match this.attributes_.axes_.options. It's used for
// data computation as well as options storage.
// Go through once and add all the axes.
+ /**
+ * TODO(danvk): be more specific
+ * @type {Array.<Object>}
+ */
this.axes_ = [];
for (axis = 0; axis < this.attributes_.numAxes(); axis++) {
};
/**
- * @private
* Returns axis properties for the given series.
- * @param { String } setName The name of the series for which to get axis
- * properties, e.g. 'Y1'.
- * @return { Object } The axis properties.
+ * @param {string} setName The name of the series for which to get axis
+ * properties, e.g. 'Y1'.
+ * @return {Object} The axis properties.
+ * @private
*/
Dygraph.prototype.axisPropertiesForSeries = function(series) {
// TODO(danvk): handle errors.
* TODO(danvk): the "missing values" bit above doesn't seem right.
*
* @private
- * @param {Array.<Array.<(number|Array<Number>)>>} rawData Input data. Rectangular
- * grid of points, where rawData[row][0] is the X value for the row,
- * and rawData[row][i] is the Y data for series #i.
+ * @param {Array.<Array.<(number|Array.<number>)>>} rawData Input data.
+ * Rectangular grid of points, where rawData[row][0] is the X value for the
+ * row, and rawData[row][i] is the Y data for series #i.
* @param {number} i Series index, starting from 1.
* @param {boolean} logScale True if using logarithmic Y scale.
- * @return {Array.<Array.<(?number|Array<?number>)>} Series array, where
+ * @return {Array.<Array.<(?number|Array.<?number>)>>} Series array, where
* series[row] = [x,y] or [x, [y, err]] or [x, [y, yplus, yminus]].
*/
Dygraph.prototype.extractSeries_ = function(rawData, i, logScale) {