Factor out ticker functions and clean up their semantics/usage.
[dygraphs.git] / dygraph-utils.js
index 2ba6ab5..7cb5019 100644 (file)
@@ -343,30 +343,6 @@ Dygraph.hmsString_ = function(date) {
 };
 
 /**
- * Convert a JS date (millis since epoch) to YYYY/MM/DD
- * @param {Number} date The JavaScript date (ms since epoch)
- * @return {String} A date of the form "YYYY/MM/DD"
- * @private
- */
-Dygraph.dateString_ = function(date) {
-  var zeropad = Dygraph.zeropad;
-  var d = new Date(date);
-
-  // Get the year:
-  var year = "" + d.getFullYear();
-  // Get a 0 padded month string
-  var month = zeropad(d.getMonth() + 1);  //months are 0-offset, sigh
-  // Get a 0 padded day string
-  var day = zeropad(d.getDate());
-
-  var ret = "";
-  var frac = d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();
-  if (frac) ret = " " + Dygraph.hmsString_(date);
-
-  return year + "/" + month + "/" + day + ret;
-};
-
-/**
  * Round a number to the specified number of digits past the decimal point.
  * @param {Number} num The number to round
  * @param {Number} places The number of decimals to which to round
@@ -495,6 +471,33 @@ Dygraph.update = function (self, o) {
 };
 
 /**
+ * Copies all the properties from o to self.
+ *
+ * @private
+ */
+Dygraph.updateDeep = function (self, o) {
+  if (typeof(o) != 'undefined' && o !== null) {
+    for (var k in o) {
+      if (o.hasOwnProperty(k)) {
+        if (o[k] == null) {
+          self[k] = null;
+        } else if (Dygraph.isArrayLike(o[k])) {
+          self[k] = o[k].slice();
+        } else if (typeof(o[k]) == 'object') {
+          if (typeof(self[k]) != 'object') {
+            self[k] = {};
+          }
+          Dygraph.updateDeep(self[k], o[k]);
+        } else {
+          self[k] = o[k];
+        }
+      }
+    }
+  }
+  return self;
+};
+
+/**
  * @private
  */
 Dygraph.isArrayLike = function (o) {
@@ -523,6 +526,7 @@ Dygraph.isDateLike = function (o) {
 };
 
 /**
+ * Note: this only seems to work for arrays.
  * @private
  */
 Dygraph.clone = function(o) {