Fork off Karma file for in-browser debug
[dygraphs.git] / auto_tests / tests / per_axis.js
CommitLineData
7f6a7190
RK
1/**
2 * @fileoverview Tests for per-axis options.
3 *
4 * @author konigsberg@google.com (Robert Konigsberg)
5 */
89fdcedb 6describe("per-axis", function() {
7f6a7190 7
319d0361
DV
8var _origGetContext = Dygraph.getContext;
9
10var xAxisLineColor = "#00ffff";
11var yAxisLineColor = "#ffff00";
12
13var g, graph;
7f6a7190 14
89fdcedb 15beforeEach(function() {
7f6a7190
RK
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);
89fdcedb 43});
7f6a7190 44
89fdcedb 45afterEach(function() {
319d0361 46 Dygraph.getContext = _origGetContext;
89fdcedb 47});
7f6a7190 48
89fdcedb 49it('testDrawXAxis', function() {
319d0361 50 g.updateOptions({ axes : { x : { drawAxis: true }} });
89fdcedb
DV
51 assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-x').length > 0);
52 assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-y').length == 0);
53});
7f6a7190 54
89fdcedb 55it('testDrawYAxis', function() {
319d0361 56 g.updateOptions({ axes : { y : { drawAxis: true }} });
89fdcedb
DV
57 assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-x').length ==0);
58 assert.isTrue(graph.getElementsByClassName('dygraph-axis-label-y').length > 0);
59});
7f6a7190 60
89fdcedb 61it('testDrawXGrid', function() {
319d0361
DV
62 g.updateOptions({ axes : { x : { drawGrid : true }}});
63 var htx = g.hidden_ctx_;
89fdcedb
DV
64 assert.isTrue(CanvasAssertions.numLinesDrawn(htx, xAxisLineColor) > 0);
65 assert.isTrue(CanvasAssertions.numLinesDrawn(htx, yAxisLineColor) == 0);
66});
7f6a7190 67
89fdcedb 68it('testDrawYGrid', function() {
319d0361
DV
69 g.updateOptions({ axes : { y : { drawGrid : true }}});
70 var htx = g.hidden_ctx_;
89fdcedb
DV
71 assert.isTrue(CanvasAssertions.numLinesDrawn(htx, xAxisLineColor) == 0);
72 assert.isTrue(CanvasAssertions.numLinesDrawn(htx, yAxisLineColor) > 0);
73});
74
75});