X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fcustom_bars.js;h=cbffe7e76ee9d57a68301dfd10eed10204d94b9c;hb=a4c3ece0a11e4e5c4f1f51a8bc8b7878d34ee052;hp=493e86c533fd1b826559a0c8c5be34b4820b589b;hpb=780a5081d29a3c0a3c4f1d126f0992cf4fc14ebd;p=dygraphs.git diff --git a/auto_tests/tests/custom_bars.js b/auto_tests/tests/custom_bars.js index 493e86c..cbffe7e 100644 --- a/auto_tests/tests/custom_bars.js +++ b/auto_tests/tests/custom_bars.js @@ -4,22 +4,22 @@ * @fileoverview Regression test based on some strange customBars data. * @author danvk@google.com (Dan Vanderkam) */ -var CustomBarsTestCase = TestCase("custom-bars"); +describe("custom-bars", function() { var _origFunc = Dygraph.getContext; -CustomBarsTestCase.prototype.setUp = function() { +beforeEach(function() { document.body.innerHTML = "
"; Dygraph.getContext = function(canvas) { return new Proxy(_origFunc(canvas)); } -}; +}); -CustomBarsTestCase.prototype.tearDown = function() { +afterEach(function() { Dygraph.getContext = _origFunc; -}; +}); // This test used to reliably produce an infinite loop. -CustomBarsTestCase.prototype.testCustomBarsNoHang = function() { +it('testCustomBarsNoHang', function() { var opts = { width: 480, height: 320, @@ -61,10 +61,10 @@ CustomBarsTestCase.prototype.testCustomBarsNoHang = function() { "35,,0;22437620;0\n"; 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() { +it('testCustomBarsZero', function() { var opts = { customBars: true }; @@ -77,12 +77,12 @@ CustomBarsTestCase.prototype.testCustomBarsZero = function() { 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); -}; + assert.isTrue(range[0] <= 0, 'y-axis must include 0'); + assert.isTrue(range[1] >= 5, 'y-axis must include 5'); +}); // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=229 -CustomBarsTestCase.prototype.testCustomBarsAtTop = function() { +it('testCustomBarsAtTop', function() { var g = new Dygraph(document.getElementById("graph"), [ [1, [10, 10, 100]], @@ -99,21 +99,28 @@ CustomBarsTestCase.prototype.testCustomBarsAtTop = function() { width: 500, height: 350, customBars: true, errorBars: true, - drawXGrid: false, - drawYGrid: false, - drawXAxis: false, - drawYAxis: false, + axes: { + x: { + drawGrid: false, + drawAxis: false, + }, + y: { + drawGrid: false, + drawAxis: false, + } + }, valueRange: [0, 120], fillAlpha: 0.15, - colors: [ '#00FF00' ] + colors: ['#00FF00'], + labels: ['X', 'Y'] }); var sampler = new PixelSampler(g); - assertEquals([0, 255, 0, 38], sampler.colorAtCoordinate(5, 60)); -}; + assert.deepEqual([0, 255, 0, 38], sampler.colorAtCoordinate(5, 60)); +}); // Tests that custom bars work with log scale. -CustomBarsTestCase.prototype.testCustomBarsLogScale = function() { +it('testCustomBarsLogScale', function() { var g = new Dygraph(document.getElementById("graph"), [ [1, [10, 10, 100]], @@ -124,13 +131,20 @@ CustomBarsTestCase.prototype.testCustomBarsLogScale = function() { customBars: true, errorBars: true, valueRange: [1, 120], - drawXGrid: false, - drawYGrid: false, - drawXAxis: false, - drawYAxis: false, + axes : { + x : { + drawGrid: false, + drawAxis: false, + }, + y : { + drawGrid: false, + drawAxis: false, + } + }, fillAlpha: 1.0, logscale: true, - colors: [ '#00FF00' ] + colors: ['#00FF00'], + labels: ['X', 'Y'] }); // The following assertions describe the sides of the custom bars, which are @@ -150,4 +164,36 @@ CustomBarsTestCase.prototype.testCustomBarsLogScale = function() { [495, 181.66450704318103], [247.5, 152.02209814465604]], { fillStyle: "#00ff00" }); -}; +}); + +it('testCustomBarsWithNegativeValuesInLogScale', function() { + var graph = document.getElementById("graph"); + + var count = 0; + var drawPointCallback = function() { + count++; + }; + + var g = new Dygraph(graph, + [ + [1, [10, 20,30]], + [2, [5, 10, 15]], + [3, [-1, 5, 10]] + ], + { + drawPoints: true, + drawPointCallback: drawPointCallback, + customBars: true, + labels: ['X', 'Y'] + }); + + // Normally all three points would be drawn. + assert.equal(3, count); + count = 0; + + // In log scale, the third point shouldn't be shown. + g.updateOptions({ logscale : true }); + assert.equal(2, count); +}); + +});