From: Nikhil Kasinadhuni Date: Thu, 11 Mar 2010 18:46:02 +0000 (-0800) Subject: push() is cheaper than unshift(). Refactor to separate the stacked case from X-Git-Tag: v1.0.0~702^2~2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=416b05ad69406631230ca76cc5b163047dd1bae1;p=dygraphs.git push() is cheaper than unshift(). Refactor to separate the stacked case from the normal case in determining the list of hovered points. --- diff --git a/dygraph.js b/dygraph.js index 954d067..1bf5e05 100644 --- a/dygraph.js +++ b/dygraph.js @@ -904,13 +904,17 @@ Dygraph.prototype.mouseMove_ = function(event) { var cumulative_sum = 0; // used only if we have a stackedGraph. var l = points.length; var isStacked = this.attr_("stackedGraph"); - for (var i = l - 1; i >= 0; i--) { - if (points[i].xval == lastx) { - if (!isStacked) { - this.selPoints_.unshift(points[i]); - } else { - // Clone the point, since we need to 'unstack' it below. Stacked points - // are in reverse order. + if (!this.attr_("stackedGraph")) { + for (var i = 0; i < l; i++) { + if (points[i].xval == lastx) { + this.selPoints_.push(points[i]); + } + } + } else { + // Stacked points need to be examined in reverse order. + for (var i = l - 1; i >= 0; i--) { + if (points[i].xval == lastx) { + // Clone the point, since we need to 'unstack' it below. var p = {}; for (var k in points[i]) { p[k] = points[i][k];