*/
/**
+ * @constructor
+ *
* The DygraphCanvasRenderer class does the actual rendering of the chart onto
* a canvas. It's based on PlotKit.CanvasRenderer.
- * @param {Object} element The canvas to attach to
- * @param {Object} elementContext The 2d context of the canvas (injected so it
- * can be mocked for testing.)
- * @param {Layout} layout The DygraphLayout object for this graph.
- * @constructor
- */
-
-var DygraphCanvasRenderer = (function() {
-
-/*jshint globalstrict: true */
-/*global Dygraph:false,RGBColorParser:false */
-"use strict";
-
-// Utility methods for this file.
-var isCanvasSupported_,
- getIteratorPredicate_,
- predicateThatSkipsEmptyPoints_,
- drawSeries_,
- drawPointsOnLine_,
- linePlotter_,
- fillPlotter_,
- errorPlotter_;
-
-
-/**
- * @constructor
*
* This gets called when there are "new points" to chart. This is generally the
* case when the underlying data being charted has changed. It is _not_ called
this.width = this.element.width;
// --- check whether everything is ok before we return
- // NOTE(konigsberg): isIE is never defined in this object. Bug of some sort.
- if (!this.isIE && !(isCanvasSupported_(this.element)))
- throw "Canvas is not supported.";
+ if (!(Dygraph.isCanvasSupported(this.element))) {
+ throw "Canvas is not supported.";
+ }
// internal state
this.area = layout.getPlotArea();
}
};
+
+(function() {
+
+/*jshint globalstrict: true */
+/*global Dygraph:false,RGBColorParser:false */
+"use strict";
+
+// Utility methods for this file.
+var getIteratorPredicate_,
+ predicateThatSkipsEmptyPoints_,
+ drawSeries_,
+ drawPointsOnLine_,
+ linePlotter_,
+ fillPlotter_,
+ errorPlotter_;
+
+
/**
* Clears out all chart content and DOM elements.
* This is called immediately before render() on every frame, including
};
/**
- * Checks whether the browser supports the <canvas> tag.
- */
-isCanvasSupported_ = function(canvasName) {
- var canvas = null;
- try {
- if (typeof(canvasName) == 'undefined' || canvasName === null) {
- canvas = document.createElement("canvas");
- } else {
- canvas = canvasName;
- }
- canvas.getContext("2d");
- }
- catch (e) {
- var ie = navigator.appVersion.match(/MSIE (\d\.\d)/);
- var opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
- if ((!ie) || (ie[1] < 6) || (opera))
- return false;
- return true;
- }
- return true;
-};
-
-/**
* This method is responsible for drawing everything on the chart, including
* lines, error bars, fills and axes.
* It is called immediately after clear() on every frame, including during pans
*
* @param {string=} opt_seriesName when specified, only that series will
* be drawn. (This is used for expedited redrawing with highlightSeriesOpts)
- * @param {CanvasRenderingContext2D} opt_ctx when specified, the drawing
- * context. However, lines are typically drawn on the object's
+ * @param {CanvasRenderingContext2D=} opt_ctx when specified, the drawing
+ * context. However, lines are typically drawn on the object's
* elementContext.
* @private
*/
this.colors = this.dygraph_.colorsMap_;
// Determine which series have specialized plotters.
- var plotter_attr = this.dygraph_.attr_("plotter");
- var plotters = plotter_attr;
+ var plotter_attr = /** @type{!Array.<!Dygraph.PlotterType>|!Dygraph.PlotterType}*/(this.dygraph_.getOption("plotter"));
+
+ /** @type{!Array.<!Dygraph.PlotterType>} */
+ var plotters;
if (!Dygraph.isArrayLike(plotters)) {
plotters = [plotters];
+ } else {
+ plotters = /** @type {!Array.<!Dygraph.PlotterType>} */(plotter_attr);
}
+ /** @type {Object.<!Dygraph.PlotterType>} */
var setPlotters = {}; // series name -> plotter fn.
for (i = 0; i < setNames.length; i++) {
setName = setNames[i];
- var setPlotter = this.dygraph_.attr_("plotter", setName);
+ var setPlotter = this.dygraph_.getOption("plotter", setName);
if (setPlotter == plotter_attr) continue; // not specialized.
- setPlotters[setName] = setPlotter;
+ setPlotters[setName] = /** @type {!Dygraph.PlotterType} */(setPlotter);
}
for (i = 0; i < plotters.length; i++) {
}
var color = this.colors[setName];
- var strokeWidth = this.dygraph_.getOption("strokeWidth", setName);
+ var strokeWidth = /** @type{number}*/(this.dygraph_.getOption("strokeWidth", setName));
ctx.save();
ctx.strokeStyle = color;
ctx.lineWidth = strokeWidth;
+ // TODO(danvk): add an @typedef for this Object.
p({
points: points,
setName: setName,
errorPlotter: errorPlotter_
};
-return DygraphCanvasRenderer;
-
})();
Dygraph.prototype.registeredEvents_;
/**
+ * @type {CanvasRenderingContext2D}
+ */
+Dygraph.prototype.canvas_ctx_;
+
+/**
+ * @type {CanvasRenderingContext2D}
+ */
+Dygraph.prototype.hidden_ctx_;
+
+/**
+ * @type {Object.<string>}
+ */
+Dygraph.prototype.colorsMap_;
+
+/**
* @return {!Array.<number>} two element [left, right] array.
*/
Dygraph.prototype.xAxisRange = function() {};
*/
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() {};
+
/** @type {{axes: Object}} */
Dygraph.DEFAULT_ATTRS;
* }}
*/
Dygraph.AxisType;
+
+/**
+ * TODO(danvk): be more specific than "Object".
+ * @typedef {function(Object)}
+ */
+Dygraph.PlotterType;
* dygraphs will remain in a consistent state. If you want to modify an option,
* use updateOptions() instead.
*
- * @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.
+ * @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 this.attr_(name, opt_seriesName);
* Return the list of colors. This is either the list of colors passed in the
* attributes or the autogenerated list of rgb(r,g,b) strings.
* This does not return colors for invisible series.
- * @return {Array<string>} The list of colors.
+ * @return {Array.<string>} The list of colors.
*/
Dygraph.prototype.getColors = function() {
return this.colors_;
* x-axis, so the data series names start at index 1.
*
* Returns null when labels have not yet been defined.
+ * @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() {
var labels = this.attr_("labels");