| 1 | /** |
| 2 | * @fileoverview Tests for per-axis options. |
| 3 | * |
| 4 | * @author konigsberg@google.com (Robert Konigsberg) |
| 5 | */ |
| 6 | var perAxisTestCase = TestCase("per-axis"); |
| 7 | |
| 8 | perAxisTestCase._origGetContext = Dygraph.getContext; |
| 9 | |
| 10 | perAxisTestCase.prototype.setUp = function() { |
| 11 | document.body.innerHTML = "<div id='graph'></div>"; |
| 12 | Dygraph.getContext = function(canvas) { |
| 13 | return new Proxy(perAxisTestCase._origGetContext(canvas)); |
| 14 | } |
| 15 | |
| 16 | this.xAxisLineColor = "#00ffff"; |
| 17 | this.yAxisLineColor = "#ffff00"; |
| 18 | |
| 19 | var opts = { |
| 20 | axes : { |
| 21 | x : { |
| 22 | drawAxis : false, |
| 23 | drawGrid : false, |
| 24 | gridLineColor : this.xAxisLineColor |
| 25 | }, |
| 26 | y : { |
| 27 | drawAxis : false, |
| 28 | drawGrid : false, |
| 29 | gridLineColor : this.yAxisLineColor |
| 30 | } |
| 31 | }, |
| 32 | colors: [ '#ff0000', '#0000ff' ] |
| 33 | }; |
| 34 | |
| 35 | var data = "X,Y,Z\n" + |
| 36 | "1,1,0\n" + |
| 37 | "8,0,1\n" |
| 38 | ; |
| 39 | this.graph = document.getElementById('graph'); |
| 40 | this.g = new Dygraph(this.graph, data, opts); |
| 41 | }; |
| 42 | |
| 43 | perAxisTestCase.prototype.tearDown = function() { |
| 44 | Dygraph.getContext = perAxisTestCase._origGetContext; |
| 45 | }; |
| 46 | |
| 47 | perAxisTestCase.prototype.testDrawXAxis = function() { |
| 48 | this.g.updateOptions({ drawXAxis : true }); |
| 49 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-x').length > 0); |
| 50 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-y').length == 0); |
| 51 | } |
| 52 | |
| 53 | perAxisTestCase.prototype.testDrawYAxis = function() { |
| 54 | this.g.updateOptions({ drawYAxis : true }); |
| 55 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-x').length ==0); |
| 56 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-y').length > 0); |
| 57 | } |
| 58 | |
| 59 | perAxisTestCase.prototype.testDrawAxisX = function() { |
| 60 | this.g.updateOptions({ axes : { x : { drawAxis : true }}}); |
| 61 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-x').length > 0); |
| 62 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-y').length == 0); |
| 63 | } |
| 64 | |
| 65 | perAxisTestCase.prototype.testDrawAxisY = function() { |
| 66 | this.g.updateOptions({ axes : { y : { drawAxis : true }}}); |
| 67 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-x').length ==0); |
| 68 | assertTrue(this.graph.getElementsByClassName('dygraph-axis-label-y').length > 0); |
| 69 | } |
| 70 | perAxisTestCase.prototype.testDrawXGrid = function() { |
| 71 | this.g.updateOptions({ drawXGrid : true }); |
| 72 | var htx = this.g.hidden_ctx_; |
| 73 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.xAxisLineColor) > 0); |
| 74 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.yAxisLineColor) == 0); |
| 75 | } |
| 76 | |
| 77 | perAxisTestCase.prototype.testDrawYGrid = function() { |
| 78 | this.g.updateOptions({ drawYGrid : true }); |
| 79 | var htx = this.g.hidden_ctx_; |
| 80 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.xAxisLineColor) == 0); |
| 81 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.yAxisLineColor) > 0); |
| 82 | } |
| 83 | |
| 84 | perAxisTestCase.prototype.testDrawGridX = function() { |
| 85 | this.g.updateOptions({ axes : { x : { drawGrid : true }}}); |
| 86 | var htx = this.g.hidden_ctx_; |
| 87 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.xAxisLineColor) > 0); |
| 88 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.yAxisLineColor) == 0); |
| 89 | } |
| 90 | |
| 91 | perAxisTestCase.prototype.testDrawGridY = function() { |
| 92 | this.g.updateOptions({ axes : { y : { drawGrid : true }}}); |
| 93 | var htx = this.g.hidden_ctx_; |
| 94 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.xAxisLineColor) == 0); |
| 95 | assertTrue(CanvasAssertions.numLinesDrawn(htx, this.yAxisLineColor) > 0); |
| 96 | } |