X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fcustom_bars.js;h=e8af21456937176fa3fdd03cda8d3f550e5923ad;hb=refs%2Fheads%2Fissue-514;hp=22ffd204be74545d30ecd6077d560c15dbe020e8;hpb=3bdeeb9b9d123e9e45159a6801b6e7fe74f08690;p=dygraphs.git diff --git a/auto_tests/tests/custom_bars.js b/auto_tests/tests/custom_bars.js index 22ffd20..e8af214 100644 --- a/auto_tests/tests/custom_bars.js +++ b/auto_tests/tests/custom_bars.js @@ -6,11 +6,16 @@ */ var CustomBarsTestCase = TestCase("custom-bars"); +CustomBarsTestCase._origFunc = Dygraph.getContext; CustomBarsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; + Dygraph.getContext = function(canvas) { + return new Proxy(CustomBarsTestCase._origFunc(canvas)); + } }; CustomBarsTestCase.prototype.tearDown = function() { + Dygraph.getContext = CustomBarsTestCase._origFunc; }; // This test used to reliably produce an infinite loop. @@ -94,10 +99,16 @@ 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' ] @@ -106,3 +117,79 @@ CustomBarsTestCase.prototype.testCustomBarsAtTop = function() { 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], + axes : { + x : { + drawGrid: false, + drawAxis: false, + }, + y : { + drawGrid: false, + drawAxis: 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" }); +}; + +CustomBarsTestCase.prototype.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 + }); + + // Normally all three points would be drawn. + assertEquals(3, count); + count = 0; + + // In log scale, the third point shouldn't be shown. + g.updateOptions({ logscale : true }); + assertEquals(2, count); +};