Start working on new-version axis support. Tests still fail.
[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
632bd78c
RK
103perSeriesTestCase.prototype.testAxisInNewSeries = function() {
104 var opts = {
105 logscale: true,
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
117 assertEquals(5, g.getOption("pointSize"));
118 assertEquals(4, g.getOption("pointSize", "Y"));
119 assertEquals(5, g.getOption("pointSize", "Z"));
120};
121
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 : {
131 y : {},
132 y2 : {}
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
139 assertEquals(5, g.getOption("pointSize"));
140 assertEquals(4, g.getOption("pointSize", "Y"));
141 assertEquals(5, g.getOption("pointSize", "Z"));
142};