X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=inline;f=auto_tests%2Ftests%2Ferror_bars.js;h=1c3894cdb1b2370ab996b5233452d8193fca13d2;hb=27fd63fc0ca45c06318bb47dd8c0f6aa074957b8;hp=1ede89b46d61fbe741bd67ca5c7bbe6979ce0252;hpb=debdb88d1ccca3648f45d6cc5d49896f3014cfdd;p=dygraphs.git diff --git a/auto_tests/tests/error_bars.js b/auto_tests/tests/error_bars.js index 1ede89b..1c3894c 100644 --- a/auto_tests/tests/error_bars.js +++ b/auto_tests/tests/error_bars.js @@ -9,16 +9,16 @@ errorBarsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; }; -var _origFunc = Dygraph.getContext; +errorBarsTestCase._origFunc = Dygraph.getContext; errorBarsTestCase.prototype.setUp = function() { document.body.innerHTML = ""; Dygraph.getContext = function(canvas) { - return new Proxy(_origFunc(canvas)); + return new Proxy(errorBarsTestCase._origFunc(canvas)); } }; errorBarsTestCase.prototype.tearDown = function() { - Dygraph.getContext = _origFunc; + Dygraph.getContext = errorBarsTestCase._origFunc; }; errorBarsTestCase.prototype.testErrorBarsDrawn = function() { @@ -86,6 +86,7 @@ errorBarsTestCase.prototype.testErrorBarsDrawn = function() { xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][1]); CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs); } + g.destroy(); // Restore balanced saves and restores. CanvasAssertions.assertBalancedSaveRestore(htx); }; @@ -124,22 +125,50 @@ errorBarsTestCase.prototype.testErrorBarsCorrectColors = function() { // 249-299: empty (white) // TODO(danvk): test the edges of these regions. - var ctx = g.hidden_.getContext("2d"); // bypass Proxy - var imageData = ctx.getImageData(0, 0, 400, 300); - - assertEquals(400, imageData.width); - assertEquals(300, imageData.height); + assertEquals([0, 0, 255, 38], Util.samplePixel(g.hidden_, 200, 75)); + 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)); +}; - // returns an (r, g, b, alpha) tuple for the pixel. - // values are in [0, 255]. - var getPixel = function(imageData, x, y) { - var i = 4 * (x + imageData.width * y); - var d = imageData.data; - return [d[i], d[i+1], d[i+2], d[i+3]]; - }; - assertEquals([0, 0, 255, 38], getPixel(imageData, 200, 75)); - assertEquals([0, 0, 255, 38], getPixel(imageData, 200, 125)); - assertEquals([0, 255, 0, 38], getPixel(imageData, 200, 175)); - assertEquals([0, 255, 0, 38], getPixel(imageData, 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 data = + [ + [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]] + ]; + var g = new Dygraph(graph, data, + { + labels: ['x', 'A', 'B' ], + connectSeparatedPoints: true, + drawPoints: true, + errorBars: true + } + ); + + var in_series = g.dataHandler_.extractSeries(data, 1, g.attributes_); + + assertEquals(null, in_series[4][1]); + assertEquals(null, in_series[4][2][0]); + assertEquals(null, in_series[4][2][1]); + assertNaN(in_series[5][1]); + assertNaN(in_series[5][2][0]); + assertNaN(in_series[5][2][1]); + + var out_series = g.dataHandler_.rollingAverage(in_series, 1, g.attributes_); + assertNaN(out_series[5][1]); + assertNaN(out_series[5][2][0]); + assertNaN(out_series[5][2][1]); + assertEquals(null, out_series[4][1]); + assertEquals(null, out_series[4][2][0]); + assertEquals(null, out_series[4][2][1]); +};