guard window.getComputedStyle call for IE8
[dygraphs.git] / dygraph.js
index 458ec45..1f55870 100644 (file)
@@ -95,6 +95,8 @@ Dygraph.DEFAULT_HEIGHT = 320;
 Dygraph.ANIMATION_STEPS = 12;
 Dygraph.ANIMATION_DURATION = 200;
 
+// Label constants for the labelsKMB and labelsKMG2 options.
+// (i.e. '100000' -> '100K')
 Dygraph.KMB_LABELS = [ 'K', 'M', 'B', 'T', 'Q' ];
 Dygraph.KMG2_BIG_LABELS = [ 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' ];
 Dygraph.KMG2_SMALL_LABELS = [ 'm', 'u', 'n', 'p', 'f', 'a', 'z', 'y' ];
@@ -140,13 +142,13 @@ Dygraph.numberValueFormatter = function(x, opts, pt, g) {
     var m_labels = [];
     if (kmb) {
       k = 1000;
-      k_labels = [ "K", "M", "B", "T", "Q" ];
+      k_labels = Dygraph.KMB_LABELS;
     }
     if (kmg2) {
       if (kmb) Dygraph.warn("Setting both labelsKMB and labelsKMG2. Pick one!");
       k = 1024;
-      k_labels = [ "k", "M", "G", "T", "P", "E", "Z", "Y" ];
-      m_labels = [ "m", "u", "n", "p", "f", "a", "z", "y" ];
+      k_labels = Dygraph.KMG2_BIG_LABELS;
+      m_labels = Dygraph.KMG2_SMALL_LABELS;
     }
 
     var absx = Math.abs(x);
@@ -710,7 +712,7 @@ Dygraph.prototype.xAxisRange = function() {
  */
 Dygraph.prototype.xAxisExtremes = function() {
   var pad = this.attr_('xRangePad') / this.plotter_.area.w;
-  if (this.numRows() == 0) {
+  if (this.numRows() === 0) {
     return [0 - pad, 1 + pad];
   }
   var left = this.rawData_[0][0];
@@ -1839,7 +1841,11 @@ Dygraph.prototype.mouseMove_ = function(event) {
 
   var callback = this.attr_("highlightCallback");
   if (callback && selectionChanged) {
-    callback(event, this.lastx_, this.selPoints_, this.lastRow_, this.highlightSet_);
+    callback(event,
+        this.lastx_,
+        this.selPoints_,
+        this.lastRow_ + this.getLeftBoundary_(),
+        this.highlightSet_);
   }
 };
 
@@ -2468,6 +2474,7 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) {
   this.cascadeEvents_('willDrawChart', e);
   this.plotter_.render();
   this.cascadeEvents_('didDrawChart', e);
+  this.lastRow_ = -1;  // because plugins/legend.js clears the legend
 
   // TODO(danvk): is this a performance bottleneck when panning?
   // The interaction canvas should already be empty in that situation.
@@ -2569,12 +2576,11 @@ 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();
+  var ypadCompat, span, series, ypad;
 
   // Compute extreme values, a span and tick marks for each axis.
   for (var i = 0; i < numAxes; i++) {
@@ -2617,7 +2623,7 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
       if (minY == Infinity) minY = 0;
       if (maxY == -Infinity) maxY = 1;
 
-      var span = maxY - minY;
+      span = maxY - minY;
       // special case: if we have no sense of scale, center on the sole value.
       if (span === 0) {
         if (maxY !== 0) {
@@ -2643,8 +2649,8 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
       // - new-style (yRangePad set by the user):
       //   always add the specified Y padding.
       //
-      var ypadCompat = true;
-      var ypad = 0.1; // add 10%
+      ypadCompat = true;
+      ypad = 0.1; // add 10%
       if (this.attr_('yRangePad') !== null) {
         ypadCompat = false;
         // Convert pixel padding to ratio
@@ -2689,7 +2695,7 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
           y0 *= logpad;
           y1 /= logpad;
         } else {
-          var span = y1 - y0;
+          span = y1 - y0;
           y0 -= span * ypad;
           y1 += span * ypad;
         }