Support boolean array in setVisibility
[dygraphs.git] / auto_tests / tests / Util.js
index 7c1eaa6..3b8c1b8 100644 (file)
@@ -51,11 +51,16 @@ Util.getClassTexts = function(css_class, parent) {
   return texts;
 };
 
+// Convert   to a normal space
+Util.nbspToSpace = function(str) {
+  var re = new RegExp(String.fromCharCode(160), 'g');
+  return str.replace(re, ' ');
+};
+
 Util.getLegend = function(parent) {
   parent = parent || document;
   var legend = parent.getElementsByClassName("dygraph-legend")[0];
-  var re = new RegExp(String.fromCharCode(160), 'g');
-  return legend.textContent.replace(re, ' ');
+  return Util.nbspToSpace(legend.textContent);
 };
 
 /**
@@ -142,3 +147,24 @@ Util.overrideXMLHttpRequest = function(data) {
 Util.formatDate = function(dateMillis) {
   return Dygraph.dateString_(dateMillis).slice(0, 10);  // 10 == "YYYY/MM/DD".length
 };
+
+/**
+ * Capture console.{log,warn,error} statements into obj.
+ * obj will look like {log:[], warn:[], error:[]}
+ * This returns a function which will restore the original console.
+ */
+Util.captureConsole = function(obj) {
+  obj.log = [];
+  obj.warn = [];
+  obj.error = [];
+  var orig = [console.log, console.warn, console.error];
+  console.log = function(text) { obj.log.push(text); };
+  console.warn = function(text) { obj.warn.push(text); };
+  console.error = function(text) { obj.error.push(text); };
+
+  return function() {
+    console.log = orig[0];
+    console.warn = orig[1];
+    console.error = orig[2];
+  };
+};