From ad7785b8f9a1564b8d18a8ee9a1036936298bb31 Mon Sep 17 00:00:00 2001 From: Adam Vartanian Date: Mon, 13 Oct 2014 12:35:36 -0400 Subject: [PATCH] Make setSelection() work with missing points. 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 | 3 ++- dygraph.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/datahandler/datahandler.js b/datahandler/datahandler.js index 2b637b5..b3eae91 100644 --- a/datahandler/datahandler.js +++ b/datahandler/datahandler.js @@ -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}]. diff --git a/dygraph.js b/dygraph.js index 8a1d65d..1745f05 100644 --- a/dygraph.js +++ b/dygraph.js @@ -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 { -- 2.7.4