2 * @fileoverview Test cases for the option "stepPlot" especially for the scenario where the option is not set for the whole graph but for single series.
4 * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)
6 var StepTestCase
= TestCase("step_plot_per_series");
8 StepTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 StepTestCase
.origFunc
= Dygraph
.getContext
;
14 StepTestCase
.prototype.setUp
= function() {
15 document
.body
.innerHTML
= "<div id='graph'></div>";
16 Dygraph
.getContext
= function(canvas
) {
17 return new Proxy(StepTestCase
.origFunc(canvas
));
21 StepTestCase
.prototype.tearDown
= function() {
22 Dygraph
.getContext
= StepTestCase
.origFunc
;
25 StepTestCase
.prototype.testMixedModeStepAndLineFilled
= function() {
34 labels
: ["X", "Idle", "Used"],
36 Idle
: {stepPlot
: false},
37 Used
: {stepPlot
: true}
52 var graph
= document
.getElementById("graph");
53 var g
= new Dygraph(graph
, data
, opts
);
60 for (var i
= 0; i
< data
.length
- 1; i
++) {
63 var x2
= data
[i
+ 1][0];
66 var y2
= data
[i
+ 1][1];
68 // First series (line)
69 var xy1
= g
.toDomCoords(x1
, y1
);
70 var xy2
= g
.toDomCoords(x2
, y2
);
71 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
76 // Seconds series (step)
78 xy1
= g
.toDomCoords(x1
, y1
);
79 xy2
= g
.toDomCoords(x2
, y1
);
80 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
82 xy1
= g
.toDomCoords(x2
, y1
);
83 xy2
= g
.toDomCoords(x2
, y2
);
84 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
88 StepTestCase
.prototype.testMixedModeStepAndLineStackedAndFilled
= function() {
97 labels
: ["X", "Idle", "Used", "NotUsed", "Active"],
99 Idle
: {stepPlot
: false},
100 Used
: {stepPlot
: true},
101 NotUsed
: {stepPlot
: false},
102 Active
: {stepPlot
: true}
117 var graph
= document
.getElementById("graph");
118 var g
= new Dygraph(graph
, data
, opts
);
125 for (var i
= 0; i
< data
.length
- 1; i
++) {
128 var x2
= data
[i
+ 1][0];
132 var y2
= data
[i
+ 1][4];
135 // Fourth series (step)
138 var xy1
= g
.toDomCoords(x1
, y1
);
139 var xy2
= g
.toDomCoords(x2
, y1
);
140 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
142 xy1
= g
.toDomCoords(x2
, y1
);
143 xy2
= g
.toDomCoords(x2
, y2
);
144 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
146 // Test edges of areas (also drawn by dygraphs as lines)
147 xy1
= g
.toDomCoords(x1
, y1
);
148 xy2
= g
.toDomCoords(x2
, y1
);
149 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
151 xy2
= g
.toDomCoords(x2
, y2base
);
152 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
154 xy2
= g
.toDomCoords(x1
, y1base
);
155 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
157 xy2
= g
.toDomCoords(x1
, y1
);
158 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
163 y2
+= data
[i
+ 1][3];
165 // Third series (line)
167 xy1
= g
.toDomCoords(x1
, y1
);
168 xy2
= g
.toDomCoords(x2
, y2
);
169 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
171 // Test edges of areas (also drawn by dygraphs as lines)
172 xy1
= g
.toDomCoords(x1
, y1
);
173 xy2
= g
.toDomCoords(x2
, y2
);
174 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
176 xy2
= g
.toDomCoords(x2
, y2base
);
177 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
179 xy2
= g
.toDomCoords(x1
, y1base
);
180 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
182 xy2
= g
.toDomCoords(x1
, y1
);
183 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
188 y2
+= data
[i
+ 1][2];
190 // Second series (step)
193 xy1
= g
.toDomCoords(x1
, y1
);
194 xy2
= g
.toDomCoords(x2
, y1
);
195 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
197 xy1
= g
.toDomCoords(x2
, y1
);
198 xy2
= g
.toDomCoords(x2
, y2
);
199 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
201 // Test edges of areas (also drawn by dygraphs as lines)
202 xy1
= g
.toDomCoords(x1
, y1
);
203 xy2
= g
.toDomCoords(x2
, y1
);
204 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
206 xy2
= g
.toDomCoords(x2
, y2base
);
207 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
209 xy2
= g
.toDomCoords(x1
, y1base
);
210 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
212 xy2
= g
.toDomCoords(x1
, y1
);
213 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
218 y2
+= data
[i
+ 1][1];
220 // First series (line)
222 xy1
= g
.toDomCoords(x1
, y1
);
223 xy2
= g
.toDomCoords(x2
, y2
);
224 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
226 // Test edges of areas (also drawn by dygraphs as lines)
227 xy1
= g
.toDomCoords(x1
, y1
);
228 xy2
= g
.toDomCoords(x2
, y2
);
229 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
231 xy2
= g
.toDomCoords(x2
, y2base
);
232 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
234 xy2
= g
.toDomCoords(x1
, y1base
);
235 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
237 xy2
= g
.toDomCoords(x1
, y1
);
238 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
242 StepTestCase
.prototype.testMixedModeStepAndLineErrorBars
= function() {
252 labels
: ["X", "Data1", "Data2"],
254 Data1
: {stepPlot
: true},
255 Data2
: {stepPlot
: false}
259 [1, [75, 2], [50, 3]],
260 [2, [70, 5], [90, 4]],
261 [3, [80, 7], [112, 5]],
262 [4, [55, 3], [100, 2]],
263 [5, [69, 4], [85, 6]]
266 var graph
= document
.getElementById("graph");
267 var g
= new Dygraph(graph
, data
, opts
);
273 // Test first series (step)
274 for (var i
= 0; i
< data
.length
- 1; i
++) {
276 var x2
= data
[i
+ 1][0];
278 var y1_middle
= data
[i
][1][0];
279 var y2_middle
= data
[i
+ 1][1][0];
281 var y1_top
= y1_middle
+ data
[i
][1][1];
282 var y2_top
= y2_middle
+ data
[i
+ 1][1][1];
284 var y1_bottom
= y1_middle
- data
[i
][1][1];
285 var y2_bottom
= y2_middle
- data
[i
+ 1][1][1];
288 var xy1
= g
.toDomCoords(x1
, y1_bottom
);
289 var xy2
= g
.toDomCoords(x2
, y1_bottom
);
290 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
292 xy1
= g
.toDomCoords(x2
, y1_bottom
);
293 xy2
= g
.toDomCoords(x2
, y2_bottom
);
294 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
298 xy1
= g
.toDomCoords(x1
, y1_top
);
299 xy2
= g
.toDomCoords(x2
, y1_top
);
300 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
302 xy1
= g
.toDomCoords(x2
, y1_top
);
303 xy2
= g
.toDomCoords(x2
, y2_top
);
304 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
308 xy1
= g
.toDomCoords(x1
, y1_middle
);
309 xy2
= g
.toDomCoords(x2
, y1_middle
);
310 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
312 xy1
= g
.toDomCoords(x2
, y1_middle
);
313 xy2
= g
.toDomCoords(x2
, y2_middle
);
314 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
317 // Test second series (line)
318 for (var i
= 0; i
< data
.length
- 1; i
++) {
320 var xy1
= g
.toDomCoords(data
[i
][0], (data
[i
][2][0] - data
[i
][2][1]));
321 var xy2
= g
.toDomCoords(data
[i
+ 1][0], (data
[i
+ 1][2][0] - data
[i
+ 1][2][1]));
322 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
325 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0] + data
[i
][2][1]);
326 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0] + data
[i
+ 1][2][1]);
327 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
330 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0]);
331 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0]);
332 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
337 StepTestCase
.prototype.testMixedModeStepAndLineCustomBars
= function() {
346 labels
: ["X", "Data1", "Data2"],
348 Data1
: {stepPlot
: true},
349 Data2
: {stepPlot
: false}
353 [1, [73, 75, 78], [50, 55, 70]],
354 [2, [65, 70, 75], [83, 91, 99]],
355 [3, [75, 85, 90], [98, 107, 117]],
356 [4, [55, 58, 61], [93, 102, 105]],
357 [5, [69, 73, 85], [80, 85, 87]]
360 var graph
= document
.getElementById("graph");
361 var g
= new Dygraph(graph
, data
, opts
);
367 // Test first series (step)
368 for (var i
= 0; i
< data
.length
- 1; i
++) {
371 var x2
= data
[i
+ 1][0];
373 var y1_middle
= data
[i
][1][1];
374 var y2_middle
= data
[i
+ 1][1][1];
376 var y1_top
= data
[i
][1][2];
377 var y2_top
= data
[i
+ 1][1][2];
379 var y1_bottom
= data
[i
][1][0];
380 var y2_bottom
= data
[i
+ 1][1][0];
384 var xy1
= g
.toDomCoords(x1
, y1_bottom
);
385 var xy2
= g
.toDomCoords(x2
, y1_bottom
);
386 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
388 xy1
= g
.toDomCoords(x2
, y1_middle
);
389 xy2
= g
.toDomCoords(x2
, y2_middle
);
390 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
394 xy1
= g
.toDomCoords(x1
, y1_top
);
395 xy2
= g
.toDomCoords(x2
, y1_top
);
396 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
398 xy1
= g
.toDomCoords(x2
, y1_middle
);
399 xy2
= g
.toDomCoords(x2
, y2_middle
);
400 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
404 xy1
= g
.toDomCoords(x1
, y1_middle
);
405 xy2
= g
.toDomCoords(x2
, y1_middle
);
406 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
408 xy1
= g
.toDomCoords(x2
, y1_middle
);
409 xy2
= g
.toDomCoords(x2
, y2_middle
);
410 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
413 // Test second series (line)
414 for (var i
= 0; i
< data
.length
- 1; i
++) {
416 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0]);
417 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0]);
418 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
421 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][2]);
422 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][2]);
423 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
426 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][1]);
427 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][1]);
428 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);