X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-utils.js;h=63411a599627809693bf15837ee47d466558f39c;hb=0b9ce4de137db60db2476fe7ee9cc05215612e30;hp=689f8eb09d42de8a80e0326bc210f11cb33d252e;hpb=1f882d071485210eaff9cc34483a1105affe8c75;p=dygraphs.git diff --git a/dygraph-utils.js b/dygraph-utils.js index 689f8eb..63411a5 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -147,6 +147,21 @@ Dygraph.addEvent = function addEvent(elem, type, fn) { /** * @private + * Add an event handler. This event handler is kept until the graph is + * destroyed with a call to graph.destroy(). + * + * @param { DOM element } elem The element to add the event to. + * @param { String } type The type of the event, e.g. 'click' or 'mousemove'. + * @param { Function } fn The function to call on the event. The function takes + * one parameter: the event object. + */ +Dygraph.prototype.addEvent = function addEvent(elem, type, fn) { + Dygraph.addEvent(elem, type, fn); + this.registeredEvents_.push({ elem : elem, type : type, fn : fn }); +}; + +/** + * @private * Remove an event handler. This smooths a difference between IE and the rest of * the world. * @param { DOM element } elem The element to add the event to. @@ -494,9 +509,17 @@ Dygraph.dateParser = function(dateStr) { var dateStrSlashed; var d; - // Let the system try the format first. - d = Dygraph.dateStrToMillis(dateStr); - if (d && !isNaN(d)) return d; + // Let the system try the format first, with one caveat: + // YYYY-MM-DD[ HH:MM:SS] is interpreted as UTC by a variety of browsers. + // dygraphs displays dates in local time, so this will result in surprising + // inconsistencies. But if you specify "T" or "Z" (i.e. YYYY-MM-DDTHH:MM:SS), + // then you probably know what you're doing, so we'll let you go ahead. + // Issue: http://code.google.com/p/dygraphs/issues/detail?id=255 + if (dateStr.search("-") == -1 || + dateStr.search("T") != -1 || dateStr.search("Z") != -1) { + d = Dygraph.dateStrToMillis(dateStr); + if (d && !isNaN(d)) return d; + } if (dateStr.search("-") != -1) { // e.g. '2009-7-12' or '2009-07-12' dateStrSlashed = dateStr.replace("-", "/", "g"); @@ -575,7 +598,7 @@ Dygraph.updateDeep = function (self, o) { // DOM objects are shallowly-copied. self[k] = o[k]; } else if (typeof(o[k]) == 'object') { - if (typeof(self[k]) != 'object') { + if (typeof(self[k]) != 'object' || self[k] === null) { self[k] = {}; } Dygraph.updateDeep(self[k], o[k]);