From 1069800f8f3a766949a64d0cee2e3f34b0f8e2c0 Mon Sep 17 00:00:00 2001 From: Uemit Seren Date: Wed, 29 Feb 2012 16:58:14 +0100 Subject: [PATCH] Bugfix: Avoid getting stuck when the first datapoint has a NaN value --- auto_tests/tests/callback.js | 9 +++++---- dygraph.js | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index a26b7e7..ceb9963 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -267,6 +267,7 @@ CallbackTestCase.prototype.testClosestPointCallbackCss2 = function() { */ CallbackTestCase.prototype.testNaNData = function() { var dataNaN = [ + [9, -1, NaN, NaN], [10, -1, 1, 2], [11, 0, 3, 1], [12, 1, 4, NaN], @@ -293,17 +294,17 @@ CallbackTestCase.prototype.testNaNData = function() { DygraphOps.dispatchMouseMove(g, 10.1, 0.9); //check correct row is returned - assertEquals(0, h_row); + assertEquals(1, h_row); // Explicitly test closest point algorithms var dom = g.toDomCoords(10.1, 0.9); - assertEquals(0, g.findClosestRow(dom[0])); + assertEquals(1, g.findClosestRow(dom[0])); var res = g.findClosestPoint(dom[0], dom[1]); - assertEquals(0, res.row); + assertEquals(1, res.row); assertEquals('b', res.seriesName); res = g.findStackedPoint(dom[0], dom[1]); - assertEquals(0, res.row); + assertEquals(1, res.row); assertEquals('c', res.seriesName); }; diff --git a/dygraph.js b/dygraph.js index bc830b2..c94536b 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1552,7 +1552,8 @@ Dygraph.prototype.findClosestPoint = function(domX, domY) { dy = point.canvasy - domY; dist = dx * dx + dy * dy; if (minDist === null || dist < minDist) { - minDist = dist; + if (!isNaN(dist)) + minDist = dist; closestPoint = point; closestSeries = setIdx; idx = i; -- 2.7.4