| 1 | /** |
| 2 | * @fileoverview Tests for per-axis options. |
| 3 | * |
| 4 | * @author konigsberg@google.com (Robert Konigsberg) |
| 5 | */ |
| 6 | describe("per-axis", function() { |
| 7 | |
| 8 | var _origGetContext = Dygraph.getContext; |
| 9 | |
| 10 | var xAxisLineColor = "#00ffff"; |
| 11 | var yAxisLineColor = "#ffff00"; |
| 12 | |
| 13 | var g, graph; |
| 14 | |
| 15 | beforeEach(function() { |
| 16 | document.body.innerHTML = "<div id='graph'></div>"; |
| 17 | Dygraph.getContext = function(canvas) { |
| 18 | return new Proxy(_origGetContext(canvas)); |
| 19 | } |
| 20 | |
| 21 | var opts = { |
| 22 | axes : { |
| 23 | x : { |
| 24 | drawAxis : false, |
| 25 | drawGrid : false, |
| 26 | gridLineColor : xAxisLineColor |
| 27 | }, |
| 28 | y : { |
| 29 | drawAxis : false, |
| 30 | drawGrid : false, |
| 31 | gridLineColor : yAxisLineColor |
| 32 | } |
| 33 | }, |
| 34 | colors: [ '#ff0000', '#0000ff' ] |
| 35 | }; |
| 36 | |
| 37 | var data = "X,Y,Z\n" + |
| 38 | "1,1,0\n" + |
| 39 | "8,0,1\n" |
| 40 | ; |
| 41 | graph = document.getElementById('graph'); |
| 42 | g = new Dygraph(graph, data, opts); |
| 43 | }); |
| 44 | |
| 45 | afterEach(function() { |
| 46 | Dygraph.getContext = _origGetContext; |
| 47 | }); |
| 48 | |
| 49 | it('testDrawXAxis', function() { |
| 50 | g.updateOptions({ axes : { x : { drawAxis: true }} }); |
| 51 | assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-x').length > 0); |
| 52 | assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-y').length == 0); |
| 53 | }); |
| 54 | |
| 55 | it('testDrawYAxis', function() { |
| 56 | g.updateOptions({ axes : { y : { drawAxis: true }} }); |
| 57 | assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-x').length ==0); |
| 58 | assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-y').length > 0); |
| 59 | }); |
| 60 | |
| 61 | it('testDrawXGrid', function() { |
| 62 | g.updateOptions({ axes : { x : { drawGrid : true }}}); |
| 63 | var htx = g.hidden_ctx_; |
| 64 | assert.isTrue(CanvasAssertions.numLinesDrawn(htx, xAxisLineColor) > 0); |
| 65 | assert.isTrue(CanvasAssertions.numLinesDrawn(htx, yAxisLineColor) == 0); |
| 66 | }); |
| 67 | |
| 68 | it('testDrawYGrid', function() { |
| 69 | g.updateOptions({ axes : { y : { drawGrid : true }}}); |
| 70 | var htx = g.hidden_ctx_; |
| 71 | assert.isTrue(CanvasAssertions.numLinesDrawn(htx, xAxisLineColor) == 0); |
| 72 | assert.isTrue(CanvasAssertions.numLinesDrawn(htx, yAxisLineColor) > 0); |
| 73 | }); |
| 74 | |
| 75 | }); |