Merge
[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,
19 drawXGrid: false,
20 drawYGrid: false,
21 drawXAxis: false,
22 drawYAxis: false,
8887663f
DV
23 series: {
24 Y: { fillGraph: true },
25 },
e2d8db3a
DV
26 colors: [ '#FF0000', '#0000FF' ],
27 fillAlpha: 0.15
28 };
29 var data = "X,Y,Z\n" +
30 "1,0,0\n" +
31 "2,0,1\n" +
32 "3,0,1\n" +
33 "4,0,0\n" +
34 "5,0,0\n" +
35 "6,1,0\n" +
36 "7,1,0\n" +
37 "8,0,0\n"
38 ;
39
40 var graph = document.getElementById("graph");
41 g = new Dygraph(graph, data, opts);
42
43 var sampler = new PixelSampler(g);
44
45 // Inside of the "Z" bump -- no fill.
46 assertEquals([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5));
47
48 // Inside of the "Y" bump -- filled in.
49 assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5));
50};
51
30abcfb6
RK
52perSeriesTestCase.prototype.testOldStyleSeries = function() {
53 var opts = {
5bd8dcae 54 pointSize : 5,
30abcfb6
RK
55 Y: { pointSize : 4 },
56 };
0fe209e5
RK
57 var graph = document.getElementById("graph");
58 var data = "X,Y,Z\n1,0,0\n";
59 g = new Dygraph(graph, data, opts);
60
61 assertEquals(5, g.getOption("pointSize"));
62 assertEquals(4, g.getOption("pointSize", "Y"));
63 assertEquals(5, g.getOption("pointSize", "Z"));
64};
65
66perSeriesTestCase.prototype.testNewStyleSeries = function() {
67 var opts = {
68 pointSize : 5,
69 series : {
70 Y: { pointSize : 4 }
71 },
72 };
73 var graph = document.getElementById("graph");
74 var data = "X,Y,Z\n1,0,0\n";
75 g = new Dygraph(graph, data, opts);
76
77 assertEquals(5, g.getOption("pointSize"));
78 assertEquals(4, g.getOption("pointSize", "Y"));
79 assertEquals(5, g.getOption("pointSize", "Z"));
80};
81
82perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() {
83 var opts = {
84 pointSize : 5,
85 Z : { pointSize : 6 },
86 series : {
87 Y: { pointSize : 4 }
88 },
89 };
90 var graph = document.getElementById("graph");
30abcfb6 91 var data = "X,Y,Z\n1,0,0\n";
0fe209e5 92 g = new Dygraph(graph, data, opts);
30abcfb6
RK
93
94 assertEquals(5, g.getOption("pointSize"));
95 assertEquals(4, g.getOption("pointSize", "Y"));
96 assertEquals(5, g.getOption("pointSize", "Z"));
0fe209e5
RK
97
98 // Erase the series object, and Z will become visible again.
99 g.updateOptions({ series : undefined });
100 assertEquals(5, g.getOption("pointSize"));
101 assertEquals(6, g.getOption("pointSize", "Z"));
102 assertEquals(5, g.getOption("pointSize", "Y"));
30abcfb6
RK
103};
104
6ad8b6a4 105// TODO(konigsberg): move to multiple_axes.js
632bd78c
RK
106perSeriesTestCase.prototype.testAxisInNewSeries = function() {
107 var opts = {
632bd78c
RK
108 series : {
109 D : { axis : 'y2' },
110 C : { axis : 1 },
111 B : { axis : 0 },
112 E : { axis : 'y' }
113 }
114 };
115 var graph = document.getElementById("graph");
116 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
117 g = new Dygraph(graph, data, opts);
118
6ad8b6a4
RK
119 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
120 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
632bd78c
RK
121};
122
6ad8b6a4 123// TODO(konigsberg): move to multiple_axes.js
632bd78c
RK
124perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() {
125 var opts = {
126 series : {
127 D : { axis : 'y2' },
128 C : { axis : 1 },
129 B : { axis : 0 },
130 E : { axis : 'y' }
131 },
132 axes : {
6ad8b6a4
RK
133 y : { pointSize : 7 },
134 y2 : { pointSize : 6 }
632bd78c
RK
135 }
136 };
137 var graph = document.getElementById("graph");
138 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
139 g = new Dygraph(graph, data, opts);
140
6ad8b6a4
RK
141 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
142 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
143
144 assertEquals(1.5, g.getOption("pointSize"));
145 assertEquals(7, g.getOption("pointSize", "A"));
146 assertEquals(7, g.getOption("pointSize", "B"));
147 assertEquals(6, g.getOption("pointSize", "C"));
148 assertEquals(6, g.getOption("pointSize", "D"));
149 assertEquals(7, g.getOption("pointSize", "E"));
632bd78c 150};
cee95ae0
RK
151
152// TODO(konigsberg): move to multiple_axes.js
153perSeriesTestCase.prototype.testOldAxisSpecInNewSeriesThrows = function() {
154 var opts = {
155 series : {
156 D : { axis : {} },
157 },
158 };
159 var graph = document.getElementById("graph");
160 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
3060c38b 161 var threw = false;
cee95ae0
RK
162 try {
163 new Dygraph(graph, data, opts);
164 } catch(e) {
3060c38b 165 threw = true;
cee95ae0 166 }
3060c38b
DV
167
168 assertTrue(threw);
cee95ae0 169}
48423521
RK
170
171perSeriesTestCase.prototype.testColorOption = function() {
172 var graph = document.getElementById("graph");
173 var data = "X,A,B,C\n0,1,2,3\n";
174 var g = new Dygraph(graph, data, {});
175 assertEquals(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g.getColors());
176 g.updateOptions({series : { B : { color : 'purple' }}});
177 assertEquals(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g.getColors());
178}