Check that setRow is not negative, fixes #644. (#773)
[dygraphs.git] / src / dygraph.js
index e5053ba..3ffc2e6 100644 (file)
@@ -1813,7 +1813,7 @@ Dygraph.prototype.setSelection = function(row, opt_seriesName, opt_locked) {
       // 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) {
+      if (setRow >= 0 && setRow < points.length && points[setRow].idx == row) {
         var point = points[setRow];
         if (point.yval !== null) this.selPoints_.push(point);
       } else {
@@ -2304,16 +2304,15 @@ Dygraph.prototype.drawGraph_ = function() {
 
   this.setIndexByName_ = {};
   var labels = this.attr_("labels");
-  if (labels.length > 0) {
-    this.setIndexByName_[labels[0]] = 0;
-  }
   var dataIdx = 0;
   for (var i = 1; i < points.length; i++) {
-    this.setIndexByName_[labels[i]] = i;
     if (!this.visibility()[i - 1]) continue;
     this.layout_.addDataset(labels[i], points[i]);
     this.datasetIndex_[i] = dataIdx++;
   }
+  for (var i = 0; i < labels.length; i++) {
+    this.setIndexByName_[labels[i]] = i;
+  }
 
   this.computeYAxisRanges_(extremes);
   this.layout_.setYAxes(this.axes_);