From: Nagy Attila Gabor Date: Thu, 25 Feb 2010 21:39:30 +0000 (+0100) Subject: Fixed bug when graph is zoomed X-Git-Tag: v1.0.0~702^2~6^2~11 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=16269f6e2b690bdeec989364ae7e80995846adc9;p=dygraphs.git Fixed bug when graph is zoomed --- diff --git a/dygraph.js b/dygraph.js index d20d348..e45fc47 100644 --- a/dygraph.js +++ b/dygraph.js @@ -208,6 +208,8 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.attrs_ = {}; Dygraph.update(this.attrs_, Dygraph.DEFAULT_ATTRS); + + this.boundaryIds_ = []; // Make a note of whether labels will be pulled from the CSV file. this.labelsFromCSV_ = (this.attr_("labels") == null); @@ -990,11 +992,19 @@ Dygraph.prototype.setSelection = function(row) { var pos = 0; if (row !== false) { + row = row-this.boundaryIds_[0][0]; + } + + if (row !== false && row >= 0) { for (var i in this.layout_.datasets) { - this.selPoints_.push(this.layout_.points[pos+row]); + if (row < this.layout_.datasets[i].length) { + this.selPoints_.push(this.layout_.points[pos+row]); + } pos += this.layout_.datasets[i].length; } - + } + + if (this.selPoints_.length) { this.lastx_ = this.selPoints_[0].xval; this.updateSelection_(); } else { @@ -1040,7 +1050,7 @@ Dygraph.prototype.getSelection = function() { for (var row=0; row 0) firstIdx--; if (lastIdx === null) lastIdx = series.length - 1; if (lastIdx < series.length - 1) lastIdx++; + this.boundaryIds_[i-1] = [firstIdx, lastIdx]; for (var k = firstIdx; k <= lastIdx; k++) { pruned.push(series[k]); } series = pruned; + } else { + this.boundaryIds_[i-1] = [0, series.length-1]; } var extremes = this.extremeValues_(series);