Merge pull request #657 from kbaggott/master
authorDan Vanderkam <danvdk@gmail.com>
Thu, 24 Sep 2015 17:37:54 +0000 (13:37 -0400)
committerDan Vanderkam <danvdk@gmail.com>
Thu, 24 Sep 2015 17:37:54 +0000 (13:37 -0400)
Fixing issue with xRangePad being ignored on unzoom

auto_tests/tests/visibility.js
docs/users.html
src/dygraph.js
src/extras/synchronizer.js

index e8860c6..5f54639 100644 (file)
@@ -67,4 +67,12 @@ it('testMultiSeriesShow', function() {
   assert.equal(' B  D', getVisibleSeries(false, [[1,3], true]));
 });
 
+it('testObjectSeriesShowAndHide', function() {
+  assert.equal(' B  D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null]));
+});
+
+it('testBooleanArraySeriesShowAndHide', function() {
+  assert.equal(' B  D', getVisibleSeries(false, [[false, true, false, true], null]));
+});
+
 });
index 5c183cc..0f362c5 100644 (file)
       Dygraphs are used in the results page, to display the growth curve and sizing changes (using annotations).
     </span>
   </li>
+
+  <li>
+    <a href="http://cida.usgs.gov/gcmrc/discharge_qw_sediment/">USGS CIDA/GCMRC River Sediment and Discharge</a><br />
+    <span class="desc">
+      The Center for Integrated Data Analytics (CIDA) is using Dygraphs to display timeseries data 
+      collected at USGS gage stations, most prominently on the Colorado River through the Grand 
+      Canyon.  Dygraphs performance was essential for interacting with years of dense timeseries 
+      data in the browser. (<a href="https://github.com/USGS-CIDA/gcmrc-ui-parent">View the code</a>!)
+    </span>
+  </li>
   
   </ul>
 
index f9b0169..a28e231 100644 (file)
@@ -3579,19 +3579,49 @@ Dygraph.prototype.visibility = function() {
 /**
  * Changes the visibility of one or more series.
  *
- * @param {number|number[]} num the series index or an array of series indices
- * @param {boolean} value true or false, identifying the visibility.
+ * @param {number|number[]|object} num the series index or an array of series indices
+ *                                     or a boolean array of visibility states by index
+ *                                     or an object mapping series numbers, as keys, to 
+ *                                     visibility state (boolean values)
+ * @param {boolean} value the visibility state expressed as a boolean
  */
 Dygraph.prototype.setVisibility = function(num, value) {
   var x = this.visibility();
+  var numIsObject = false;
 
-  if (num.constructor !== Array) num = [num];
-
-  for (var i = 0; i < num.length; i++) {
-    if (num[i] < 0 || num[i] >= x.length) {
-      console.warn("invalid series number in setVisibility: " + num[i]);
+  if (!Array.isArray(num)) {
+    if (num !== null && typeof num === 'object') {
+      numIsObject = true;
     } else {
-      x[num[i]] = value;
+      num = [num];
+    }
+  }
+
+  if (numIsObject) {
+    for (var i in num) {
+      if (num.hasOwnProperty(i)) {
+        if (i < 0 || i >= x.length) {
+          console.warn("Invalid series number in setVisibility: " + i);
+        } else {
+          x[i] = num[i];
+        }
+      }
+    }
+  } else {
+    for (var i = 0; i < num.length; i++) {
+      if (typeof num[i] === 'boolean') {
+        if (i >= x.length) {
+          console.warn("Invalid series number in setVisibility: " + i);
+        } else {
+          x[i] = num[i];
+        }
+      } else {
+        if (num[i] < 0 || num[i] >= x.length) {
+          console.warn("Invalid series number in setVisibility: " + num[i]);
+        } else {
+          x[num[i]] = value;
+        }
+      }
     }
   }
 
index 78efbcb..dd4329c 100644 (file)
@@ -170,7 +170,7 @@ function attachZoomHandlers(gs, syncOpts, prevCallbacks) {
         }
         block = false;
       }
-    }, false /* no need to redraw */);
+    }, true /* no need to redraw */);
   }
 }
 
@@ -213,7 +213,7 @@ function attachSelectionHandlers(gs, prevCallbacks) {
         }
         block = false;
       }
-    });
+    }, true /* no need to redraw */);
   }
 }