Remove old-style series specifications.
[dygraphs.git] / auto_tests / tests / per_series.js
1 /**
2 * @fileoverview Tests for per-series options.
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
6 var perSeriesTestCase = TestCase("per-series");
7
8 perSeriesTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10 };
11
12 perSeriesTestCase.prototype.tearDown = function() {
13 };
14
15 perSeriesTestCase.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
52 perSeriesTestCase.prototype.testNewStyleSeries = function() {
53 var opts = {
54 pointSize : 5,
55 series : {
56 Y: { pointSize : 4 }
57 },
58 };
59 var graph = document.getElementById("graph");
60 var data = "X,Y,Z\n1,0,0\n";
61 g = new Dygraph(graph, data, opts);
62
63 assertEquals(5, g.getOption("pointSize"));
64 assertEquals(4, g.getOption("pointSize", "Y"));
65 assertEquals(5, g.getOption("pointSize", "Z"));
66 };
67
68 // TODO(konigsberg): move to multiple_axes.js
69 perSeriesTestCase.prototype.testAxisInNewSeries = function() {
70 var opts = {
71 series : {
72 D : { axis : 'y2' },
73 C : { axis : 1 },
74 B : { axis : 0 },
75 E : { axis : 'y' }
76 }
77 };
78 var graph = document.getElementById("graph");
79 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
80 g = new Dygraph(graph, data, opts);
81
82 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
83 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
84 };
85
86 // TODO(konigsberg): move to multiple_axes.js
87 perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() {
88 var opts = {
89 series : {
90 D : { axis : 'y2' },
91 C : { axis : 1 },
92 B : { axis : 0 },
93 E : { axis : 'y' }
94 },
95 axes : {
96 y : { pointSize : 7 },
97 y2 : { pointSize : 6 }
98 }
99 };
100 var graph = document.getElementById("graph");
101 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
102 g = new Dygraph(graph, data, opts);
103
104 assertEquals(["A", "B", "E"], g.attributes_.seriesForAxis(0));
105 assertEquals(["C", "D"], g.attributes_.seriesForAxis(1));
106
107 assertEquals(1.5, g.getOption("pointSize"));
108 assertEquals(7, g.getOption("pointSize", "A"));
109 assertEquals(7, g.getOption("pointSize", "B"));
110 assertEquals(6, g.getOption("pointSize", "C"));
111 assertEquals(6, g.getOption("pointSize", "D"));
112 assertEquals(7, g.getOption("pointSize", "E"));
113 };
114
115 // TODO(konigsberg): move to multiple_axes.js
116 perSeriesTestCase.prototype.testOldAxisSpecInNewSeriesThrows = function() {
117 var opts = {
118 series : {
119 D : { axis : {} },
120 },
121 };
122 var graph = document.getElementById("graph");
123 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
124 var threw = false;
125 try {
126 new Dygraph(graph, data, opts);
127 } catch(e) {
128 threw = true;
129 }
130
131 assertTrue(threw);
132 }
133
134 perSeriesTestCase.prototype.testColorOption = function() {
135 var graph = document.getElementById("graph");
136 var data = "X,A,B,C\n0,1,2,3\n";
137 var g = new Dygraph(graph, data, {});
138 assertEquals(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g.getColors());
139 g.updateOptions({series : { B : { color : 'purple' }}});
140 assertEquals(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g.getColors());
141 }