* @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
// --- check whether everything is ok before we return
// NOTE(konigsberg): isIE is never defined in this object. Bug of some sort.
- if (!this.isIE && !(DygraphCanvasRenderer.isSupported(this.element)))
+ if (!this.isIE && !(isCanvasSupported_(this.element)))
throw "Canvas is not supported.";
// internal state
};
/**
- * This just forwards to dygraph.attr_.
- * TODO(danvk): remove this?
- * @private
- */
-DygraphCanvasRenderer.prototype.attr_ = function(name, opt_seriesName) {
- return this.dygraph_.attr_(name, opt_seriesName);
-};
-
-/**
* Clears out all chart content and DOM elements.
* This is called immediately before render() on every frame, including
* during zooms and pans.
/**
* Checks whether the browser supports the <canvas> tag.
- * @private
*/
-DygraphCanvasRenderer.isSupported = function(canvasName) {
+isCanvasSupported_ = function(canvasName) {
var canvas = null;
try {
if (typeof(canvasName) == 'undefined' || canvasName === null) {
* connectSeparatedPoints is true. When it's false, the predicate will
* skip over points with missing yVals.
*/
-DygraphCanvasRenderer._getIteratorPredicate = function(connectSeparatedPoints) {
- return connectSeparatedPoints ?
- DygraphCanvasRenderer._predicateThatSkipsEmptyPoints :
- null;
+getIteratorPredicate_ = function(connectSeparatedPoints) {
+ return connectSeparatedPoints ? predicateThatSkipsEmptyPoints_ : null;
};
-DygraphCanvasRenderer._predicateThatSkipsEmptyPoints =
- function(array, idx) {
+predicateThatSkipsEmptyPoints_ = function(array, idx) {
return array[idx].yval !== null;
};
* @param {Object} e The dictionary passed to the plotter function.
* @private
*/
-DygraphCanvasRenderer._drawStyledLine = function(e,
+var drawStyledLine_ = function(e,
color, strokeWidth, strokePattern, drawPoints,
drawPointCallback, pointSize) {
var g = e.dygraph;
var points = e.points;
var iter = Dygraph.createIterator(points, 0, points.length,
- DygraphCanvasRenderer._getIteratorPredicate(
+ getIteratorPredicate_(
g.getOption("connectSeparatedPoints"))); // TODO(danvk): per-series?
var stroking = strokePattern && (strokePattern.length >= 2);
ctx.installPattern(strokePattern);
}
- var pointsOnLine = DygraphCanvasRenderer._drawSeries(
+ var pointsOnLine = drawSeries_(
e, iter, strokeWidth, pointSize, drawPoints, drawGapPoints, stepPlot, color);
- DygraphCanvasRenderer._drawPointsOnLine(
- e, pointsOnLine, drawPointCallback, color, pointSize);
+ drawPointsOnLine_(e, pointsOnLine, drawPointCallback, color, pointSize);
if (stroking) {
ctx.uninstallPattern();
* drawPointCallback should be fired. These include isolated points, or all
* points if drawPoints=true.
* @param {Object} e The dictionary passed to the plotter function.
- * @private
*/
-DygraphCanvasRenderer._drawSeries = function(e,
+drawSeries_ = function(e,
iter, strokeWidth, pointSize, drawPoints, drawGapPoints, stepPlot, color) {
var prevCanvasX = null;
* @param {Object} e The dictionary passed to the plotter function.
* @private
*/
-DygraphCanvasRenderer._drawPointsOnLine = function(
+drawPointsOnLine_ = function(
e, pointsOnLine, drawPointCallback, color, pointSize) {
var ctx = e.drawingContext;
for (var idx = 0; idx < pointsOnLine.length; idx++) {
this.colors = this.dygraph_.colorsMap_;
// Determine which series have specialized plotters.
- var plotter_attr = this.attr_("plotter");
+ var plotter_attr = this.dygraph_.attr_("plotter");
var plotters = plotter_attr;
if (!Dygraph.isArrayLike(plotters)) {
plotters = [plotters];
var setPlotters = {}; // series name -> plotter fn.
for (i = 0; i < setNames.length; i++) {
setName = setNames[i];
- var setPlotter = this.attr_("plotter", setName);
+ var setPlotter = this.dygraph_.attr_("plotter", setName);
if (setPlotter == plotter_attr) continue; // not specialized.
setPlotters[setName] = setPlotter;
};
/**
- * Standard plotters. These may be used by clients via Dygraph.Plotters.
- * See comments there for more details.
- */
-DygraphCanvasRenderer._Plotters = {
- linePlotter: function(e) {
- DygraphCanvasRenderer._linePlotter(e);
- },
-
- fillPlotter: function(e) {
- DygraphCanvasRenderer._fillPlotter(e);
- },
-
- errorPlotter: function(e) {
- DygraphCanvasRenderer._errorPlotter(e);
- }
-};
-
-/**
* Plotter which draws the central lines for a series.
* @private
*/
-DygraphCanvasRenderer._linePlotter = function(e) {
+linePlotter_ = function(e) {
var g = e.dygraph;
var setName = e.setName;
var strokeWidth = e.strokeWidth;
// TODO(danvk): Check if there's any performance impact of just calling
- // getOption() inside of _drawStyledLine. Passing in so many parameters makes
+ // getOption() inside of drawStyledLine_. Passing in so many parameters makes
// this code a bit nasty.
var borderWidth = g.getOption("strokeBorderWidth", setName);
var drawPointCallback = g.getOption("drawPointCallback", setName) ||
var pointSize = g.getOption("pointSize", setName);
if (borderWidth && strokeWidth) {
- DygraphCanvasRenderer._drawStyledLine(e,
+ drawStyledLine_(e,
g.getOption("strokeBorderColor", setName),
strokeWidth + 2 * borderWidth,
strokePattern,
);
}
- DygraphCanvasRenderer._drawStyledLine(e,
+ drawStyledLine_(e,
e.color,
strokeWidth,
strokePattern,
* need to be drawn on top of the error bars for all series.
* @private
*/
-DygraphCanvasRenderer._errorPlotter = function(e) {
+errorPlotter_ = function(e) {
var g = e.dygraph;
var setName = e.setName;
var errorBars = g.getOption("errorBars") || g.getOption("customBars");
var points = e.points;
var iter = Dygraph.createIterator(points, 0, points.length,
- DygraphCanvasRenderer._getIteratorPredicate(
- g.getOption("connectSeparatedPoints")));
+ getIteratorPredicate_(g.getOption("connectSeparatedPoints")));
var newYs;
*
* @private
*/
-DygraphCanvasRenderer._fillPlotter = function(e) {
+fillPlotter_ = function(e) {
// Skip if we're drawing a single series for interactive highlight overlay.
if (e.singleSeriesName) return;
var points = sets[setIdx];
var iter = Dygraph.createIterator(points, 0, points.length,
- DygraphCanvasRenderer._getIteratorPredicate(
- g.getOption("connectSeparatedPoints")));
+ getIteratorPredicate_(g.getOption("connectSeparatedPoints")));
// setup graphics context
var prevX = NaN;
ctx.fill();
}
};
+
+/**
+ * Standard plotters. These may be used by clients via Dygraph.Plotters.
+ * See comments there for more details.
+ */
+DygraphCanvasRenderer._Plotters = {
+ linePlotter: linePlotter_,
+ fillPlotter: fillPlotter_,
+ errorPlotter: errorPlotter_
+};
+
+return DygraphCanvasRenderer;
+
+})();
/*global Dygraph:false */
"use strict";
+// Constants, defined below.
+var PREFERRED_LOG_TICK_VALUES;
+
/** @typedef {Array.<{v:number, label:string, label_v:(string|undefined)}>} */
-Dygraph.TickList = undefined; // the ' = undefined' keeps jshint happy.
+var TickList;
/** @typedef {function(
* number,
* function(string):*,
* Dygraph=,
* Array.<number>=
- * ): Dygraph.TickList}
+ * ): TickList}
*/
-Dygraph.Ticker = undefined; // the ' = undefined' keeps jshint happy.
+var Ticker;
-/** @type {Dygraph.Ticker} */
+/** @type {Ticker} */
Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) {
var nonLogscaleOpts = function(opt) {
if (opt === 'logscale') return false;
return Dygraph.numericTicks(a, b, pixels, nonLogscaleOpts, dygraph, vals);
};
-/** @type {Dygraph.Ticker} */
+/** @type {Ticker} */
Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) {
var pixels_per_tick = /** @type{number} */(opts('pixelsPerLabel'));
var ticks = [];
};
-/** @type {Dygraph.Ticker} */
+/** @type {Ticker} */
Dygraph.dateTicker = function(a, b, pixels, opts, dygraph, vals) {
var chosen = Dygraph.pickDateTickGranularity(a, b, pixels, opts);
* NOTE: this assumes that Dygraph.LOG_SCALE = 10.
* @type {Array.<number>}
*/
-var PREFERRED_LOG_TICK_VALUES = function() {
+PREFERRED_LOG_TICK_VALUES = function() {
var vals = [];
for (var power = -39; power <= 39; power++) {
var range = Math.pow(10, power);
* @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 {!TickList}
*/
Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) {
var formatter = /** @type{AxisLabelFormatter} */(
};
/**
+ * 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.
+ */
+var addAnnotationRule_ = function() {
+ // TODO(danvk): move this function into plugins/annotations.js?
+ if (addedAnnotationCSS) return;
+
+ var rule = "border: 1px solid black; " +
+ "background-color: white; " +
+ "text-align: center;";
+
+ var styleSheetElement = document.createElement("style");
+ styleSheetElement.type = "text/css";
+ document.getElementsByTagName("head")[0].appendChild(styleSheetElement);
+
+ // Find the first style sheet that we can access.
+ // We may not add a rule to a style sheet from another domain for security
+ // reasons. This sometimes comes up when using gviz, since the Google gviz JS
+ // adds its own style sheets from google.com.
+ for (var i = 0; i < document.styleSheets.length; i++) {
+ if (document.styleSheets[i].disabled) continue;
+ var mysheet = document.styleSheets[i];
+ try {
+ if (mysheet.insertRule) { // Firefox
+ var idx = mysheet.cssRules ? mysheet.cssRules.length : 0;
+ mysheet.insertRule(".dygraphDefaultAnnotation { " + rule + " }", idx);
+ } else if (mysheet.addRule) { // IE
+ mysheet.addRule(".dygraphDefaultAnnotation", rule);
+ }
+ addedAnnotationCSS = true;
+ return;
+ } catch(err) {
+ // Was likely a security exception.
+ }
+ }
+
+ Dygraph.warn("Unable to add default annotation CSS rule; display may be off.");
+};
+
+
+/**
* Update the list of annotations and redraw the chart.
* See dygraphs.com/annotations.html for more info on how to use annotations.
* @param ann {Array} An array of annotation objects.
*/
Dygraph.prototype.setAnnotations = function(ann, suppressDraw) {
// Only add the annotation CSS rule once we know it will be used.
- addAnnotationRule();
+ addAnnotationRule_();
this.annotations_ = ann;
if (!this.layout_) {
Dygraph.warn("Tried to setAnnotations before dygraph was ready. " +
return this.setIndexByName_[name];
};
-/**
- * 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.
- */
-var addAnnotationRule = function() {
- // TODO(danvk): move this function into plugins/annotations.js?
- if (addedAnnotationCSS) return;
-
- var rule = "border: 1px solid black; " +
- "background-color: white; " +
- "text-align: center;";
-
- var styleSheetElement = document.createElement("style");
- styleSheetElement.type = "text/css";
- document.getElementsByTagName("head")[0].appendChild(styleSheetElement);
-
- // Find the first style sheet that we can access.
- // We may not add a rule to a style sheet from another domain for security
- // reasons. This sometimes comes up when using gviz, since the Google gviz JS
- // adds its own style sheets from google.com.
- for (var i = 0; i < document.styleSheets.length; i++) {
- if (document.styleSheets[i].disabled) continue;
- var mysheet = document.styleSheets[i];
- try {
- if (mysheet.insertRule) { // Firefox
- var idx = mysheet.cssRules ? mysheet.cssRules.length : 0;
- mysheet.insertRule(".dygraphDefaultAnnotation { " + rule + " }", idx);
- } else if (mysheet.addRule) { // IE
- mysheet.addRule(".dygraphDefaultAnnotation", rule);
- }
- addedAnnotationCSS = true;
- return;
- } catch(err) {
- // Was likely a security exception.
- }
- }
-
- Dygraph.warn("Unable to add default annotation CSS rule; display may be off.");
-};
-
return Dygraph;
})();