X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-options.js;h=9227870eb31ae8e8fd52ce08185195a505928d69;hb=eb0da59f0c6983b201d0479f02f3c871ebb8324e;hp=562fa244ede9ce4773e0b4b70e48ca42f092ce91;hpb=c1780ad0fcfaa98acb399c976176ebefb25c8794;p=dygraphs.git diff --git a/dygraph-options.js b/dygraph-options.js index 562fa24..9227870 100644 --- a/dygraph-options.js +++ b/dygraph-options.js @@ -33,8 +33,21 @@ var DygraphOptions = function(dygraph) { this.global_user = this.dygraph_.user_attrs_ || {}; // Get a list of series names. + + var labels = this.find("labels"); + if (!labels) { + return; // -- can't do more for now, will parse after getting the labels. + }; + + this.reparseSeries(); +} + +DygraphOptions.prototype.reparseSeries = function() { this.labels = this.find("labels").slice(1); + this.axes = [ {} ]; // Always one axis at least. + this.series = {}; + var axisId = 0; // 0-offset; there's always one. // Go through once, add all the series, and for those with {} axis options, add a new axis. for (var idx = 0; idx < this.labels.length; idx++) { @@ -46,6 +59,7 @@ var DygraphOptions = function(dygraph) { var axis = optionsForSeries["axis"]; if (typeof(axis) == 'object') { yAxis = ++axisId; + this.axes[yAxis] = axis; } this.series[seriesName] = { idx: idx, yAxis: yAxis, options : optionsForSeries }; } @@ -72,10 +86,14 @@ var DygraphOptions = function(dygraph) { if (this.global_user.hasOwnProperty("axes")) { var axis_opts = this.global_user.axes; - this.axes.push(axis_opts["y"] || {}); - this.axes.push(axis_opts["y2"] || {}); - } else { - this.axes.push(axis_opts["y"] || {}); // There has to be at least one axis. + if (axis_opts.hasOwnProperty("y")) { + Dygraph.update(this.axes[0], axis_opts.y); + } + + if (axis_opts.hasOwnProperty("y2")) { + this.axes[1] = this.axes[1] || {}; + Dygraph.update(this.axes[1], axis_opts.y2); + } } }; @@ -91,7 +109,7 @@ DygraphOptions.prototype.find = function(name) { DygraphOptions.prototype.findForAxis = function(name, axis) { - var axisIdx = (axis == "y2" || axis == 1) ? 1 : 0; + var axisIdx = (axis == "y2" || axis == "y2" || axis == 1) ? 1 : 0; var axisOptions = this.axes[axisIdx]; if (axisOptions.hasOwnProperty(name)) {