From: adam-p Date: Mon, 4 Oct 2010 14:02:55 +0000 (-0400) Subject: Based on feedback from danvk, moving unstackPointAtIndex_ to DygraphLayout X-Git-Tag: v1.0.0~644^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=667d510b2afb8e000f3b188937cc35d6670a728d;p=dygraphs.git Based on feedback from danvk, moving unstackPointAtIndex_ to DygraphLayout --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 8d3bfe2..3c059db 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 9a94fcf..2923aa3 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1070,36 +1070,6 @@ Dygraph.prototype.updateSelection_ = function() { }; /** - * Return a copy of the point at the indicated index, with its yval unstacked. - * @param int index of point in this.layout_.points - * @private - */ -Dygraph.prototype.unstackPointAtIndex_ = function(idx) { - var point = this.layout_.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.layout_.points.length; i++) { - if (this.layout_.points[i].xval == point.xval) { - unstackedPoint.yval -= this.layout_.points[i].yval; - break; - } - } - - return unstackedPoint; -} - -/** * Set manually set selected dots, and display information about them * @param int row number that should by highlighted * false value clears the selection @@ -1120,7 +1090,7 @@ Dygraph.prototype.setSelection = function(row) { var point = this.layout_.points[pos+row]; if (this.attr_("stackedGraph")) { - point = this.unstackPointAtIndex_(pos+row); + point = this.layout_.unstackPointAtIndex_(pos+row); } this.selPoints_.push(point);