Commit | Line | Data |
---|---|---|
7f6a7190 RK |
1 | /** |
2 | * @fileoverview Tests for per-axis options. | |
3 | * | |
4 | * @author konigsberg@google.com (Robert Konigsberg) | |
5 | */ | |
6 | var perAxisTestCase = TestCase("per-axis"); | |
7 | ||
319d0361 DV |
8 | var _origGetContext = Dygraph.getContext; |
9 | ||
10 | var xAxisLineColor = "#00ffff"; | |
11 | var yAxisLineColor = "#ffff00"; | |
12 | ||
13 | var g, graph; | |
7f6a7190 RK |
14 | |
15 | perAxisTestCase.prototype.setUp = function() { | |
16 | document.body.innerHTML = "<div id='graph'></div>"; | |
17 | Dygraph.getContext = function(canvas) { | |
319d0361 | 18 | return new Proxy(_origGetContext(canvas)); |
7f6a7190 RK |
19 | } |
20 | ||
7f6a7190 RK |
21 | var opts = { |
22 | axes : { | |
23 | x : { | |
24 | drawAxis : false, | |
25 | drawGrid : false, | |
319d0361 | 26 | gridLineColor : xAxisLineColor |
7f6a7190 RK |
27 | }, |
28 | y : { | |
29 | drawAxis : false, | |
30 | drawGrid : false, | |
319d0361 | 31 | gridLineColor : yAxisLineColor |
7f6a7190 RK |
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 | ; | |
319d0361 DV |
41 | graph = document.getElementById('graph'); |
42 | g = new Dygraph(graph, data, opts); | |
7f6a7190 RK |
43 | }; |
44 | ||
45 | perAxisTestCase.prototype.tearDown = function() { | |
319d0361 | 46 | Dygraph.getContext = _origGetContext; |
7f6a7190 RK |
47 | }; |
48 | ||
49 | perAxisTestCase.prototype.testDrawXAxis = function() { | |
319d0361 DV |
50 | g.updateOptions({ axes : { x : { drawAxis: true }} }); |
51 | assertTrue(graph.getElementsByClassName('dygraph-axis-label-x').length > 0); | |
52 | assertTrue(graph.getElementsByClassName('dygraph-axis-label-y').length == 0); | |
7f6a7190 RK |
53 | } |
54 | ||
55 | perAxisTestCase.prototype.testDrawYAxis = function() { | |
319d0361 DV |
56 | g.updateOptions({ axes : { y : { drawAxis: true }} }); |
57 | assertTrue(graph.getElementsByClassName('dygraph-axis-label-x').length ==0); | |
58 | assertTrue(graph.getElementsByClassName('dygraph-axis-label-y').length > 0); | |
7f6a7190 RK |
59 | } |
60 | ||
7f6a7190 | 61 | perAxisTestCase.prototype.testDrawXGrid = function() { |
319d0361 DV |
62 | g.updateOptions({ axes : { x : { drawGrid : true }}}); |
63 | var htx = g.hidden_ctx_; | |
64 | assertTrue(CanvasAssertions.numLinesDrawn(htx, xAxisLineColor) > 0); | |
65 | assertTrue(CanvasAssertions.numLinesDrawn(htx, yAxisLineColor) == 0); | |
7f6a7190 RK |
66 | } |
67 | ||
bfb3e0a4 | 68 | perAxisTestCase.prototype.testDrawYGrid = function() { |
319d0361 DV |
69 | g.updateOptions({ axes : { y : { drawGrid : true }}}); |
70 | var htx = g.hidden_ctx_; | |
71 | assertTrue(CanvasAssertions.numLinesDrawn(htx, xAxisLineColor) == 0); | |
72 | assertTrue(CanvasAssertions.numLinesDrawn(htx, yAxisLineColor) > 0); | |
7f6a7190 | 73 | } |