X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fcustom_bars.js;h=493e86c533fd1b826559a0c8c5be34b4820b589b;hb=24f7710ba142479e082ac909f84283c0ad8261ce;hp=e55b1c8dc9318cf458e3e3119193669a83a34f6a;hpb=502d5996b66af93af562e2ae58f625c26d83145c;p=dygraphs.git diff --git a/auto_tests/tests/custom_bars.js b/auto_tests/tests/custom_bars.js index e55b1c8..493e86c 100644 --- a/auto_tests/tests/custom_bars.js +++ b/auto_tests/tests/custom_bars.js @@ -6,11 +6,16 @@ */ var CustomBarsTestCase = TestCase("custom-bars"); +var _origFunc = Dygraph.getContext; CustomBarsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; + Dygraph.getContext = function(canvas) { + return new Proxy(_origFunc(canvas)); + } }; CustomBarsTestCase.prototype.tearDown = function() { + Dygraph.getContext = _origFunc; }; // This test used to reliably produce an infinite loop. @@ -57,3 +62,92 @@ CustomBarsTestCase.prototype.testCustomBarsNoHang = function() { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); }; + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=201 +CustomBarsTestCase.prototype.testCustomBarsZero = function() { + var opts = { + customBars: true + }; + var data = "X,Y1,Y2\n" + +"1,1;2;3,0;0;0\n" + +"2,2;3;4,0;0;0\n" + +"3,1;3;5,0;0;0\n"; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, opts); + + var range = g.yAxisRange(); + assertTrue('y-axis must include 0', range[0] <= 0); + assertTrue('y-axis must include 5', range[1] >= 5); +}; + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=229 +CustomBarsTestCase.prototype.testCustomBarsAtTop = function() { + var g = new Dygraph(document.getElementById("graph"), + [ + [1, [10, 10, 100]], + [1, [10, 10, 100]], + [2, [15, 20, 110]], + [3, [10, 30, 100]], + [4, [15, 40, 110]], + [5, [10,120, 100]], + [6, [15, 50, 110]], + [7, [10, 70, 100]], + [8, [15, 90, 110]], + [9, [10, 50, 100]] + ], { + width: 500, height: 350, + customBars: true, + errorBars: true, + drawXGrid: false, + drawYGrid: false, + drawXAxis: false, + drawYAxis: false, + valueRange: [0, 120], + fillAlpha: 0.15, + colors: [ '#00FF00' ] + }); + + var sampler = new PixelSampler(g); + assertEquals([0, 255, 0, 38], sampler.colorAtCoordinate(5, 60)); +}; + +// Tests that custom bars work with log scale. +CustomBarsTestCase.prototype.testCustomBarsLogScale = function() { + var g = new Dygraph(document.getElementById("graph"), + [ + [1, [10, 10, 100]], + [5, [15,120, 80]], + [9, [10, 50, 100]] + ], { + width: 500, height: 350, + customBars: true, + errorBars: true, + valueRange: [1, 120], + drawXGrid: false, + drawYGrid: false, + drawXAxis: false, + drawYAxis: false, + fillAlpha: 1.0, + logscale: true, + colors: [ '#00FF00' ] + }); + + // The following assertions describe the sides of the custom bars, which are + // drawn in two halves. + CanvasAssertions.assertConsecutiveLinesDrawn( + g.hidden_ctx_, + [[0, 13.329014086362069], + [247.5, 29.64240889852502], + [247.5, 152.02209814465604], + [0, 181.66450704318103]], + { fillStyle: "#00ff00" }); + + CanvasAssertions.assertConsecutiveLinesDrawn( + g.hidden_ctx_, + [[247.5, 29.64240889852502], + [495, 13.329014086362069], + [495, 181.66450704318103], + [247.5, 152.02209814465604]], + { fillStyle: "#00ff00" }); +};