From 1f7f664bdc32af396157632389500276e08b9725 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Mon, 22 Nov 2010 10:46:47 -0500 Subject: [PATCH] fix infinity bug --- dygraph.js | 8 ++++++- tests/gviz-infinity.html | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/gviz-infinity.html diff --git a/dygraph.js b/dygraph.js index c24f4f3..ca935a1 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2413,7 +2413,8 @@ Dygraph.prototype.parseCSV_ = function(data) { // Parse the x as a float or return null if it's not a number. var parseFloatOrNull = function(x) { var val = parseFloat(x); - return isNaN(val) ? null : val; + // isFinite() returns false for NaN and +/-Infinity. + return isFinite(val) ? val : null; }; var xParser; @@ -2645,6 +2646,11 @@ Dygraph.prototype.parseDataTable_ = function(data) { if (ret.length > 0 && row[0] < ret[ret.length - 1][0]) { outOfOrder = true; } + + // Strip out infinities, which give dygraphs problems later on. + for (var j = 0; j < row.length; j++) { + if (!isFinite(row[j])) row[j] = null; + } ret.push(row); } diff --git a/tests/gviz-infinity.html b/tests/gviz-infinity.html new file mode 100644 index 0000000..9361a97 --- /dev/null +++ b/tests/gviz-infinity.html @@ -0,0 +1,62 @@ + + + gviz + + + + + + + + + +

This tests that infinite values don't break dygraphs.

+

gviz line chart:

+
+ +

same data drawn using dygraphs:

+ date column: +
+ + -- 2.7.4