X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Ferror_bars.js;h=bb6c1d97ea1c57c5e977c8b39544e2cfe6251dc1;hb=77a1405a7dea7e9de770583598a50e5907e6b1a1;hp=0d8b3bac222166eded95184f0d5dada3b3fa4384;hpb=f35016e8b97d39691777a8ad850bfa314e7e223a;p=dygraphs.git diff --git a/auto_tests/tests/error_bars.js b/auto_tests/tests/error_bars.js index 0d8b3ba..bb6c1d9 100644 --- a/auto_tests/tests/error_bars.js +++ b/auto_tests/tests/error_bars.js @@ -3,32 +3,38 @@ * * @author danvk@google.com (Dan Vanderkam) */ -var errorBarsTestCase = TestCase("error-bars"); +describe("error-bars", function() { -errorBarsTestCase.prototype.setUp = function() { +beforeEach(function() { document.body.innerHTML = "
"; -}; +}); var _origFunc = Dygraph.getContext; -errorBarsTestCase.prototype.setUp = function() { +beforeEach(function() { document.body.innerHTML = "
"; Dygraph.getContext = function(canvas) { return new Proxy(_origFunc(canvas)); } -}; +}); -errorBarsTestCase.prototype.tearDown = function() { +afterEach(function() { Dygraph.getContext = _origFunc; -}; +}); -errorBarsTestCase.prototype.testNameGoesHere = function() { +it('testErrorBarsDrawn', function() { var opts = { width: 480, height: 320, - drawXGrid: false, - drawYGrid: false, - drawXAxis: false, - drawYAxis: false, + axes : { + x : { + drawGrid: false, + drawAxis: false, + }, + y : { + drawGrid: false, + drawAxis: false, + } + }, customBars: true, errorBars: true }; @@ -47,7 +53,7 @@ errorBarsTestCase.prototype.testNameGoesHere = function() { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); - htx = g.hidden_ctx_; + var htx = g.hidden_ctx_; var attrs = {}; // TODO(danvk): fill in @@ -86,5 +92,97 @@ errorBarsTestCase.prototype.testNameGoesHere = 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); +}); +it('testErrorBarsCorrectColors', function() { + // Two constant series with constant error. + var data = [ + [0, [100, 50], [200, 50]], + [1, [100, 50], [200, 50]] + ]; + + var opts = { + errorBars: true, + sigma: 1.0, + fillAlpha: 0.15, + colors: ['#00ff00', '#0000ff'], + axes : { + x : { + drawGrid: false, + drawAxis: false, + }, + y : { + drawGrid: false, + drawAxis: false, + } + }, + width: 400, + height: 300, + valueRange: [0, 300], + labels: ['X', 'Y1', 'Y2'] + }; + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, opts); + + // y-pixels (0=top, 299=bottom) + // 0- 48: empty (white) + // 49- 98: Y2 error bar + // 99: Y2 center line + // 100-148: Y2 error bar + // 149-198: Y1 error bar + // 199: Y1 center line + // 200-248: Y1 error bar + // 249-299: empty (white) + // TODO(danvk): test the edges of these regions. + + assert.deepEqual([0, 0, 255, 38], Util.samplePixel(g.hidden_, 200, 75)); + assert.deepEqual([0, 0, 255, 38], Util.samplePixel(g.hidden_, 200, 125)); + assert.deepEqual([0, 255, 0, 38], Util.samplePixel(g.hidden_, 200, 175)); + assert.deepEqual([0, 255, 0, 38], Util.samplePixel(g.hidden_, 200, 225)); +}); + + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=392 +it('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_); + + assert.equal(null, in_series[4][1]); + assert.equal(null, in_series[4][2][0]); + assert.equal(null, in_series[4][2][1]); + assert(isNaN(in_series[5][1])); + assert(isNaN(in_series[5][2][0])); + assert(isNaN(in_series[5][2][1])); + + var out_series = g.dataHandler_.rollingAverage(in_series, 1, g.attributes_); + assert(isNaN(out_series[5][1])); + assert(isNaN(out_series[5][2][0])); + assert(isNaN(out_series[5][2][1])); + assert.equal(null, out_series[4][1]); + assert.equal(null, out_series[4][2][0]); + assert.equal(null, out_series[4][2][1]); +}); + +});