X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Ferror_bars.js;h=51443633f9df319ea8319e84a8e472768e9113b1;hb=4707563ce91e069b58ed6c1be38c8e4ace4a2150;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..5144363 100644 --- a/auto_tests/tests/error_bars.js +++ b/auto_tests/tests/error_bars.js @@ -9,19 +9,19 @@ 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.testNameGoesHere = function() { +errorBarsTestCase.prototype.testErrorBarsDrawn = function() { var opts = { width: 480, height: 320, @@ -86,5 +86,60 @@ errorBarsTestCase.prototype.testNameGoesHere = function() { xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][1]); CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs); } + CanvasAssertions.assertBalancedSaveRestore(htx); }; +errorBarsTestCase.prototype.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'], + drawXGrid: false, + drawYGrid: false, + drawXAxis: false, + drawYAxis: 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. + + var ctx = g.hidden_.getContext("2d"); // bypass Proxy + var imageData = ctx.getImageData(0, 0, 400, 300); + + assertEquals(400, imageData.width); + assertEquals(300, imageData.height); + + // 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)); +}