2 * @fileoverview Tests for per-series options.
4 * @author danvk@google.com (Dan Vanderkam)
6 var perSeriesTestCase
= TestCase("per-series");
8 perSeriesTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 perSeriesTestCase
.prototype.tearDown
= function() {
15 perSeriesTestCase
.prototype.testPerSeriesFill
= function() {
30 Y
: { fillGraph
: true },
32 colors
: [ '#FF0000', '#0000FF' ],
35 var data
= "X,Y,Z\n" +
46 var graph
= document
.getElementById("graph");
47 g
= new Dygraph(graph
, data
, opts
);
49 var sampler
= new PixelSampler(g
);
51 // Inside of the "Z" bump -- no fill.
52 assertEquals([0,0,0,0], sampler
.colorAtCoordinate(2.5, 0.5));
54 // Inside of the "Y" bump -- filled in.
55 assertEquals([255,0,0,38], sampler
.colorAtCoordinate(6.5, 0.5));
58 perSeriesTestCase
.prototype.testOldStyleSeries
= function() {
63 var graph
= document
.getElementById("graph");
64 var data
= "X,Y,Z\n1,0,0\n";
65 g
= new Dygraph(graph
, data
, opts
);
67 assertEquals(5, g
.getOption("pointSize"));
68 assertEquals(4, g
.getOption("pointSize", "Y"));
69 assertEquals(5, g
.getOption("pointSize", "Z"));
72 perSeriesTestCase
.prototype.testNewStyleSeries
= function() {
79 var graph
= document
.getElementById("graph");
80 var data
= "X,Y,Z\n1,0,0\n";
81 g
= new Dygraph(graph
, data
, opts
);
83 assertEquals(5, g
.getOption("pointSize"));
84 assertEquals(4, g
.getOption("pointSize", "Y"));
85 assertEquals(5, g
.getOption("pointSize", "Z"));
88 perSeriesTestCase
.prototype.testNewStyleSeriesTrumpsOldStyle
= function() {
91 Z
: { pointSize
: 6 },
96 var graph
= document
.getElementById("graph");
97 var data
= "X,Y,Z\n1,0,0\n";
98 g
= new Dygraph(graph
, data
, opts
);
100 assertEquals(5, g
.getOption("pointSize"));
101 assertEquals(4, g
.getOption("pointSize", "Y"));
102 assertEquals(5, g
.getOption("pointSize", "Z"));
104 // Erase the series object, and Z will become visible again.
105 g
.updateOptions({ series
: undefined
});
106 assertEquals(5, g
.getOption("pointSize"));
107 assertEquals(6, g
.getOption("pointSize", "Z"));
108 assertEquals(5, g
.getOption("pointSize", "Y"));
111 // TODO(konigsberg): move to multiple_axes.js
112 perSeriesTestCase
.prototype.testAxisInNewSeries
= function() {
121 var graph
= document
.getElementById("graph");
122 var data
= "X,A,B,C,D,E\n0,1,2,3,4,5\n";
123 g
= new Dygraph(graph
, data
, opts
);
125 assertEquals(["A", "B", "E"], g
.attributes_
.seriesForAxis(0));
126 assertEquals(["C", "D"], g
.attributes_
.seriesForAxis(1));
129 // TODO(konigsberg): move to multiple_axes.js
130 perSeriesTestCase
.prototype.testAxisInNewSeries_withAxes
= function() {
139 y
: { pointSize
: 7 },
140 y2
: { pointSize
: 6 }
143 var graph
= document
.getElementById("graph");
144 var data
= "X,A,B,C,D,E\n0,1,2,3,4,5\n";
145 g
= new Dygraph(graph
, data
, opts
);
147 assertEquals(["A", "B", "E"], g
.attributes_
.seriesForAxis(0));
148 assertEquals(["C", "D"], g
.attributes_
.seriesForAxis(1));
150 assertEquals(1.5, g
.getOption("pointSize"));
151 assertEquals(7, g
.getOption("pointSize", "A"));
152 assertEquals(7, g
.getOption("pointSize", "B"));
153 assertEquals(6, g
.getOption("pointSize", "C"));
154 assertEquals(6, g
.getOption("pointSize", "D"));
155 assertEquals(7, g
.getOption("pointSize", "E"));
158 // TODO(konigsberg): move to multiple_axes.js
159 perSeriesTestCase
.prototype.testOldAxisSpecInNewSeriesThrows
= function() {
165 var graph
= document
.getElementById("graph");
166 var data
= "X,A,B,C,D,E\n0,1,2,3,4,5\n";
169 new Dygraph(graph
, data
, opts
);
177 perSeriesTestCase
.prototype.testColorOption
= function() {
178 var graph
= document
.getElementById("graph");
179 var data
= "X,A,B,C\n0,1,2,3\n";
180 var g
= new Dygraph(graph
, data
, {});
181 assertEquals(['rgb(64,128,0)', 'rgb(64,0,128)', 'rgb(0,128,128)'], g
.getColors());
182 g
.updateOptions({series
: { B
: { color
: 'purple' }}});
183 assertEquals(['rgb(64,128,0)', 'purple', 'rgb(0,128,128)'], g
.getColors());