X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-utils.js;h=7282c9c4df53e2371a37e0db6657130bd8546899;hb=b941564d6f1d2791c6b9714bd089bd19f4ca67b3;hp=11a2fba2f76861806fde946af6be631083e9d8ca;hpb=745e9e52bf0c9fe1eec18ad64d76787419b033f4;p=dygraphs.git diff --git a/dygraph-utils.js b/dygraph-utils.js index 11a2fba..7282c9c 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -79,7 +79,7 @@ Dygraph.log = function(severity, message) { // In older versions of Firefox, only console.log is defined. var console = window.console; var log = function(console, method, msg) { - if (method) { + if (method && typeof(method) == 'function') { method.call(console, msg); } else { console.log(msg); @@ -135,7 +135,6 @@ Dygraph.prototype.warn = Dygraph.warn; /** * @param {string} message - * @private */ Dygraph.error = function(message) { Dygraph.log(Dygraph.ERROR, message); @@ -193,7 +192,7 @@ Dygraph.addEvent = function addEvent(elem, type, fn) { * on the event. The function takes one parameter: the event object. * @private */ -Dygraph.prototype.addEvent = function(elem, type, fn) { +Dygraph.prototype.addAndTrackEvent = function(elem, type, fn) { Dygraph.addEvent(elem, type, fn); this.registeredEvents_.push({ elem : elem, type : type, fn : fn }); }; @@ -221,6 +220,17 @@ Dygraph.removeEvent = function(elem, type, fn) { } }; +Dygraph.prototype.removeTrackedEvents_ = function() { + if (this.registeredEvents_) { + for (var idx = 0; idx < this.registeredEvents_.length; idx++) { + var reg = this.registeredEvents_[idx]; + Dygraph.removeEvent(reg.elem, reg.type, reg.fn); + } + } + + this.registeredEvents_ = []; +} + /** * Cancels further processing of an event. This is useful to prevent default * browser actions, e.g. highlighting text on a double-click. @@ -634,7 +644,6 @@ Dygraph.dateStrToMillis = function(str) { * @param {!Object} self * @param {!Object} o * @return {!Object} - * @private */ Dygraph.update = function(self, o) { if (typeof(o) != 'undefined' && o !== null) { @@ -818,7 +827,7 @@ Dygraph.Iterator.prototype.next = function() { }; /** - * Returns a new iterator over array, between indexes start and + * Returns a new iterator over array, between indexes start and * start + length, and only returns entries that pass the accept function * * @param {!Array} array the array to iterate over. @@ -908,7 +917,7 @@ Dygraph.repeatAndCleanup = function(repeatFn, maxFrames, framePeriodInMillis, * This function will scan the option list and determine if they * require us to recalculate the pixel positions of each point. * @param {!Array.} labels a list of options to check. - * @param {!Object} attrs + * @param {!Object} attrs * @return {boolean} true if the graph needs new points else false. * @private */ @@ -1012,7 +1021,7 @@ Dygraph.isPixelChangingOptionList = function(labels, attrs) { /** * Compares two arrays to see if they are equal. If either parameter is not an - * array it will return false. Does a shallow compare + * array it will return false. Does a shallow compare * Dygraph.compareArrays([[1,2], [3, 4]], [[1,2], [3,4]]) === false. * @param {!Array.} array1 first array * @param {!Array.} array2 second array @@ -1057,7 +1066,7 @@ Dygraph.regularShape_ = function( var computeCoordinates = function() { var x = cx + (Math.sin(angle) * radius); var y = cy + (-Math.cos(angle) * radius); - return [x, y]; + return [x, y]; }; var initialCoordinates = computeCoordinates(); @@ -1165,7 +1174,7 @@ Dygraph.Circles = { * }; * window.addEventListener('mouseup', mouseUpHandler); * }; - * + * * @constructor */ Dygraph.IFrameTarp = function() { @@ -1236,20 +1245,21 @@ Dygraph.detectLineDelimiter = function(data) { }; /** - * Is one element contained by another? - * @param {Element} containee The contained element. - * @param {Element} container The container element. + * Is one node contained by another? + * @param {Node} containee The contained node. + * @param {Node} container The container node. * @return {boolean} Whether containee is inside (or equal to) container. * @private */ -Dygraph.isElementContainedBy = function(containee, container) { +Dygraph.isNodeContainedBy = function(containee, container) { if (container === null || containee === null) { return false; } - while (containee && containee !== container) { - containee = containee.parentNode; + var containeeNode = /** @type {Node} */ (containee); + while (containeeNode && containeeNode !== container) { + containeeNode = containeeNode.parentNode; } - return (containee === container); + return (containeeNode === container); };