From 416b05ad69406631230ca76cc5b163047dd1bae1 Mon Sep 17 00:00:00 2001 From: Nikhil Kasinadhuni Date: Thu, 11 Mar 2010 10:46:02 -0800 Subject: [PATCH] push() is cheaper than unshift(). Refactor to separate the stacked case from the normal case in determining the list of hovered points. --- dygraph.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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]; -- 2.7.4