Remove legacy options:
[dygraphs.git] / auto_tests / tests / per_series.js
CommitLineData
e2d8db3a 1/**
30abcfb6 2 * @fileoverview Tests for per-series options.
e2d8db3a
DV
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
5bd8dcae 6var perSeriesTestCase = TestCase("per-series");
e2d8db3a
DV
7
8perSeriesTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10};
11
12perSeriesTestCase.prototype.tearDown = function() {
13};
14
e2d8db3a
DV
15perSeriesTestCase.prototype.testPerSeriesFill = function() {
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");
47 g = new Dygraph(graph, data, opts);
48
49 var sampler = new PixelSampler(g);
50
51 // Inside of the "Z" bump -- no fill.
52 assertEquals([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5));
53
54 // Inside of the "Y" bump -- filled in.
55 assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5));
56};
57
30abcfb6
RK
58perSeriesTestCase.prototype.testOldStyleSeries = function() {
59 var opts = {
5bd8dcae 60 pointSize : 5,
30abcfb6
RK
61 Y: { pointSize : 4 },
62 };
0fe209e5
RK
63 var graph = document.getElementById("graph");
64 var data = "X,Y,Z\n1,0,0\n";
65 g = new Dygraph(graph, data, opts);
66
67 assertEquals(5, g.getOption("pointSize"));
68 assertEquals(4, g.getOption("pointSize", "Y"));
69 assertEquals(5, g.getOption("pointSize", "Z"));
70};
71
72perSeriesTestCase.prototype.testNewStyleSeries = function() {
73 var opts = {
74 pointSize : 5,
75 series : {
76 Y: { pointSize : 4 }
77 },
78 };
79 var graph = document.getElementById("graph");
80 var data = "X,Y,Z\n1,0,0\n";
81 g = new Dygraph(graph, data, opts);
82
83 assertEquals(5, g.getOption("pointSize"));
84 assertEquals(4, g.getOption("pointSize", "Y"));
85 assertEquals(5, g.getOption("pointSize", "Z"));
86};
87
88perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() {
89 var opts = {
90 pointSize : 5,
91 Z : { pointSize : 6 },
92 series : {
93 Y: { pointSize : 4 }
94 },
95 };
96 var graph = document.getElementById("graph");
30abcfb6 97 var data = "X,Y,Z\n1,0,0\n";
0fe209e5 98 g = new Dygraph(graph, data, opts);
30abcfb6
RK
99
100 assertEquals(5, g.getOption("pointSize"));
101 assertEquals(4, g.getOption("pointSize", "Y"));
102 assertEquals(5, g.getOption("pointSize", "Z"));
0fe209e5
RK
103
104 // Erase the series object, and Z will become visible again.
105 g.updateOptions({ series : undefined });
106 assertEquals(5, g.getOption("pointSize"));
107 assertEquals(6, g.getOption("pointSize", "Z"));
108 assertEquals(5, g.getOption("pointSize", "Y"));
30abcfb6
RK
109};
110
6ad8b6a4 111// TODO(konigsberg): move to multiple_axes.js
632bd78c
RK
112perSeriesTestCase.prototype.testAxisInNewSeries = function() {
113 var opts = {
632bd78c
RK
114 series : {
115 D : { axis : 'y2' },
116 C : { axis : 1 },
117 B : { axis : 0 },
118 E : { axis : 'y' }
119 }
120 };
121 var graph = document.getElementById("graph");
122 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
123 g = new Dygraph(graph, data, opts);
124
6ad8b6a4
RK
125 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
126 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
632bd78c
RK
127};
128
6ad8b6a4 129// TODO(konigsberg): move to multiple_axes.js
632bd78c
RK
130perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() {
131 var opts = {
132 series : {
133 D : { axis : 'y2' },
134 C : { axis : 1 },
135 B : { axis : 0 },
136 E : { axis : 'y' }
137 },
138 axes : {
6ad8b6a4
RK
139 y : { pointSize : 7 },
140 y2 : { pointSize : 6 }
632bd78c
RK
141 }
142 };
143 var graph = document.getElementById("graph");
144 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
145 g = new Dygraph(graph, data, opts);
146
6ad8b6a4
RK
147 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
148 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
149
150 assertEquals(1.5, g.getOption("pointSize"));
151 assertEquals(7, g.getOption("pointSize", "A"));
152 assertEquals(7, g.getOption("pointSize", "B"));
153 assertEquals(6, g.getOption("pointSize", "C"));
154 assertEquals(6, g.getOption("pointSize", "D"));
155 assertEquals(7, g.getOption("pointSize", "E"));
632bd78c 156};
cee95ae0
RK
157
158// TODO(konigsberg): move to multiple_axes.js
159perSeriesTestCase.prototype.testOldAxisSpecInNewSeriesThrows = function() {
160 var opts = {
161 series : {
162 D : { axis : {} },
163 },
164 };
165 var graph = document.getElementById("graph");
166 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
3060c38b 167 var threw = false;
cee95ae0
RK
168 try {
169 new Dygraph(graph, data, opts);
170 } catch(e) {
3060c38b 171 threw = true;
cee95ae0 172 }
3060c38b
DV
173
174 assertTrue(threw);
cee95ae0 175}
48423521
RK
176
177perSeriesTestCase.prototype.testColorOption = function() {
178 var graph = document.getElementById("graph");
179 var data = "X,A,B,C\n0,1,2,3\n";
180 var g = new Dygraph(graph, data, {});
181 assertEquals(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g.getColors());
182 g.updateOptions({series : { B : { color : 'purple' }}});
183 assertEquals(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g.getColors());
184}