rework option as showInRangeSelector
authorDan Vanderkam <danvdk@gmail.com>
Tue, 4 Nov 2014 23:35:00 +0000 (18:35 -0500)
committerDan Vanderkam <danvdk@gmail.com>
Tue, 4 Nov 2014 23:36:52 +0000 (18:36 -0500)
auto_tests/tests/range_selector.js
dygraph-options-reference.js
dygraph.js
plugins/range-selector.js
tests/range-selector.html

index 1f4dfe8..aed2b3e 100644 (file)
@@ -455,8 +455,11 @@ RangeSelectorTestCase.prototype.testCombinedSeries = function() {
 RangeSelectorTestCase.prototype.testSelectedCombinedSeries = function() {
   var opts = {
     showRangeSelector: true,
-    rangeSelectorCombinedSeries: [1, 3], // first and third series averaged, second skipped
-    labels: ['X', 'Y1', 'Y2', 'Y3', 'Y4']
+    labels: ['X', 'Y1', 'Y2', 'Y3', 'Y4'],
+    series: {
+      'Y1': { showInRangeSelector: true },
+      'Y3': { showInRangeSelector: true }
+    }
   };
   var data = [
       [0, 5, 8, 13, 21],  // average (first and third) = 9
index d31a794..75af59e 100644 (file)
@@ -793,11 +793,11 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "type": "string",
     "description": "The range selector mini plot fill color. This can be of the form \"#AABBCC\" or \"rgb(255,100,200)\" or \"yellow\". You can also specify null or \"\" to turn off fill."
   },
-  "rangeSelectorCombinedSeries": {
+  "showInRangeSelector": {
     "default": "null",
     "labels": ["Interactive Elements"],
-    "type": "array<integer>",
-    "description": "Array of series indexes (1 being the first serie) to combine for drawing the mini plot. The mini plot curve will be an average of these series. If \"null\", all series are combined."
+    "type": "boolean",
+    "description": "Mark this series for inclusion in the range selector. The mini plot curve will be an average of all such series. If this is not specified for any series, the default behavior is to average all the series. Setting it for one series will result in that series being charted alone in the range selector."
   },
   "animatedZooms": {
     "default": "false",
index bbfb3d8..366323a 100644 (file)
@@ -320,7 +320,7 @@ Dygraph.DEFAULT_ATTRS = {
   rangeSelectorHeight: 40,
   rangeSelectorPlotStrokeColor: "#808FAB",
   rangeSelectorPlotFillColor: "#A7B1C4",
-  rangeSelectorCombinedSeries: null,
+  showInRangeSelector: null,
 
   // The ordering here ensures that central lines always appear above any
   // fill bars/error bars.
index e7e9362..3a70e7d 100644 (file)
@@ -52,8 +52,8 @@ rangeSelector.prototype.destroy = function() {
 // Private methods
 //------------------------------------------------------------------
 
-rangeSelector.prototype.getOption_ = function(name) {
-  return this.dygraph_.getOption(name);
+rangeSelector.prototype.getOption_ = function(name, opt_series) {
+  return this.dygraph_.getOption(name, opt_series);
 };
 
 rangeSelector.prototype.setDefaultOption_ = function(name, value) {
@@ -646,30 +646,30 @@ rangeSelector.prototype.drawMiniPlot_ = function() {
 rangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
   var g = this.dygraph_;
   var logscale = this.getOption_('logscale');
-
-  // Create a combined series (average of selected series values).
   var i;
 
-  // Select series to combine
-  var selectedSeries = this.getOption_('rangeSelectorCombinedSeries');
-
-  // Default: select all series
-  if (selectedSeries === null) {
-    var numColumns = g.numColumns();
-    selectedSeries = new Array(numColumns - 1);
-
-    for (i = 1; i < numColumns; i++) {
-      selectedSeries[i - 1] = i;
-    }
+  // Select series to combine. By default, all series are combined.
+  var numColumns = g.numColumns();
+  var labels = g.getLabels();
+  var includeSeries = new Array(numColumns);
+  var anySet = false;
+  for (i = 1; i < numColumns; i++) {
+    var include = this.getOption_('showInRangeSelector', labels[i]);
+    includeSeries[i] = include;
+    if (include !== null) anySet = true;  // it's set explicitly for this series
+  }
+  if (!anySet) {
+    for (i = 0; i < includeSeries.length; i++) includeSeries[i] = true;
   }
 
+  // Create a combined series (average of selected series values).
   // TODO(danvk): short-circuit if there's only one series.
   var rolledSeries = [];
   var dataHandler = g.dataHandler_;
   var options = g.attributes_;
-  for (i = 0; i < selectedSeries.length; i++) {
-    var seriesIndex = selectedSeries[i];
-    var series = dataHandler.extractSeries(g.rawData_, seriesIndex, options);
+  for (i = 1; i < g.numColumns(); i++) {
+    if (!includeSeries[i]) continue;
+    var series = dataHandler.extractSeries(g.rawData_, i, options);
     if (g.rollPeriod() > 1) {
       series = dataHandler.rollingAverage(series, g.rollPeriod(), options);
     }
index c5c973b..52792dd 100644 (file)
@@ -30,7 +30,7 @@
     </p>
     <div id="roll14" style="width:800px; height:320px;"></div>
     <p>
-      Use the average of a specific subset of series to draw the mini plot (only the first serie is used in this test).
+      Use the average of a specific subset of series to draw the mini plot (only the first series is used in this test).
       The default behaviour is to compute the average of <em>all</em> series.
     </p>
     <div id="selectcombined" style="width:800px; height:320px;"></div>
             title: 'Daily Temperatures in New York vs. San Francisco',
             ylabel: 'Temperature (F)',
             showRangeSelector: true,
-            rangeSelectorCombinedSeries: [1]
+            labels: ['X', 'Y1', 'Y2', 'Y3'],
+            series: {
+              'Y1': { showInRangeSelector: true }
+            }
           }
       );
       g4 = new Dygraph(