*/
-// For "production" code, this gets set to false by uglifyjs.
-// if (typeof(DEBUG) === 'undefined') DEBUG=true;
-var DEBUG = true;
-
import DygraphLayout from './dygraph-layout';
import DygraphCanvasRenderer from './dygraph-canvas';
import DygraphOptions from './dygraph-options';
import * as DygraphTickers from './dygraph-tickers';
import * as utils from './dygraph-utils';
import DEFAULT_ATTRS from './dygraph-default-attrs';
-import DygraphDataHandler from './datahandler/datahandler';
+import OPTIONS_REFERENCE from './dygraph-options-reference';
+import IFrameTarp from './iframe-tarp';
+
import DefaultHandler from './datahandler/default';
+import ErrorBarsHandler from './datahandler/bars-error';
+import CustomBarsHandler from './datahandler/bars-custom';
+import DefaultFractionHandler from './datahandler/default-fractions';
+import FractionsBarsHandler from './datahandler/bars-fractions';
+import BarsHandler from './datahandler/bars';
import AnnotationsPlugin from './plugins/annotations';
import AxesPlugin from './plugins/axes';
import LegendPlugin from './plugins/legend';
import RangeSelectorPlugin from './plugins/range-selector';
-/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */
+import GVizChart from './dygraph-gviz';
+
"use strict";
/**
* @return { ... } The value of the option.
*/
Dygraph.prototype.attr_ = function(name, seriesName) {
- // if (DEBUG) {
- // if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
- // console.error('Must include options reference JS for testing');
- // } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
- // console.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;
- // }
- // }
+ // For "production" code, this gets removed by uglifyjs.
+ if (process.env.NODE_ENV != 'production') {
+ if (typeof(OPTIONS_REFERENCE) === 'undefined') {
+ console.error('Must include options reference JS for testing');
+ } else if (!OPTIONS_REFERENCE.hasOwnProperty(name)) {
+ console.error('Dygraphs is using property ' + name + ', which has no ' +
+ 'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
+ // Only log this error once.
+ OPTIONS_REFERENCE[name] = true;
+ }
+ }
return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
};
//
// Use both sides as the exponent in 10^exp and we're done.
// x = 10 ^ (log(xRange[0]) + (pct * (log(xRange[1]) - log(xRange[0])))
- var logr0 = Dygraph.log10(xRange[0]);
- var logr1 = Dygraph.log10(xRange[1]);
+ var logr0 = utils.log10(xRange[0]);
+ var logr1 = utils.log10(xRange[1]);
var exponent = logr0 + (pct * (logr1 - logr0));
- var value = Math.pow(Dygraph.LOG_SCALE, exponent);
+ var value = Math.pow(utils.LOG_SCALE, exponent);
return value;
}
};
//
// Use both sides as the exponent in 10^exp and we're done.
// y = 10 ^ (log(yRange[1]) - (pct * (log(yRange[1]) - log(yRange[0]))));
- var logr0 = Dygraph.log10(yRange[0]);
- var logr1 = Dygraph.log10(yRange[1]);
+ var logr0 = utils.log10(yRange[0]);
+ var logr1 = utils.log10(yRange[1]);
var exponent = logr1 - (pct * (logr1 - logr0));
- var value = Math.pow(Dygraph.LOG_SCALE, exponent);
+ var value = Math.pow(utils.LOG_SCALE, exponent);
return value;
}
};
var pct;
var logscale = this.attributes_.getForAxis("logscale", axis);
if (logscale) {
- var logr0 = Dygraph.log10(yRange[0]);
- var logr1 = Dygraph.log10(yRange[1]);
- pct = (logr1 - Dygraph.log10(y)) / (logr1 - logr0);
+ var logr0 = utils.log10(yRange[0]);
+ var logr1 = utils.log10(yRange[1]);
+ pct = (logr1 - utils.log10(y)) / (logr1 - logr0);
} else {
// yRange[1] - y is unit distance from the bottom.
// yRange[1] - yRange[0] is the scale of the range.
var pct;
var logscale = this.attributes_.getForAxis("logscale", 'x') ;
if (logscale === true) { // logscale can be null so we test for true explicitly.
- var logr0 = Dygraph.log10(xRange[0]);
- var logr1 = Dygraph.log10(xRange[1]);
- pct = (Dygraph.log10(x) - logr0) / (logr1 - logr0);
+ var logr0 = utils.log10(xRange[0]);
+ var logr1 = utils.log10(xRange[1]);
+ pct = (utils.log10(x) - logr0) / (logr1 - logr0);
} else {
// x - xRange[0] is unit distance from the left.
// xRange[1] - xRange[0] is the scale of the range.
this.removeTrackedEvents_();
// remove mouse event handlers (This may not be necessary anymore)
- Dygraph.removeEvent(window, 'mouseout', this.mouseOutHandler_);
- Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
+ utils.removeEvent(window, 'mouseout', this.mouseOutHandler_);
+ utils.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
// remove window handlers
- Dygraph.removeEvent(window,'resize', this.resizeHandler_);
+ utils.removeEvent(window,'resize', this.resizeHandler_);
this.resizeHandler_ = null;
removeRecursive(this.maindiv_);
// alternate colors for high contrast.
var idx = i % 2 ? (half + (i + 1)/ 2) : Math.ceil((i + 1) / 2);
var hue = (1.0 * idx / (1 + num));
- colorStr = Dygraph.hsvToRGB(hue, sat, val);
+ colorStr = utils.hsvToRGB(hue, sat, val);
}
}
this.colors_.push(colorStr);
// We cover iframes during mouse interactions. See comments in
// dygraph-utils.js for more info on why this is a good idea.
- tarp: new utils.IFrameTarp(),
+ tarp: new IFrameTarp(),
// contextB is the same thing as this context object but renamed.
initializeMouseDown: function(event, g, contextB) {
var points = this.layout_.points[setIdx];
for (var i = 0; i < points.length; ++i) {
point = points[i];
- if (!Dygraph.isValidPoint(point)) continue;
+ if (!utils.isValidPoint(point)) continue;
dx = point.canvasx - domX;
dy = point.canvasy - domY;
dist = dx * dx + dy * dy;
var points = this.layout_.points[setIdx];
if (rowIdx >= points.length) continue;
var p1 = points[rowIdx];
- if (!Dygraph.isValidPoint(p1)) continue;
+ if (!utils.isValidPoint(p1)) continue;
var py = p1.canvasy;
if (domX > p1.canvasx && rowIdx + 1 < points.length) {
// interpolate series Y value using next point
var p2 = points[rowIdx + 1];
- if (Dygraph.isValidPoint(p2)) {
+ if (utils.isValidPoint(p2)) {
var dx = p2.canvasx - p1.canvasx;
if (dx > 0) {
var r = (domX - p1.canvasx) / dx;
} else if (domX < p1.canvasx && rowIdx > 0) {
// interpolate series Y value using previous point
var p0 = points[rowIdx - 1];
- if (Dygraph.isValidPoint(p0)) {
+ if (utils.isValidPoint(p0)) {
var dx = p1.canvasx - p0.canvasx;
if (dx > 0) {
var r = (p1.canvasx - domX) / dx;
if (this.getOption('highlightSeriesOpts')) {
ctx.clearRect(0, 0, this.width_, this.height_);
var alpha = 1.0 - this.getNumericOption('highlightSeriesBackgroundAlpha');
+ var backgroundColor = utils.toRGB_(this.getOption('highlightSeriesBackgroundColor'));
+
if (alpha) {
// Activating background fade includes an animation effect for a gradual
// fade. TODO(klausw): make this independently configurable if it causes
}
alpha *= opt_animFraction;
}
- ctx.fillStyle = 'rgba(255,255,255,' + alpha + ')';
+ ctx.fillStyle = 'rgba(' + backgroundColor.r + ',' + backgroundColor.g + ',' + backgroundColor.b + ',' + alpha + ')';
ctx.fillRect(0, 0, this.width_, this.height_);
}
ctx.save();
for (i = 0; i < this.selPoints_.length; i++) {
var pt = this.selPoints_[i];
- if (!utils.isOK(pt.canvasy)) continue;
+ if (isNaN(pt.canvasy) || pt.canvasy === null || pt.canvasy === undefined) continue;
var circleSize = this.getNumericOption('highlightCircleSize', pt.name);
var callback = this.getFunctionOption("drawHighlightPointCallback", pt.name);
handlerClass = this.attr_('dataHandler');
} else if (this.fractions_) {
if (this.getBooleanOption('errorBars')) {
- handlerClass = DygraphDataHandlers.FractionsBarsHandler;
+ handlerClass = FractionsBarsHandler;
} else {
- handlerClass = DygraphDataHandlers.DefaultFractionHandler;
+ handlerClass = DefaultFractionHandler;
}
} else if (this.getBooleanOption('customBars')) {
- handlerClass = DygraphDataHandlers.CustomBarsHandler;
+ handlerClass = CustomBarsHandler;
} else if (this.getBooleanOption('errorBars')) {
- handlerClass = DygraphDataHandlers.ErrorBarsHandler;
+ handlerClass = ErrorBarsHandler;
} else {
handlerClass = DefaultHandler;
}
GridPlugin
];
+// There are many symbols which have historically been available through the
+// Dygraph class. These are exported here for backwards compatibility.
+Dygraph.GVizChart = GVizChart;
+Dygraph.DASHED_LINE = utils.DASHED_LINE;
+Dygraph.DOT_DASH_LINE = utils.DOT_DASH_LINE;
+Dygraph.dateAxisLabelFormatter = utils.dateAxisLabelFormatter;
+Dygraph.toRGB_ = utils.toRGB_;
+Dygraph.findPos = utils.findPos;
+Dygraph.pageX = utils.pageX;
+Dygraph.pageY = utils.pageY;
+Dygraph.dateString_ = utils.dateString_;
+Dygraph.defaultInteractionModel = DygraphInteraction.defaultModel;
+Dygraph.nonInteractiveModel = Dygraph.nonInteractiveModel_ = DygraphInteraction.nonInteractiveModel_;
+Dygraph.Circles = utils.Circles;
+
+Dygraph.Plugins = {
+ Legend: LegendPlugin,
+ Axes: AxesPlugin,
+ Annotations: AnnotationsPlugin,
+ ChartLabels: ChartLabelsPlugin,
+ Grid: GridPlugin,
+ RangeSelector: RangeSelectorPlugin
+};
+
+Dygraph.DataHandlers = {
+ DefaultHandler,
+ BarsHandler,
+ CustomBarsHandler,
+ DefaultFractionHandler,
+ ErrorBarsHandler,
+ FractionsBarsHandler
+};
+
+Dygraph.startPan = DygraphInteraction.startPan;
+Dygraph.startZoom = DygraphInteraction.startZoom;
+Dygraph.movePan = DygraphInteraction.movePan;
+Dygraph.moveZoom = DygraphInteraction.moveZoom;
+Dygraph.endPan = DygraphInteraction.endPan;
+Dygraph.endZoom = DygraphInteraction.endZoom;
+
+Dygraph.numericLinearTicks = DygraphTickers.numericLinearTicks;
+Dygraph.numericTicks = DygraphTickers.numericTicks;
+Dygraph.dateTicker = DygraphTickers.dateTicker;
+Dygraph.Granularity = DygraphTickers.Granularity;
+Dygraph.getDateAxis = DygraphTickers.getDateAxis;
+Dygraph.floatFormat = utils.floatFormat;
+
export default Dygraph;