Merge
[dygraphs.git] / auto_tests / tests / per_series.js
... / ...
CommitLineData
1/**
2 * @fileoverview Tests for per-series options.
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
6var perSeriesTestCase = TestCase("per-series");
7
8perSeriesTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10};
11
12perSeriesTestCase.prototype.tearDown = function() {
13};
14
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 series: {
24 Y: { fillGraph: true },
25 },
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
52perSeriesTestCase.prototype.testOldStyleSeries = function() {
53 var opts = {
54 pointSize : 5,
55 Y: { pointSize : 4 },
56 };
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");
91 var data = "X,Y,Z\n1,0,0\n";
92 g = new Dygraph(graph, data, opts);
93
94 assertEquals(5, g.getOption("pointSize"));
95 assertEquals(4, g.getOption("pointSize", "Y"));
96 assertEquals(5, g.getOption("pointSize", "Z"));
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"));
103};
104
105// TODO(konigsberg): move to multiple_axes.js
106perSeriesTestCase.prototype.testAxisInNewSeries = function() {
107 var opts = {
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
119 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
120 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
121};
122
123// TODO(konigsberg): move to multiple_axes.js
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 : {
133 y : { pointSize : 7 },
134 y2 : { pointSize : 6 }
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
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"));
150};
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";
161 var threw = false;
162 try {
163 new Dygraph(graph, data, opts);
164 } catch(e) {
165 threw = true;
166 }
167
168 assertTrue(threw);
169}
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}