Merge pull request #199 from witsa/master
authorDan Vanderkam <danvdk@gmail.com>
Fri, 1 Feb 2013 17:21:51 +0000 (09:21 -0800)
committerDan Vanderkam <danvdk@gmail.com>
Fri, 1 Feb 2013 17:21:51 +0000 (09:21 -0800)
some robustness and partial auto value range

1  2 
dygraph.js

diff --combined dygraph.js
@@@ -956,20 -956,19 +956,20 @@@ Dygraph.prototype.createInterface_ = fu
  
    var dygraph = this;
  
 -  // 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_);
 +  this.mouseMoveHandler_ = function(e) {
 +    dygraph.mouseMove_(e);
 +  };
  
 -    this.mouseOutHandler_ = function(e) {
 -      dygraph.mouseOut_(e);
 -    };
 -    this.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler_);
 +  this.mouseOutHandler_ = function(e) {
 +    dygraph.mouseOut_(e);
 +  };
  
 +  this.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler_);
 +  this.addEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler_);
 +
 +  // Don't recreate and register the resize handler on subsequent calls.
 +  // This happens when the graph is resized.
 +  if (!this.resizeHandler_) {
      this.resizeHandler_ = function(e) {
        dygraph.resize();
      };
@@@ -993,10 -992,13 +993,13 @@@ Dygraph.prototype.destroy = function() 
      }
    };
  
-   for (var idx = 0; idx < this.registeredEvents_.length; idx++) {
-     var reg = this.registeredEvents_[idx];
-     Dygraph.removeEvent(reg.elem, reg.type, reg.fn);
+   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_ = [];
  
    // remove mouse event handlers (This may not be necessary anymore)
@@@ -1278,12 -1280,6 +1281,12 @@@ Dygraph.prototype.createDragInterface_ 
          bindHandler(interactionModel[eventName]));
    }
  
 +  // unregister the handler on subsequent calls.
 +  // This happens when the graph is resized.
 +  if (this.mouseUpHandler_) {
 +    Dygraph.removeEvent(document, 'mouseup', this.mouseUpHandler_);
 +  }
 +
    // If the user releases the mouse button during a drag, but not over the
    // canvas, then it doesn't count as a zooming action.
    this.mouseUpHandler_ = function(event) {
@@@ -2500,6 -2496,10 +2503,10 @@@ Dygraph.prototype.axisPropertiesForSeri
   * 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();
  
        axis.computedValueRange = [axis.valueWindow[0], axis.valueWindow[1]];
      } else if (axis.valueRange) {
        // This is a user-set value range for this axis.
-       axis.computedValueRange = [axis.valueRange[0], axis.valueRange[1]];
+       axis.computedValueRange = [
+          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;
      }