From a703cbdf5c20bbcf7b2216cf94ab092d5cfb2ec7 Mon Sep 17 00:00:00 2001
From: eberldav <eberldav@ch.sauter-bc.com>
Date: Thu, 13 Jun 2013 10:38:31 +0200
Subject: [PATCH] BUGFIX: Fixed bug using the idxToRow_ function instead of
 directly taking the row from the point. Also the idxToRow_ method has been
 completely removed based on Dans comment, that it is unneeded.

---
 dygraph.js | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/dygraph.js b/dygraph.js
index 8764430..7556a7e 100644
--- a/dygraph.js
+++ b/dygraph.js
@@ -1697,7 +1697,7 @@ Dygraph.prototype.eventToDomCoords = function(event) {
  */
 Dygraph.prototype.findClosestRow = function(domX) {
   var minDistX = Infinity;
-  var pointIdx = -1, setIdx = -1;
+  var closestRow = -1;
   var sets = this.layout_.points;
   for (var i = 0; i < sets.length; i++) {
     var points = sets[i];
@@ -1708,14 +1708,12 @@ Dygraph.prototype.findClosestRow = function(domX) {
       var dist = Math.abs(point.canvasx - domX);
       if (dist < minDistX) {
         minDistX = dist;
-        setIdx = i;
-        pointIdx = j;
+        closestRow = point.idx;
       }
     }
   }
 
-  // TODO(danvk): remove this function; it's trivial and has only one use.
-  return this.idxToRow_(setIdx, pointIdx);
+  return closestRow;
 };
 
 /**
@@ -1862,8 +1860,8 @@ Dygraph.prototype.mouseMove_ = function(event) {
  * @private
  */
 Dygraph.prototype.getLeftBoundary_ = function(setIdx) {
-  if(!isNaN(setIdx) && setIdx < this.boundaryIds_.length){
-    return this.boundaryIds_[setIdx][0];
+  if(this.boundaryIds_[setIdx]){
+      return this.boundaryIds_[setIdx][0];
   } else {
     for (var i = 0; i < this.boundaryIds_.length; i++) {
       if (this.boundaryIds_[i] !== undefined) {
@@ -1874,19 +1872,6 @@ Dygraph.prototype.getLeftBoundary_ = function(setIdx) {
   }
 };
 
-/**
- * Transforms layout_.points index into data row number.
- * @param int layout_.points index
- * @return int row number, or -1 if none could be found.
- * @private
- */
-Dygraph.prototype.idxToRow_ = function(setIdx, rowIdx) {
-  if (rowIdx < 0) return -1;
-
-  var boundary = this.getLeftBoundary_(setIdx);
-  return boundary + rowIdx;
-};
-
 Dygraph.prototype.animateSelection_ = function(direction) {
   var totalSteps = 10;
   var millis = 30;
-- 
2.7.4