From: Dan Vanderkam
Date: Tue, 4 Nov 2014 23:35:00 +0000 (-0500)
Subject: rework option as showInRangeSelector
X-Git-Tag: v1.1.0~34
X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=0a0885d1383321a67155fcf1cb12c583cdd89ef2;p=dygraphs.git
rework option as showInRangeSelector
---
diff --git a/auto_tests/tests/range_selector.js b/auto_tests/tests/range_selector.js
index 1f4dfe8..aed2b3e 100644
--- a/auto_tests/tests/range_selector.js
+++ b/auto_tests/tests/range_selector.js
@@ -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
diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js
index d31a794..75af59e 100644
--- a/dygraph-options-reference.js
+++ b/dygraph-options-reference.js
@@ -793,11 +793,11 @@ Dygraph.OPTIONS_REFERENCE = //
"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",
- "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",
diff --git a/dygraph.js b/dygraph.js
index bbfb3d8..366323a 100644
--- a/dygraph.js
+++ b/dygraph.js
@@ -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.
diff --git a/plugins/range-selector.js b/plugins/range-selector.js
index e7e9362..3a70e7d 100644
--- a/plugins/range-selector.js
+++ b/plugins/range-selector.js
@@ -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);
}
diff --git a/tests/range-selector.html b/tests/range-selector.html
index c5c973b..52792dd 100644
--- a/tests/range-selector.html
+++ b/tests/range-selector.html
@@ -30,7 +30,7 @@
- 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 all series.
@@ -81,7 +81,10 @@
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(