From: Robert Konigsberg Date: Sat, 24 Nov 2012 15:45:26 +0000 (-0500) Subject: Merge branch 'master' into remove-old-options X-Git-Tag: v1.0.0~157^2~3^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=242a8bc8c3282bf2334aa3e9254d6e99e3e2f2c2;p=dygraphs.git Merge branch 'master' into remove-old-options Conflicts: dygraph-options.js dygraph.js --- 242a8bc8c3282bf2334aa3e9254d6e99e3e2f2c2 diff --cc dygraph-options.js index 0f65f39,9a4f6bf..dd7bb6b --- a/dygraph-options.js +++ b/dygraph-options.js @@@ -9,11 -9,11 +9,11 @@@ /* * Interesting member variables: * dygraph_ - the graph. - * global - global attributes (common among all graphs, AIUI) + * global_ - global attributes (common among all graphs, AIUI) - * user_ - attributes set by the user + * user - attributes set by the user - * axes - map of options specific to the axis. - * series - { seriesName -> { idx, yAxis, options } - * labels - used as mapping from index to series name. + * axes_ - array of axis index to { series : [ series names ] , options : { axis-specific options. } - * series_ - { seriesName -> { idx, yAxis, options } ++ * series_ - { seriesName -> { idx, yAxis, options }} + * labels_ - used as mapping from index to series name. */ /** @@@ -32,21 -35,27 +35,27 @@@ var DygraphOptions = function(dygraph) this.global_ = this.dygraph_.attrs_; this.user_ = this.dygraph_.user_attrs_ || {}; - this.highlightSeries_ = this.find("highlightSeriesOpts") || {}; + this.highlightSeries_ = this.get("highlightSeriesOpts") || {}; // Get a list of series names. - var labels = this.find("labels"); + var labels = this.get("labels"); if (!labels) { return; // -- can't do more for now, will parse after getting the labels. - }; + } this.reparseSeries(); - } + }; + /** + * Reparses options that are all related to series. This typically occurs when + * options are either updated, or source data has been made avaialble. + * + * TODO(konigsberg): The method name is kind of weak; fix. + */ DygraphOptions.prototype.reparseSeries = function() { - this.labels = this.find("labels").slice(1); + this.labels = this.get("labels").slice(1); - this.axes_ = [ {} ]; // Always one axis at least. + this.axes_ = [ { series : [], options : {}} ]; // Always one axis at least. this.series_ = {}; var axisId = 0; // 0-offset; there's always one. @@@ -114,12 -120,26 +128,26 @@@ DygraphOptions.prototype.get = function return this.global_[name]; } return null; - } + }; - DygraphOptions.prototype.findForAxis = function(name, axis) { - var axisIdx = (axis == "y2" || axis == "y2" || axis == 1) ? 1 : 0; + /** + * Get a value for a specific axis. If there is no specific value for the axis, + * the global value is returned. + * + * @param {String} name the name of the option. + * @param {String|number} axis the axis to search. Can be the string representation + * ("y", "y2") or the axis number (0, 1). + */ + DygraphOptions.prototype.getForAxis = function(name, axis) { + var axisIdx = 0; + if (typeof(axis) == 'number') { + axisIdx = axis; + } else { + // TODO(konigsberg): Accept only valid axis strings? + axisIdx = (axis == "y2") ? 1 : 0; + } - var axisOptions = this.axes_[axisIdx]; + var axisOptions = this.axes_[axisIdx].options; if (axisOptions.hasOwnProperty(name)) { return axisOptions[name]; } @@@ -146,34 -174,6 +182,34 @@@ DygraphOptions.prototype.getForSeries return seriesOptions[name]; } - return this.findForAxis(name, seriesObj["yAxis"]); - } + return this.getForAxis(name, seriesObj["yAxis"]); + }; +/** + * Returns the number of y-axes on the chart. + * @return {Number} the number of axes. + */ +DygraphOptions.prototype.numAxes = function() { + return this.axes_.length; +} + +/** + * Return the y-axis for a given series, specified by name. + */ +DygraphOptions.prototype.axisForSeries = function(seriesName) { + return this.series_[seriesName].yAxis; +} + +/** + * Returns the options for the specified axis. + */ +DygraphOptions.prototype.axisOptions = function(yAxis) { + return this.axes_[yAxis].options; +} + +/** + * Return the series associated with an axis. + */ +DygraphOptions.prototype.seriesForAxis = function(yAxis) { + return this.axes_[yAxis].series; +} diff --cc dygraph.js index 42761cf,3783907..4b275d9 --- a/dygraph.js +++ b/dygraph.js @@@ -569,7 -573,8 +573,7 @@@ Dygraph.prototype.attr_ = function(name Dygraph.OPTIONS_REFERENCE[name] = true; } // - return seriesName ? this.attributes_.findForSeries(name, seriesName) : this.attributes_.find(name); - + return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name); }; /**