X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-options.js;h=f059ff9cbd9eee70232a875fd5ad8414fbfb9fe7;hb=d574a45ea4f06abe9b65be39a2ae4991f59257f3;hp=f734c5da470b5b4c1e2dcbe9b656e904cb02d321;hpb=6ad8b6a444ae32d026264409698f496506b3d33b;p=dygraphs.git diff --git a/dygraph-options.js b/dygraph-options.js index f734c5d..f059ff9 100644 --- a/dygraph-options.js +++ b/dygraph-options.js @@ -57,20 +57,24 @@ DygraphOptions.AXIS_STRING_MAPPINGS_ = { 'Y1' : 0, 'y2' : 1, 'Y2' : 1 -} +}; DygraphOptions.axisToIndex_ = function(axis) { if (typeof(axis) == "string") { if (DygraphOptions.AXIS_STRING_MAPPINGS_.hasOwnProperty(axis)) { return DygraphOptions.AXIS_STRING_MAPPINGS_[axis]; } - throw "Unknown axis : " + text; + throw "Unknown axis : " + axis; } if (typeof(axis) == "number") { - if (axis == 0 || axis == 1) { + if (axis === 0 || axis === 1) { return axis; } - throw "Dygraphs only supports two y-axes, indexed from 0-1." + throw "Dygraphs only supports two y-axes, indexed from 0-1."; + } + if (typeof(axis) == "object") { + throw "Using objects for axis specification " + + "is not supported inside the 'series' option."; } if (axis) { throw "Unknown axis : " + axis; @@ -157,15 +161,11 @@ DygraphOptions.prototype.reparseSeries = function() { } } } else { - var maxYAxis = 0; - for (var idx = 0; idx < this.labels.length; idx++) { var seriesName = this.labels[idx]; var optionsForSeries = this.user_.series[seriesName] || {}; var yAxis = DygraphOptions.axisToIndex_(optionsForSeries["axis"]); - maxYAxis = Math.max(yAxis, maxYAxis); - this.series_[seriesName] = { idx: idx, yAxis: yAxis, @@ -193,14 +193,29 @@ DygraphOptions.prototype.reparseSeries = function() { * @param {String} name the name of the option. */ DygraphOptions.prototype.get = function(name) { + var result = this.getGlobalUser_(name); + if (result != null) { + return result; + } + return this.getGlobalDefault_(name); +}; + +DygraphOptions.prototype.getGlobalUser_ = function(name) { if (this.user_.hasOwnProperty(name)) { return this.user_[name]; } + return null; +}; + +DygraphOptions.prototype.getGlobalDefault_ = function(name) { if (this.global_.hasOwnProperty(name)) { return this.global_[name]; } + if (Dygraph.DEFAULT_ATTRS.hasOwnProperty(name)) { + return Dygraph.DEFAULT_ATTRS[name]; + } return null; -}; +} /** * Get a value for a specific axis. If there is no specific value for the axis, @@ -218,12 +233,29 @@ DygraphOptions.prototype.getForAxis = function(name, axis) { // TODO(konigsberg): Accept only valid axis strings? axisIdx = (axis == "y2") ? 1 : 0; } + // Search the user-specified axis option first. + if (this.axes_[axisIdx]) { + var axisOptions = this.axes_[axisIdx].options; + if (axisOptions.hasOwnProperty(name)) { + return axisOptions[name]; + } + } + + // User-specified global options second. + var result = this.getGlobalUser_(name); + if (result != null) { + return result; + } - var axisOptions = this.axes_[axisIdx].options; - if (axisOptions.hasOwnProperty(name)) { - return axisOptions[name]; + // Default axis options third. + var axisString = axis == 0 ? "y" : "y2"; + var defaultAxisOptions = Dygraph.DEFAULT_ATTRS.axes[axisString]; + if (defaultAxisOptions.hasOwnProperty(name)) { + return defaultAxisOptions[name]; } - return this.get(name); + + // Default global options last. + return this.getGlobalDefault_(name); }; /** @@ -263,35 +295,35 @@ DygraphOptions.prototype.getForSeries = function(name, series) { */ 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; -} +}; /** * Return the list of all series, in their columnar order. */ DygraphOptions.prototype.seriesNames = function() { return this.labels_; -} +}; /* Are we using this? */ /** @@ -300,4 +332,4 @@ DygraphOptions.prototype.seriesNames = function() { */ DygraphOptions.prototype.indexOfSeries = function(series) { return this.series_[series].idx; -} +};