From: Dan Vanderkam Date: Mon, 22 Nov 2010 15:46:47 +0000 (-0500) Subject: fix infinity bug X-Git-Tag: v1.0.0~600 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=1f7f664bdc32af396157632389500276e08b9725;p=dygraphs.git fix infinity bug --- 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: +
+ +