/**
* Creates a new DygraphLayout object.
- * @param {Object} options Options for PlotKit.Layout
* @return {Object} The DygraphLayout object
*/
-DygraphLayout = function(dygraph, options) {
+DygraphLayout = function(dygraph) {
this.dygraph_ = dygraph;
- this.options = {}; // TODO(danvk): remove, use attr_ instead.
- Dygraph.update(this.options, options ? options : {});
this.datasets = new Array();
this.annotations = new Array();
+ this.yAxes_ = null;
+
+ // TODO(danvk): it's odd that xTicks_ and yTicks_ are inputs, but xticks and
+ // yticks are outputs. Clean this up.
+ this.xTicks_ = null;
+ this.yTicks_ = null;
};
DygraphLayout.prototype.attr_ = function(name) {
}
};
+DygraphLayout.prototype.setXTicks = function(xTicks) {
+ this.xTicks_ = xTicks;
+};
+
+// TODO(danvk): add this to the Dygraph object's API or move it into Layout.
+DygraphLayout.prototype.setYAxes = function (yAxes) {
+ this.yAxes_ = yAxes;
+};
+
+DygraphLayout.prototype.setDateWindow = function(dateWindow) {
+ this.dateWindow_ = dateWindow;
+};
+
DygraphLayout.prototype.evaluate = function() {
this._evaluateLimits();
this._evaluateLineCharts();
DygraphLayout.prototype._evaluateLimits = function() {
this.minxval = this.maxxval = null;
- if (this.options.dateWindow) {
- this.minxval = this.options.dateWindow[0];
- this.maxxval = this.options.dateWindow[1];
+ if (this.dateWindow_) {
+ this.minxval = this.dateWindow_[0];
+ this.maxxval = this.dateWindow_[1];
} else {
for (var name in this.datasets) {
if (!this.datasets.hasOwnProperty(name)) continue;
this.xrange = this.maxxval - this.minxval;
this.xscale = (this.xrange != 0 ? 1/this.xrange : 1.0);
- for (var i = 0; i < this.options.yAxes.length; i++) {
- var axis = this.options.yAxes[i];
+ for (var i = 0; i < this.yAxes_.length; i++) {
+ var axis = this.yAxes_[i];
axis.minyval = axis.computedValueRange[0];
axis.maxyval = axis.computedValueRange[1];
axis.yrange = axis.maxyval - axis.minyval;
if (!this.datasets.hasOwnProperty(setName)) continue;
var dataset = this.datasets[setName];
- var axis = this.options.yAxes[this.options.seriesToAxisMap[setName]];
+ var axis = this.dygraph_.axisPropertiesForSeries(setName);
for (var j = 0; j < dataset.length; j++) {
var item = dataset[j];
DygraphLayout.prototype._evaluateLineTicks = function() {
this.xticks = new Array();
- for (var i = 0; i < this.options.xTicks.length; i++) {
- var tick = this.options.xTicks[i];
+ for (var i = 0; i < this.xTicks_.length; i++) {
+ var tick = this.xTicks_[i];
var label = tick.label;
var pos = this.xscale * (tick.v - this.minxval);
if ((pos >= 0.0) && (pos <= 1.0)) {
}
this.yticks = new Array();
- for (var i = 0; i < this.options.yAxes.length; i++ ) {
- var axis = this.options.yAxes[i];
+ for (var i = 0; i < this.yAxes_.length; i++ ) {
+ var axis = this.yAxes_[i];
for (var j = 0; j < axis.ticks.length; j++) {
var tick = axis.ticks[j];
var label = tick.label;
*/
DygraphLayout.prototype.evaluateWithError = function() {
this.evaluate();
- if (!this.options.errorBars) return;
+ if (!(this.attr_('errorBars') || this.attr_('customBars'))) return;
// Copy over the error terms
var i = 0; // index in this.points
};
/**
- * Change the values of various layout options
- * @param {Object} new_options an associative array of new properties
- */
-DygraphLayout.prototype.updateOptions = function(new_options) {
- Dygraph.update(this.options, new_options ? new_options : {});
-};
-
-/**
* Return a copy of the point at the indicated index, with its yval unstacked.
* @param int index of point in layout_.points
*/
var colorCount = this.options.colorScheme.length;
var colorScheme = this.options.colorScheme;
var fillAlpha = this.options.fillAlpha;
- var errorBars = this.layout.options.errorBars;
+ var errorBars = this.attr_("errorBars");
var fillGraph = this.attr_("fillGraph");
- var stackedGraph = this.layout.options.stackedGraph;
- var stepPlot = this.layout.options.stepPlot;
+ var stackedGraph = this.attr_("stackedGraph");
+ var stepPlot = this.attr_("stepPlot");
var setNames = [];
for (var name in this.layout.datasets) {
for (var i = 0; i < setCount; i++) {
var setName = setNames[i];
- var axis = this.layout.options.yAxes[
- this.layout.options.seriesToAxisMap[setName]];
+ var axis = this.dygraph_.axisPropertiesForSeries(setName);
var color = this.colors[setName];
// setup graphics context
for (var i = setCount - 1; i >= 0; i--) {
var setName = setNames[i];
var color = this.colors[setName];
- var axis = this.layout.options.yAxes[
- this.layout.options.seriesToAxisMap[setName]];
+ var axis = this.dygraph_.axisPropertiesForSeries(setName);
var axisY = 1.0 + axis.minyval * axis.yscale;
if (axisY < 0.0) axisY = 0.0;
else if (axisY > 1.0) axisY = 1.0;
});
// Create the grapher
- // TODO(danvk): why does the Layout need its own set of options?
- this.layoutOptions_ = { 'xOriginIsZero': false };
- Dygraph.update(this.layoutOptions_, this.attrs_);
- Dygraph.update(this.layoutOptions_, this.user_attrs_);
- Dygraph.update(this.layoutOptions_, {
- 'errorBars': (this.attr_("errorBars") || this.attr_("customBars")) });
-
- this.layout_ = new DygraphLayout(this, this.layoutOptions_);
+ this.layout_ = new DygraphLayout(this);
// TODO(danvk): why does the Renderer need its own set of options?
this.renderOptions_ = { colorScheme: this.colors_,
// TODO(danvk): update this w/r/t/ the new options system.
this.renderOptions_.colorScheme = this.colors_;
Dygraph.update(this.plotter_.options, this.renderOptions_);
- Dygraph.update(this.layoutOptions_, this.user_attrs_);
- Dygraph.update(this.layoutOptions_, this.attrs_);
};
/**
}
var xTicks = this.attr_('xTicker')(range[0], range[1], this);
- this.layout_.updateOptions({xTicks: xTicks});
+ this.layout_.setXTicks(xTicks);
};
// Time granularity enumeration
}
this.computeYAxisRanges_(extremes);
- this.layout_.updateOptions( { yAxes: this.axes_,
- seriesToAxisMap: this.seriesToAxisMap_
- } );
+ this.layout_.setYAxes(this.axes_);
+
this.addXTicks_();
- // Save the X axis zoomed status as the updateOptions call will tend to set it errorneously
+ // Save the X axis zoomed status as the updateOptions call will tend to set it erroneously
var tmp_zoomed_x = this.zoomed_x_;
// Tell PlotKit to use this new data and render itself
- this.layout_.updateOptions({dateWindow: this.dateWindow_});
+ this.layout_.setDateWindow(this.dateWindow_);
this.zoomed_x_ = tmp_zoomed_x;
this.layout_.evaluateWithError();
this.plotter_.clear();
/**
* @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.
+ */
+Dygraph.prototype.axisPropertiesForSeries = function(series) {
+ // TODO(danvk): handle errors.
+ return this.axes_[this.seriesToAxisMap_[series]];
+};
+
+/**
+ * @private
* Determine the value range and tick marks for each axis.
* @param {Object} extremes A mapping from seriesName -> [low, high]
* This fills in the valueRange and ticks fields in each entry of this.axes_.
this.labelsFromCSV_ = (this.attr_("labels") == null);
- // TODO(danvk): this doesn't match the constructor logic
- this.layout_.updateOptions({ 'errorBars': this.attr_("errorBars") });
if (attrs['file']) {
this.file_ = attrs['file'];
this.start_();