Add a fast-path setSelection() if the points are in the expected place.
[dygraphs.git] / dygraph.js
index 1745f05..b3243bd 100644 (file)
@@ -2124,13 +2124,22 @@ Dygraph.prototype.setSelection = function(row, opt_seriesName, opt_locked) {
     this.lastRow_ = row;
     for (var setIdx = 0; setIdx < this.layout_.points.length; ++setIdx) {
       var points = this.layout_.points[setIdx];
-      for (var pointIdx = 0; pointIdx < points.length; ++pointIdx) {
-       var point = points[pointIdx];
-        if (point.idx == row) {
-          if (point.yval !== null) {
-            this.selPoints_.push(point);
+      // Check if the point at the appropriate index is the point we're looking
+      // for.  If it is, just use it, otherwise search the array for a point
+      // in the proper place.
+      var setRow = row - this.getLeftBoundary_(setIdx);
+      if (setRow < points.length && points[setRow].idx == row) {
+        var point = points[setRow];
+        if (point.yval !== null) this.selPoints_.push(point);
+      } else {
+        for (var pointIdx = 0; pointIdx < points.length; ++pointIdx) {
+          var point = points[pointIdx];
+          if (point.idx == row) {
+            if (point.yval !== null) {
+              this.selPoints_.push(point);
+            }
+            break;
           }
-          break;
         }
       }
     }