From: Dan Vanderkam Date: Wed, 20 Feb 2013 04:08:40 +0000 (-0500) Subject: Fix & regression test for issue 392: connectSeparated and errorBars don't play nicely... X-Git-Tag: v1.0.0~53^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=7522b21bef325dd8d3fa201e835a540cd7c6d9bf;p=dygraphs.git Fix & regression test for issue 392: connectSeparated and errorBars don't play nicely together --- diff --git a/auto_tests/tests/error_bars.js b/auto_tests/tests/error_bars.js index e57898b..7e50e42 100644 --- a/auto_tests/tests/error_bars.js +++ b/auto_tests/tests/error_bars.js @@ -128,4 +128,51 @@ errorBarsTestCase.prototype.testErrorBarsCorrectColors = function() { assertEquals([0, 0, 255, 38], Util.samplePixel(g.hidden_, 200, 125)); assertEquals([0, 255, 0, 38], Util.samplePixel(g.hidden_, 200, 175)); assertEquals([0, 255, 0, 38], Util.samplePixel(g.hidden_, 200, 225)); -} +}; + + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=392 +errorBarsTestCase.prototype.testRollingAveragePreservesNaNs = function() { + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, + [ + [1, [null, null], [3,1]], + [2, [2, 1], [null, null]], + [3, [null, null], [5,1]], + [4, [4, 0.5], [null, null]], + [5, [null, null], [7,1]], + [6, [NaN, NaN], [null, null]], + [8, [8, 1], [null, null]], + [10, [10, 1], [null, null]] + ] + , { + labels: ['x', 'A', 'B' ], + connectSeparatedPoints: true, + drawPoints: true, + errorBars: true + } + ); + + var in_series = [ + [1, [null, null]], + [2, [2, 1]], + [3, [null, null]], + [4, [4, 0.5]], + [5, [null, null]], + [6, [NaN, NaN]], + [8, [8, 1]], + [10, [10, 1]] + ]; + assertEquals(null, in_series[4][1][0]); + assertEquals(null, in_series[4][1][1]); + assertNaN(in_series[5][1][0]); + assertNaN(in_series[5][1][1]); + + var out_series = g.rollingAverage(in_series, 1); + assertNaN(out_series[5][1][0]); + assertNaN(out_series[5][1][1]); + assertNaN(out_series[5][1][2]); + assertEquals(null, out_series[4][1][0]); + assertEquals(null, out_series[4][1][1]); + assertEquals(null, out_series[4][1][1]); +}; diff --git a/dygraph.js b/dygraph.js index 1f55870..9ac1181 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2896,7 +2896,10 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { rollingData[i] = [originalData[i][0], [sum / num_ok, sigma * stddev, sigma * stddev]]; } else { - rollingData[i] = [originalData[i][0], [null, null, null]]; + // This explicitly preserves NaNs to aid with "independent series". + // See testRollingAveragePreservesNaNs. + var v = (rollPeriod == 1) ? originalData[i][1][0] : null; + rollingData[i] = [originalData[i][0], [v, v, v]]; } } }