Rewrite tests to use ES6 modules.
[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 */
e2d8db3a 6
e8c70e4e
DV
7import Dygraph from '../../src/dygraph';
8
9import PixelSampler from './PixelSampler';
10
11describe("per-series", function() {
e2d8db3a 12
e8c70e4e 13cleanupAfterEach();
e2d8db3a 14
89fdcedb 15it('testPerSeriesFill', function() {
e2d8db3a
DV
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");
89fdcedb 47 var g = new Dygraph(graph, data, opts);
e2d8db3a
DV
48
49 var sampler = new PixelSampler(g);
50
51 // Inside of the "Z" bump -- no fill.
89fdcedb 52 assert.deepEqual([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5));
e2d8db3a
DV
53
54 // Inside of the "Y" bump -- filled in.
89fdcedb
DV
55 assert.deepEqual([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5));
56});
e2d8db3a 57
17bdb194
TL
58it('testPerSeriesAlpha', function() {
59 var opts = {
60 width: 480,
61 height: 320,
62 axes : {
63 x : {
64 drawGrid: false,
65 drawAxis: false,
66 },
67 y : {
68 drawGrid: false,
69 drawAxis: false,
70 }
71 },
72 series: {
73 Y: { fillGraph: true, fillAlpha: 0.25 },
74 Z: { fillGraph: true, fillAlpha: 0.75 }
75 },
76 colors: [ '#FF0000', '#0000FF' ]
77 };
78 var data = "X,Y,Z\n" +
79 "1,0,0\n" +
80 "2,0,1\n" +
81 "3,0,1\n" +
82 "4,0,0\n" +
83 "5,0,0\n" +
84 "6,1,0\n" +
85 "7,1,0\n" +
86 "8,0,0\n"
87 ;
88
89 var graph = document.getElementById("graph");
90 var g = new Dygraph(graph, data, opts);
91
92 var sampler = new PixelSampler(g);
93
94 // Inside of the "Y" bump -- 5% alpha.
95 assert.deepEqual([255,0,0,63], sampler.colorAtCoordinate(6.5, 0.5));
96
97 // Inside of the "Z" bump -- 95% alpha.
98 assert.deepEqual([0,0,255,191], sampler.colorAtCoordinate(2.5, 0.5));
99});
100
89fdcedb 101it('testNewStyleSeries', function() {
0fe209e5
RK
102 var opts = {
103 pointSize : 5,
104 series : {
105 Y: { pointSize : 4 }
106 },
107 };
108 var graph = document.getElementById("graph");
109 var data = "X,Y,Z\n1,0,0\n";
89fdcedb 110 var g = new Dygraph(graph, data, opts);
0fe209e5 111
89fdcedb
DV
112 assert.equal(5, g.getOption("pointSize"));
113 assert.equal(4, g.getOption("pointSize", "Y"));
114 assert.equal(5, g.getOption("pointSize", "Z"));
115});
0fe209e5 116
6ad8b6a4 117// TODO(konigsberg): move to multiple_axes.js
89fdcedb 118it('testAxisInNewSeries', function() {
632bd78c 119 var opts = {
632bd78c
RK
120 series : {
121 D : { axis : 'y2' },
122 C : { axis : 1 },
123 B : { axis : 0 },
124 E : { axis : 'y' }
125 }
126 };
127 var graph = document.getElementById("graph");
128 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
89fdcedb 129 var g = new Dygraph(graph, data, opts);
632bd78c 130
89fdcedb
DV
131 assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0));
132 assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1));
133});
632bd78c 134
6ad8b6a4 135// TODO(konigsberg): move to multiple_axes.js
89fdcedb 136it('testAxisInNewSeries_withAxes', function() {
632bd78c
RK
137 var opts = {
138 series : {
139 D : { axis : 'y2' },
140 C : { axis : 1 },
141 B : { axis : 0 },
142 E : { axis : 'y' }
143 },
144 axes : {
6ad8b6a4
RK
145 y : { pointSize : 7 },
146 y2 : { pointSize : 6 }
632bd78c
RK
147 }
148 };
149 var graph = document.getElementById("graph");
150 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
89fdcedb 151 var g = new Dygraph(graph, data, opts);
632bd78c 152
89fdcedb
DV
153 assert.deepEqual(["A", "B", "E"], g.attributes_.seriesForAxis(0));
154 assert.deepEqual(["C", "D"], g.attributes_.seriesForAxis(1));
6ad8b6a4 155
89fdcedb
DV
156 assert.equal(1.5, g.getOption("pointSize"));
157 assert.equal(7, g.getOption("pointSize", "A"));
158 assert.equal(7, g.getOption("pointSize", "B"));
159 assert.equal(6, g.getOption("pointSize", "C"));
160 assert.equal(6, g.getOption("pointSize", "D"));
161 assert.equal(7, g.getOption("pointSize", "E"));
162});
cee95ae0
RK
163
164// TODO(konigsberg): move to multiple_axes.js
89fdcedb 165it('testOldAxisSpecInNewSeriesThrows', function() {
cee95ae0
RK
166 var opts = {
167 series : {
168 D : { axis : {} },
169 },
170 };
171 var graph = document.getElementById("graph");
172 var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
3060c38b 173 var threw = false;
cee95ae0
RK
174 try {
175 new Dygraph(graph, data, opts);
176 } catch(e) {
3060c38b 177 threw = true;
cee95ae0 178 }
3060c38b 179
89fdcedb
DV
180 assert.isTrue(threw);
181});
48423521 182
89fdcedb 183it('testColorOption', function() {
48423521
RK
184 var graph = document.getElementById("graph");
185 var data = "X,A,B,C\n0,1,2,3\n";
186 var g = new Dygraph(graph, data, {});
89fdcedb 187 assert.deepEqual(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g.getColors());
48423521 188 g.updateOptions({series : { B : { color : 'purple' }}});
89fdcedb
DV
189 assert.deepEqual(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g.getColors());
190});
191
192});