From: Dan Vanderkam Date: Mon, 4 Oct 2010 14:16:31 +0000 (-0400) Subject: Merge branch 'master' of http://github.com/adam-p/dygraphs X-Git-Tag: v1.0.0~644 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=895b3657b0ab22bb35815a1687c71116b2d8b36c;hp=227b93cc36500fbab1edab16880f1aa696f8a408;p=dygraphs.git Merge branch 'master' of github.com/adam-p/dygraphs --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 3b2ffa7..bf04e13 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -202,6 +202,35 @@ DygraphLayout.prototype.updateOptions = function(new_options) { Dygraph.update(this.options, new_options ? new_options : {}); }; +/** + * Return a copy of the point at the indicated index, with its yval unstacked. + * @param int index of point in layout_.points + */ +DygraphLayout.prototype.unstackPointAtIndex = function(idx) { + var point = this.points[idx]; + + // Clone the point since we modify it + var unstackedPoint = {}; + for (var i in point) { + unstackedPoint[i] = point[i]; + } + + if (!this.attr_("stackedGraph")) { + return unstackedPoint; + } + + // The unstacked yval is equal to the current yval minus the yval of the + // next point at the same xval. + for (var i = idx+1; i < this.points.length; i++) { + if (this.points[i].xval == point.xval) { + unstackedPoint.yval -= this.points[i].yval; + break; + } + } + + return unstackedPoint; +} + // Subclass PlotKit.CanvasRenderer to add: // 1. X/Y grid overlay // 2. Ability to draw error bars (if required) diff --git a/dygraph.js b/dygraph.js index 2574d4b..074776f 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1101,7 +1101,13 @@ Dygraph.prototype.setSelection = function(row) { if (row !== false && row >= 0) { for (var i in this.layout_.datasets) { if (row < this.layout_.datasets[i].length) { - this.selPoints_.push(this.layout_.points[pos+row]); + var point = this.layout_.points[pos+row]; + + if (this.attr_("stackedGraph")) { + point = this.layout_.unstackPointAtIndex(pos+row); + } + + this.selPoints_.push(point); } pos += this.layout_.datasets[i].length; } diff --git a/tests/stacked.html b/tests/stacked.html index 8973347..368d2e3 100644 --- a/tests/stacked.html +++ b/tests/stacked.html @@ -20,18 +20,42 @@

Stacked graph with many series:

+

Change selection/highlighting on all graphs:

+
+ +