2 * @fileoverview Tests for per-axis options.
4 * @author konigsberg@google.com (Robert Konigsberg)
6 var perAxisTestCase
= TestCase("per-axis");
8 perAxisTestCase
._origGetContext
= Dygraph
.getContext
;
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
));
16 this.xAxisLineColor
= "#00ffff";
17 this.yAxisLineColor
= "#ffff00";
24 gridLineColor
: this.xAxisLineColor
29 gridLineColor
: this.yAxisLineColor
32 colors
: [ '#ff0000', '#0000ff' ]
35 var data
= "X,Y,Z\n" +
39 this.graph
= document
.getElementById('graph');
40 this.g
= new Dygraph(this.graph
, data
, opts
);
43 perAxisTestCase
.prototype.tearDown
= function() {
44 Dygraph
.getContext
= perAxisTestCase
._origGetContext
;
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);
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);
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);
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);
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);
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);
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);
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);