Add auto test for isolated and gap points.
[dygraphs.git] / dygraph.js
index 47c6d2c..06abf97 100644 (file)
@@ -424,16 +424,11 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
       pluginOptions: {}
     };
 
-    var registerer = (function(pluginDict) {
-      return {
-        addEventListener: function(eventName, callback) {
-          // TODO(danvk): validate eventName.
-          pluginDict.events[eventName] = callback;
-        }
-      };
-    })(pluginDict);
-    pluginInstance.activate(this, registerer);
-    // TODO(danvk): prevent activate() from holding a reference to registerer.
+    var handlers = pluginInstance.activate(this);
+    for (var eventName in handlers) {
+      // TODO(danvk): validate eventName.
+      pluginDict.events[eventName] = handlers[eventName];
+    }
 
     this.plugins_.push(pluginDict);
   }
@@ -485,11 +480,13 @@ Dygraph.prototype.cascadeEvents_ = function(name, extra_props) {
   Dygraph.update(e, extra_props);
 
   var callback_plugin_pairs = this.eventListeners_[name];
-  for (var i = callback_plugin_pairs.length - 1; i >= 0; i--) {
-    var plugin = callback_plugin_pairs[i][0];
-    var callback = callback_plugin_pairs[i][1];
-    callback.call(plugin, e);
-    if (e.propagationStopped) break;
+  if (callback_plugin_pairs) {
+    for (var i = callback_plugin_pairs.length - 1; i >= 0; i--) {
+      var plugin = callback_plugin_pairs[i][0];
+      var callback = callback_plugin_pairs[i][1];
+      callback.call(plugin, e);
+      if (e.propagationStopped) break;
+    }
   }
   return e.defaultPrevented;
 };
@@ -988,14 +985,14 @@ Dygraph.prototype.destroy = function() {
  
   for (var idx = 0; idx < this.registeredEvents_.length; idx++) {
     var reg = this.registeredEvents_[idx];
-    this.removeEvent(reg.elem, reg.type, reg.fn);
+    Dygraph.removeEvent(reg.elem, reg.type, reg.fn);
   }
   this.registeredEvents_ = [];
 
   // remove mouse event handlers (This may not be necessary anymore)
-  this.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler);
-  this.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler);
-  this.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_);
+  Dygraph.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler);
+  Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler);
+  Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_);
   removeRecursive(this.maindiv_);
 
   var nullOut = function(obj) {
@@ -1006,7 +1003,7 @@ Dygraph.prototype.destroy = function() {
     }
   };
   // remove event handlers
-  this.removeEvent(window,'resize',this.resizeHandler);
+  Dygraph.removeEvent(window,'resize',this.resizeHandler);
   this.resizeHandler = null;
   // These may not all be necessary, but it can't hurt...
   nullOut(this.layout_);