X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-utils.js;h=98128e317f53a6da1b1a11903d457d863e32df11;hb=5108eb2029afe739872ebfb58f9fb826cef9ea13;hp=2ba6ab5c9951e37808951c4a26e70649b4dc7074;hpb=9ca829f2675e0be2e35d67d45dd91cc28c9c2cfe;p=dygraphs.git diff --git a/dygraph-utils.js b/dygraph-utils.js index 2ba6ab5..98128e3 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -1,5 +1,5 @@ // Copyright 2011 Dan Vanderkam (danvdk@gmail.com) -// All Rights Reserved. +// MIT-licensed (http://opensource.org/licenses/MIT) /** * @fileoverview This file contains utility functions used by dygraphs. These @@ -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) {