Commit | Line | Data |
---|---|---|
e2d8db3a | 1 | /** |
30abcfb6 | 2 | * @fileoverview Tests for per-series options. |
e2d8db3a DV |
3 | * |
4 | * @author danvk@google.com (Dan Vanderkam) | |
5 | */ | |
89fdcedb | 6 | describe("per-series", function() { |
e2d8db3a | 7 | |
89fdcedb | 8 | beforeEach(function() { |
e2d8db3a | 9 | document.body.innerHTML = "<div id='graph'></div>"; |
89fdcedb | 10 | }); |
e2d8db3a | 11 | |
89fdcedb DV |
12 | afterEach(function() { |
13 | }); | |
e2d8db3a | 14 | |
89fdcedb | 15 | it('testPerSeriesFill', function() { |
e2d8db3a DV |
16 | var opts = { |
17 | width: 480, | |
18 | height: 320, | |
bfb3e0a4 RK |
19 | axes : { |
20 | x : { | |
21 | drawGrid: false, | |
22 | drawAxis: false, | |
23 | }, | |
24 | y : { | |
25 | drawGrid: false, | |
26 | drawAxis: false, | |
27 | } | |
28 | }, | |
8887663f DV |
29 | series: { |
30 | Y: { fillGraph: true }, | |
31 | }, | |
e2d8db3a DV |
32 | colors: [ '#FF0000', '#0000FF' ], |
33 | fillAlpha: 0.15 | |
34 | }; | |
35 | var data = "X,Y,Z\n" + | |
36 | "1,0,0\n" + | |
37 | "2,0,1\n" + | |
38 | "3,0,1\n" + | |
39 | "4,0,0\n" + | |
40 | "5,0,0\n" + | |
41 | "6,1,0\n" + | |
42 | "7,1,0\n" + | |
43 | "8,0,0\n" | |
44 | ; | |
45 | ||
46 | var graph = document.getElementById("graph"); | |
89fdcedb | 47 | var g = new Dygraph(graph, data, opts); |
e2d8db3a DV |
48 | |
49 | var sampler = new PixelSampler(g); | |
50 | ||
51 | // Inside of the "Z" bump -- no fill. | |
89fdcedb | 52 | assert.deepEqual([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5)); |
e2d8db3a DV |
53 | |
54 | // Inside of the "Y" bump -- filled in. | |
89fdcedb DV |
55 | assert.deepEqual([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5)); |
56 | }); | |
e2d8db3a | 57 | |
89fdcedb | 58 | it('testNewStyleSeries', function() { |
0fe209e5 RK |
59 | var opts = { |
60 | pointSize : 5, | |
61 | series : { | |
62 | Y: { pointSize : 4 } | |
63 | }, | |
64 | }; | |
65 | var graph = document.getElementById("graph"); | |
66 | var data = "X,Y,Z\n1,0,0\n"; | |
89fdcedb | 67 | var g = new Dygraph(graph, data, opts); |
0fe209e5 | 68 | |
89fdcedb DV |
69 | assert.equal(5, g.getOption("pointSize")); |
70 | assert.equal(4, g.getOption("pointSize", "Y")); | |
71 | assert.equal(5, g.getOption("pointSize", "Z")); | |
72 | }); | |
0fe209e5 | 73 | |
6ad8b6a4 | 74 | // TODO(konigsberg): move to multiple_axes.js |
89fdcedb | 75 | it('testAxisInNewSeries', function() { |
632bd78c | 76 | var opts = { |
632bd78c RK |
77 | series : { |
78 | D : { axis : 'y2' }, | |
79 | C : { axis : 1 }, | |
80 | B : { axis : 0 }, | |
81 | E : { axis : 'y' } | |
82 | } | |
83 | }; | |
84 | var graph = document.getElementById("graph"); | |
85 | var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; | |
89fdcedb | 86 | var g = new Dygraph(graph, data, opts); |
632bd78c | 87 | |
89fdcedb DV |
88 | assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0)); |
89 | assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1)); | |
90 | }); | |
632bd78c | 91 | |
6ad8b6a4 | 92 | // TODO(konigsberg): move to multiple_axes.js |
89fdcedb | 93 | it('testAxisInNewSeries_withAxes', function() { |
632bd78c RK |
94 | var opts = { |
95 | series : { | |
96 | D : { axis : 'y2' }, | |
97 | C : { axis : 1 }, | |
98 | B : { axis : 0 }, | |
99 | E : { axis : 'y' } | |
100 | }, | |
101 | axes : { | |
6ad8b6a4 RK |
102 | y : { pointSize : 7 }, |
103 | y2 : { pointSize : 6 } | |
632bd78c RK |
104 | } |
105 | }; | |
106 | var graph = document.getElementById("graph"); | |
107 | var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; | |
89fdcedb | 108 | var g = new Dygraph(graph, data, opts); |
632bd78c | 109 | |
89fdcedb DV |
110 | assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0)); |
111 | assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1)); | |
6ad8b6a4 | 112 | |
89fdcedb DV |
113 | assert.equal(1.5, g.getOption("pointSize")); |
114 | assert.equal(7, g.getOption("pointSize", "A")); | |
115 | assert.equal(7, g.getOption("pointSize", "B")); | |
116 | assert.equal(6, g.getOption("pointSize", "C")); | |
117 | assert.equal(6, g.getOption("pointSize", "D")); | |
118 | assert.equal(7, g.getOption("pointSize", "E")); | |
119 | }); | |
cee95ae0 RK |
120 | |
121 | // TODO(konigsberg): move to multiple_axes.js | |
89fdcedb | 122 | it('testOldAxisSpecInNewSeriesThrows', function() { |
cee95ae0 RK |
123 | var opts = { |
124 | series : { | |
125 | D : { axis : {} }, | |
126 | }, | |
127 | }; | |
128 | var graph = document.getElementById("graph"); | |
129 | var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n"; | |
3060c38b | 130 | var threw = false; |
cee95ae0 RK |
131 | try { |
132 | new Dygraph(graph, data, opts); | |
133 | } catch(e) { | |
3060c38b | 134 | threw = true; |
cee95ae0 | 135 | } |
3060c38b | 136 | |
89fdcedb DV |
137 | assert.isTrue(threw); |
138 | }); | |
48423521 | 139 | |
89fdcedb | 140 | it('testColorOption', function() { |
48423521 RK |
141 | var graph = document.getElementById("graph"); |
142 | var data = "X,A,B,C\n0,1,2,3\n"; | |
143 | var g = new Dygraph(graph, data, {}); | |
89fdcedb | 144 | assert.deepEqual(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g.getColors()); |
48423521 | 145 | g.updateOptions({series : { B : { color : 'purple' }}}); |
89fdcedb DV |
146 | assert.deepEqual(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g.getColors()); |
147 | }); | |
148 | ||
149 | }); |