From: Robert Konigsberg Date: Thu, 22 Nov 2012 13:35:23 +0000 (-0500) Subject: Add code to deal with the new, global, series option. X-Git-Tag: v1.0.0~157^2~16 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=73e953cd888d942f7e0610ebaa67a2cefbdaa085;p=dygraphs.git Add code to deal with the new, global, series option. --- diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index abdb015..9f9b532 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -760,6 +760,12 @@ Dygraph.OPTIONS_REFERENCE = // "type": "array or function", "description": "A function (or array of functions) which plot each data series on the chart. TODO(danvk): more details! May be set per-series." } + "series": { + "default": "null", + "labels": ["Series"], + "type": "Object" + "description": "Defines per-series options. Its keys match the y-axis label names, and the values are dictionaries themselves that contain options specific to that series. When this option is missing, it falls back on the old-style of per-series options comingled with global options." + } } ; // // NOTE: in addition to parsing as JS, this snippet is expected to be valid diff --git a/dygraph-options.js b/dygraph-options.js index cc8c770..569d5c8 100644 --- a/dygraph-options.js +++ b/dygraph-options.js @@ -49,12 +49,36 @@ DygraphOptions.prototype.reparseSeries = function() { this.axes_ = [ {} ]; // Always one axis at least. this.series_ = {}; + // Traditionally, per-series options were specified right up there with the options. For instance + // { + // labels: [ "X", "foo", "bar" ], + // pointSize: 3, + // foo : {}, // options for foo + // bar : {} // options for bar + // } + // + // Moving forward, series really should be specified in the series element, separating them. + // like so: + // + // { + // labels: [ "X", "foo", "bar" ], + // pointSize: 3, + // series : { + // foo : {}, // options for foo + // bar : {} // options for bar + // } + // } + // + // So, if series is found, it's expected to contain per-series data, otherwise we fall + // back. + var allseries = this.user_.hasOwnProperty("series") ? this.user_.series : this.user_; + 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++) { var seriesName = this.labels[idx]; - var optionsForSeries = this.user_[seriesName] || {}; + var optionsForSeries = allseries[seriesName] || {}; var yAxis = 0; var axis = optionsForSeries["axis"];