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() {
24 Y
: { fillGraph
: true },
26 colors
: [ '#FF0000', '#0000FF' ],
29 var data
= "X,Y,Z\n" +
40 var graph
= document
.getElementById("graph");
41 g
= new Dygraph(graph
, data
, opts
);
43 var sampler
= new PixelSampler(g
);
45 // Inside of the "Z" bump -- no fill.
46 assertEquals([0,0,0,0], sampler
.colorAtCoordinate(2.5, 0.5));
48 // Inside of the "Y" bump -- filled in.
49 assertEquals([255,0,0,38], sampler
.colorAtCoordinate(6.5, 0.5));
52 perSeriesTestCase
.prototype.testOldStyleSeries
= function() {
57 var graph
= document
.getElementById("graph");
58 var data
= "X,Y,Z\n1,0,0\n";
59 g
= new Dygraph(graph
, data
, opts
);
61 assertEquals(5, g
.getOption("pointSize"));
62 assertEquals(4, g
.getOption("pointSize", "Y"));
63 assertEquals(5, g
.getOption("pointSize", "Z"));
66 perSeriesTestCase
.prototype.testNewStyleSeries
= function() {
73 var graph
= document
.getElementById("graph");
74 var data
= "X,Y,Z\n1,0,0\n";
75 g
= new Dygraph(graph
, data
, opts
);
77 assertEquals(5, g
.getOption("pointSize"));
78 assertEquals(4, g
.getOption("pointSize", "Y"));
79 assertEquals(5, g
.getOption("pointSize", "Z"));
82 perSeriesTestCase
.prototype.testNewStyleSeriesTrumpsOldStyle
= function() {
85 Z
: { pointSize
: 6 },
90 var graph
= document
.getElementById("graph");
91 var data
= "X,Y,Z\n1,0,0\n";
92 g
= new Dygraph(graph
, data
, opts
);
94 assertEquals(5, g
.getOption("pointSize"));
95 assertEquals(4, g
.getOption("pointSize", "Y"));
96 assertEquals(5, g
.getOption("pointSize", "Z"));
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"));
105 // TODO(konigsberg): move to multiple_axes.js
106 perSeriesTestCase
.prototype.testAxisInNewSeries
= function() {
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
);
119 assertEquals(["A", "B", "E"], g
.attributes_
.seriesForAxis(0));
120 assertEquals(["C", "D"], g
.attributes_
.seriesForAxis(1));
123 // TODO(konigsberg): move to multiple_axes.js
124 perSeriesTestCase
.prototype.testAxisInNewSeries_withAxes
= function() {
133 y
: { pointSize
: 7 },
134 y2
: { pointSize
: 6 }
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
);
141 assertEquals(["A", "B", "E"], g
.attributes_
.seriesForAxis(0));
142 assertEquals(["C", "D"], g
.attributes_
.seriesForAxis(1));
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"));
152 // TODO(konigsberg): move to multiple_axes.js
153 perSeriesTestCase
.prototype.testOldAxisSpecInNewSeriesThrows
= function() {
159 var graph
= document
.getElementById("graph");
160 var data
= "X,A,B,C,D,E\n0,1,2,3,4,5\n";
163 new Dygraph(graph
, data
, opts
);
171 perSeriesTestCase
.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());