From: Adam Vartanian Date: Mon, 13 Oct 2014 16:35:36 +0000 (-0400) Subject: Make setSelection() work with missing points. X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=9b7f997297a8c8becb3359186f39afbdbb1f88bc;p=dygraphs.git 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. --- 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 5985964..2fc527d 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2156,10 +2156,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 {