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