Changing name of isUnspecifiedLimit function to isNullUndefinedOrNaN
[dygraphs.git] / dygraph.js
index b516f5e..63b2edb 100644 (file)
@@ -956,29 +956,27 @@ Dygraph.prototype.createInterface_ = function() {
 
   var dygraph = this;
 
-  this.mouseMoveHandler = function(e) {
-    dygraph.mouseMove_(e);
-  };
-  this.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler);
-
-  this.mouseOutHandler = function(e) {
-    dygraph.mouseOut_(e);
-  };
-  this.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler);
+  // Don't recreate and register the handlers on subsequent calls.
+  // This happens when the graph is resized.
+  if (!this.mouseMoveHandler_) {
+    this.mouseMoveHandler_ = function(e) {
+      dygraph.mouseMove_(e);
+    };
+    this.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
 
-  if (this.resizeHandler) {
-    // remove handler because it's already setup.
-    Dygraph.removeEvent(window, 'resize', this.resizeHandler);
-  }
+    this.mouseOutHandler_ = function(e) {
+      dygraph.mouseOut_(e);
+    };
+    this.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler_);
 
-  this.resizeHandler = function(e) {
-    dygraph.resize();
-  };
+    this.resizeHandler_ = function(e) {
+      dygraph.resize();
+    };
 
-  // Update when the window is resized.
-  // TODO(danvk): drop frames depending on complexity of the chart.
-  this.addEvent(window, 'resize', this.resizeHandler);
+    // Update when the window is resized.
+    // TODO(danvk): drop frames depending on complexity of the chart.
+    this.addEvent(window, 'resize', this.resizeHandler_);
+  }
 };
 
 /**
@@ -1004,9 +1002,14 @@ Dygraph.prototype.destroy = function() {
   this.registeredEvents_ = [];
 
   // remove mouse event handlers (This may not be necessary anymore)
-  Dygraph.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler);
-  Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler);
+  Dygraph.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler_);
+  Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
   Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_);
+
+  // remove window handlers
+  Dygraph.removeEvent(window,'resize',this.resizeHandler_);
+  this.resizeHandler_ = null;
+
   removeRecursive(this.maindiv_);
 
   var nullOut = function(obj) {
@@ -1016,9 +1019,6 @@ Dygraph.prototype.destroy = function() {
       }
     }
   };
-  // remove event handlers
-  Dygraph.removeEvent(window,'resize',this.resizeHandler);
-  this.resizeHandler = null;
   // These may not all be necessary, but it can't hurt...
   nullOut(this.layout_);
   nullOut(this.plotter_);
@@ -2367,9 +2367,7 @@ Dygraph.prototype.drawGraph_ = function() {
 
   if (this.attr_("timingName")) {
     var end = new Date();
-    if (console) {
-      console.log(this.attr_("timingName") + " - drawGraph: " + (end - start) + "ms");
-    }
+    Dygraph.info(this.attr_("timingName") + " - drawGraph: " + (end - start) + "ms");
   }
 };
 
@@ -2498,6 +2496,10 @@ Dygraph.prototype.axisPropertiesForSeries = function(series) {
  * This fills in the valueRange and ticks fields in each entry of this.axes_.
  */
 Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
+  
+  var isNullUndefinedOrNaN = function(num) {
+    return isNaN(parseFloat(num));
+  };
   var series;
   var numAxes = this.attributes_.numAxes();
 
@@ -2571,8 +2573,8 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
     } else if (axis.valueRange) {
       // This is a user-set value range for this axis.
       axis.computedValueRange = [
-         !isNaN(axis.valueRange[0]) ? axis.valueRange[0] : axis.extremeRange[0],
-         !isNaN(axis.valueRange[1]) ? axis.valueRange[1] : axis.extremeRange[1]
+         isNullUndefinedOrNaN(axis.valueRange[0]) ? axis.extremeRange[0] : axis.valueRange[0],
+         isNullUndefinedOrNaN(axis.valueRange[1]) ? axis.extremeRange[1] : axis.valueRange[1]
       ];
     } else {
       axis.computedValueRange = axis.extremeRange;