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]);
+};
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]];
}
}
}