From: Dan Vanderkam Date: Mon, 9 May 2011 15:27:07 +0000 (-0700) Subject: remove DygraphLayout.options X-Git-Tag: v1.0.0~502 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=b2c9222a1acdb3c5af252937176fe2e9f9ea7bb1;p=dygraphs.git remove DygraphLayout.options --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 2874990..ab66ef3 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -29,15 +29,18 @@ /** * 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) { @@ -72,6 +75,19 @@ DygraphLayout.prototype.setAnnotations = function(ann) { } }; +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(); @@ -81,9 +97,9 @@ DygraphLayout.prototype.evaluate = function() { 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; @@ -100,8 +116,8 @@ DygraphLayout.prototype._evaluateLimits = function() { 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; @@ -126,7 +142,7 @@ DygraphLayout.prototype._evaluateLineCharts = function() { 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]; @@ -153,8 +169,8 @@ DygraphLayout.prototype._evaluateLineCharts = function() { 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)) { @@ -163,8 +179,8 @@ DygraphLayout.prototype._evaluateLineTicks = function() { } 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; @@ -183,7 +199,7 @@ DygraphLayout.prototype._evaluateLineTicks = function() { */ 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 @@ -234,14 +250,6 @@ DygraphLayout.prototype.removeAllDatasets = function() { }; /** - * 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 */ @@ -852,10 +860,10 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { 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) { @@ -887,8 +895,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { 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 @@ -950,8 +957,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { 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; diff --git a/dygraph.js b/dygraph.js index a59edd6..0f297fe 100644 --- a/dygraph.js +++ b/dygraph.js @@ -758,14 +758,7 @@ Dygraph.prototype.createInterface_ = function() { }); // 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_, @@ -905,8 +898,6 @@ Dygraph.prototype.setColors_ = function() { // 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_); }; /** @@ -2188,7 +2179,7 @@ Dygraph.prototype.addXTicks_ = function() { } var xTicks = this.attr_('xTicker')(range[0], range[1], this); - this.layout_.updateOptions({xTicks: xTicks}); + this.layout_.setXTicks(xTicks); }; // Time granularity enumeration @@ -2797,15 +2788,14 @@ Dygraph.prototype.drawGraph_ = function() { } 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(); @@ -2936,6 +2926,18 @@ Dygraph.prototype.numAxes = function() { /** * @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_. @@ -3761,8 +3763,6 @@ Dygraph.prototype.updateOptions = function(attrs) { 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_();