remove all traces of Dygraph.log
[dygraphs.git] / plugins / range-selector.js
index 09c98bb..8842546 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) {
@@ -74,7 +74,7 @@ rangeSelector.prototype.createInterface_ = function() {
 
   // Range selector and animatedZooms have a bad interaction. See issue 359.
   if (this.getOption_('animatedZooms')) {
-    Dygraph.warn('Animated zooms and range selector are not compatible; disabling animatedZooms.');
+    console.warn('Animated zooms and range selector are not compatible; disabling animatedZooms.');
     this.dygraph_.updateOptions({animatedZooms: false}, true);
   }
 
@@ -268,7 +268,7 @@ rangeSelector.prototype.createZoomHandles_ = function() {
  */
 rangeSelector.prototype.initInteraction_ = function() {
   var self = this;
-  var topElem = this.isIE_ ? document : window;
+  var topElem = document;
   var clientXLast = 0;
   var handle = null;
   var isZooming = false;
@@ -541,11 +541,11 @@ rangeSelector.prototype.initInteraction_ = function() {
 rangeSelector.prototype.drawStaticLayer_ = function() {
   var ctx = this.bgcanvas_ctx_;
   ctx.clearRect(0, 0, this.canvasRect_.w, this.canvasRect_.h);
-  // try {
+  try {
     this.drawMiniPlot_();
-  // } catch(ex) {
-  //   Dygraph.warn(ex);
-  // }
+  } catch(ex) {
+    console.warn(ex);
+  }
 
   var margin = 0.5;
   this.bgcanvas_ctx_.lineWidth = 1;
@@ -645,21 +645,30 @@ rangeSelector.prototype.drawMiniPlot_ = function() {
  */
 rangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
   var g = this.dygraph_;
-  var data = g.rawData_;
   var logscale = this.getOption_('logscale');
+  var 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 all series values).
-  var sum;
-  var count;
-  var mutipleValues;
-  var i, j, k;
-  var xVal, yVal;
-
+  // 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 (var i = 1; i < g.numColumns(); i++) {
+  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);
@@ -672,7 +681,7 @@ rangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
   for (i = 0; i < rolledSeries[0].length; i++) {
     var sum = 0;
     var count = 0;
-    for (j = 0; j < rolledSeries.length; j++) {
+    for (var j = 0; j < rolledSeries.length; j++) {
       var y = rolledSeries[j][i][1];
       if (y === null || isNaN(y)) continue;
       count++;
@@ -685,7 +694,7 @@ rangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
   var yMin = Number.MAX_VALUE;
   var yMax = -Number.MAX_VALUE;
   for (i = 0; i < combinedSeries.length; i++) {
-    yVal = combinedSeries[i][1];
+    var yVal = combinedSeries[i][1];
     if (yVal !== null && isFinite(yVal) && (!logscale || yVal > 0)) {
       yMin = Math.min(yMin, yVal);
       yMax = Math.max(yMax, yVal);