From: Dan Vanderkam Date: Sat, 12 Dec 2009 00:15:59 +0000 (-0800) Subject: check for null/undefined/NaN values, not zero values. add test X-Git-Tag: v1.0.0~804^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=8b91c51f857bc71543466e7b045124d92bf38322;p=dygraphs.git check for null/undefined/NaN values, not zero values. add test --- diff --git a/dygraph.js b/dygraph.js index bdfa1b1..d10ca38 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1268,7 +1268,7 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { var y = data[1]; rollingData[i] = [originalData[i][0], [y, y - data[0], data[2] - y]]; - if (y && !isNaN(y)) { + if (y != null && !isNaN(y)) { low += data[0]; mid += y; high += data[2]; @@ -1276,7 +1276,7 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { } if (i - rollPeriod >= 0) { var prev = originalData[i - rollPeriod]; - if (prev[1][1] && !isNaN(prev[1][1])) { + if (prev[1][1] != null && !isNaN(prev[1][1])) { low -= prev[1][0]; mid -= prev[1][1]; high -= prev[1][2]; @@ -1301,7 +1301,7 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { var num_ok = 0; for (var j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) { var y = originalData[j][1]; - if (!y || isNaN(y)) continue; + if (y == null || isNaN(y)) continue; num_ok++; sum += originalData[j][1]; } @@ -1319,7 +1319,7 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { var num_ok = 0; for (var j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) { var y = originalData[j][1][0]; - if (!y || isNaN(y)) continue; + if (y == null || isNaN(y)) continue; num_ok++; sum += originalData[j][1][0]; variance += Math.pow(originalData[j][1][1], 2); diff --git a/tests/zero-series.html b/tests/zero-series.html new file mode 100644 index 0000000..4e09df7 --- /dev/null +++ b/tests/zero-series.html @@ -0,0 +1,29 @@ + + + zero series + + + + + + +

Custom bars with a completely zero series. Both Y1 and Y2 should show.

+ + + +
+ + +