Make setSelection() work with missing points.
authorAdam Vartanian <flooey@gmail.com>
Mon, 13 Oct 2014 16:35:36 +0000 (12:35 -0400)
committerAdam Vartanian <flooey@gmail.com>
Mon, 13 Oct 2014 16:35:36 +0000 (12:35 -0400)
If the points array is missing points, for instance because the data
handler omitted them, setSelection() will now still properly find
the points that are being selected by looking at the points' idx
property instead of just indexing into the points array.

datahandler/datahandler.js
dygraph.js

index 2b637b5..b3eae91 100644 (file)
@@ -103,7 +103,8 @@ handler.prototype.extractSeries = function(rawData, seriesIndex, options) {
 };
 
 /**
- * Converts a series to a Point array.
+ * Converts a series to a Point array.  The resulting point array must be
+ * returned in increasing order of idx property.
  * 
  * @param {!Array.<[!number,?number,?]>} series The series in the unified 
  *          data format where series[i] = [x,y,{extras}].
index 8a1d65d..1745f05 100644 (file)
@@ -2124,10 +2124,14 @@ 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];
-      var setRow = row - this.getLeftBoundary_(setIdx);
-      if (setRow < points.length) {
-        var point = points[setRow];
-        if (point.yval !== null) this.selPoints_.push(point);
+      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;
+        }
       }
     }
   } else {