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("stepPlot_per_series");
8 stepTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 var _origFunc
= Dygraph
.getContext
;
13 stepTestCase
.prototype.setUp
= function() {
14 document
.body
.innerHTML
= "<div id='graph'></div>";
15 Dygraph
.getContext
= function(canvas
) {
16 return new Proxy(_origFunc(canvas
));
20 stepTestCase
.prototype.tearDown
= function() {
21 Dygraph
.getContext
= _origFunc
;
24 stepTestCase
.prototype.testMixedModeStepAndLineFilled
= function() {
33 labels
: ["X", "Idle", "Used"],
35 Idle
: {stepPlot
: false},
36 Used
: {stepPlot
: true}
51 var graph
= document
.getElementById("graph");
52 var g
= new Dygraph(graph
, data
, opts
);
59 for (var i
= 0; i
< data
.length
- 1; i
++) {
62 var x2
= data
[i
+ 1][0];
65 var y2
= data
[i
+ 1][1];
67 // First series (line)
68 var xy1
= g
.toDomCoords(x1
, y1
);
69 var xy2
= g
.toDomCoords(x2
, y2
);
70 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
75 // Seconds series (step)
77 xy1
= g
.toDomCoords(x1
, y1
);
78 xy2
= g
.toDomCoords(x2
, y1
);
79 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
81 xy1
= g
.toDomCoords(x2
, y1
);
82 xy2
= g
.toDomCoords(x2
, y2
);
83 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
87 stepTestCase
.prototype.testMixedModeStepAndLineStackedAndFilled
= function() {
96 labels
: ["X", "Idle", "Used", "NotUsed", "Active"],
98 Idle
: {stepPlot
: false},
99 Used
: {stepPlot
: true},
100 NotUsed
: {stepPlot
: false},
101 Active
: {stepPlot
: true}
116 var graph
= document
.getElementById("graph");
117 var g
= new Dygraph(graph
, data
, opts
);
124 for (var i
= 0; i
< data
.length
- 1; i
++) {
127 var x2
= data
[i
+ 1][0];
131 var y2
= data
[i
+ 1][4];
134 // Fourth series (step)
137 var xy1
= g
.toDomCoords(x1
, y1
);
138 var xy2
= g
.toDomCoords(x2
, y1
);
139 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
141 xy1
= g
.toDomCoords(x2
, y1
);
142 xy2
= g
.toDomCoords(x2
, y2
);
143 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
145 // Test edges of areas (also drawn by dygraphs as lines)
146 xy1
= g
.toDomCoords(x1
, y1
);
147 xy2
= g
.toDomCoords(x2
, y1
);
148 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
150 xy2
= g
.toDomCoords(x2
, y2base
);
151 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
153 xy2
= g
.toDomCoords(x1
, y1base
);
154 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
156 xy2
= g
.toDomCoords(x1
, y1
);
157 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
162 y2
+= data
[i
+ 1][3];
164 // Third series (line)
166 xy1
= g
.toDomCoords(x1
, y1
);
167 xy2
= g
.toDomCoords(x2
, y2
);
168 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
170 // Test edges of areas (also drawn by dygraphs as lines)
171 xy1
= g
.toDomCoords(x1
, y1
);
172 xy2
= g
.toDomCoords(x2
, y2
);
173 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
175 xy2
= g
.toDomCoords(x2
, y2base
);
176 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
178 xy2
= g
.toDomCoords(x1
, y1base
);
179 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
181 xy2
= g
.toDomCoords(x1
, y1
);
182 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
187 y2
+= data
[i
+ 1][2];
189 // Second series (step)
192 xy1
= g
.toDomCoords(x1
, y1
);
193 xy2
= g
.toDomCoords(x2
, y1
);
194 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
196 xy1
= g
.toDomCoords(x2
, y1
);
197 xy2
= g
.toDomCoords(x2
, y2
);
198 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
200 // Test edges of areas (also drawn by dygraphs as lines)
201 xy1
= g
.toDomCoords(x1
, y1
);
202 xy2
= g
.toDomCoords(x2
, y1
);
203 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
205 xy2
= g
.toDomCoords(x2
, y2base
);
206 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
208 xy2
= g
.toDomCoords(x1
, y1base
);
209 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
211 xy2
= g
.toDomCoords(x1
, y1
);
212 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
217 y2
+= data
[i
+ 1][1];
219 // First series (line)
221 xy1
= g
.toDomCoords(x1
, y1
);
222 xy2
= g
.toDomCoords(x2
, y2
);
223 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
225 // Test edges of areas (also drawn by dygraphs as lines)
226 xy1
= g
.toDomCoords(x1
, y1
);
227 xy2
= g
.toDomCoords(x2
, y2
);
228 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
230 xy2
= g
.toDomCoords(x2
, y2base
);
231 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
233 xy2
= g
.toDomCoords(x1
, y1base
);
234 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
236 xy2
= g
.toDomCoords(x1
, y1
);
237 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
241 stepTestCase
.prototype.testMixedModeStepAndLineErrorBars
= function() {
251 labels
: ["X", "Data1", "Data2"],
253 Data1
: {stepPlot
: true},
254 Data2
: {stepPlot
: false}
258 [1, [75, 2], [50, 3]],
259 [2, [70, 5], [90, 4]],
260 [3, [80, 7], [112, 5]],
261 [4, [55, 3], [100, 2]],
262 [5, [69, 4], [85, 6]]
265 var graph
= document
.getElementById("graph");
266 var g
= new Dygraph(graph
, data
, opts
);
272 // Test first series (step)
273 for (var i
= 0; i
< data
.length
- 1; i
++) {
275 var x2
= data
[i
+ 1][0];
277 var y1_middle
= data
[i
][1][0];
278 var y2_middle
= data
[i
+ 1][1][0];
280 var y1_top
= y1_middle
+ data
[i
][1][1];
281 var y2_top
= y2_middle
+ data
[i
+ 1][1][1];
283 var y1_bottom
= y1_middle
- data
[i
][1][1];
284 var y2_bottom
= y2_middle
- data
[i
+ 1][1][1];
287 var xy1
= g
.toDomCoords(x1
, y1_bottom
);
288 var xy2
= g
.toDomCoords(x2
, y1_bottom
);
289 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
291 xy1
= g
.toDomCoords(x2
, y1_bottom
);
292 xy2
= g
.toDomCoords(x2
, y2_bottom
);
293 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
297 xy1
= g
.toDomCoords(x1
, y1_top
);
298 xy2
= g
.toDomCoords(x2
, y1_top
);
299 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
301 xy1
= g
.toDomCoords(x2
, y1_top
);
302 xy2
= g
.toDomCoords(x2
, y2_top
);
303 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
307 xy1
= g
.toDomCoords(x1
, y1_middle
);
308 xy2
= g
.toDomCoords(x2
, y1_middle
);
309 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
311 xy1
= g
.toDomCoords(x2
, y1_middle
);
312 xy2
= g
.toDomCoords(x2
, y2_middle
);
313 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
316 // Test second series (line)
317 for (var i
= 0; i
< data
.length
- 1; i
++) {
319 var xy1
= g
.toDomCoords(data
[i
][0], (data
[i
][2][0] - data
[i
][2][1]));
320 var xy2
= g
.toDomCoords(data
[i
+ 1][0], (data
[i
+ 1][2][0] - data
[i
+ 1][2][1]));
321 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
324 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0] + data
[i
][2][1]);
325 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0] + data
[i
+ 1][2][1]);
326 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
329 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0]);
330 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0]);
331 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
336 stepTestCase
.prototype.testMixedModeStepAndLineCustomBars
= function() {
345 labels
: ["X", "Data1", "Data2"],
347 Data1
: {stepPlot
: true},
348 Data2
: {stepPlot
: false}
352 [1, [73, 75, 78], [50, 55, 70]],
353 [2, [65, 70, 75], [83, 91, 99]],
354 [3, [75, 85, 90], [98, 107, 117]],
355 [4, [55, 58, 61], [93, 102, 105]],
356 [5, [69, 73, 85], [80, 85, 87]]
359 var graph
= document
.getElementById("graph");
360 var g
= new Dygraph(graph
, data
, opts
);
366 // Test first series (step)
367 for (var i
= 0; i
< data
.length
- 1; i
++) {
370 var x2
= data
[i
+ 1][0];
372 var y1_middle
= data
[i
][1][1];
373 var y2_middle
= data
[i
+ 1][1][1];
375 var y1_top
= data
[i
][1][2];
376 var y2_top
= data
[i
+ 1][1][2];
378 var y1_bottom
= data
[i
][1][0];
379 var y2_bottom
= data
[i
+ 1][1][0];
383 var xy1
= g
.toDomCoords(x1
, y1_bottom
);
384 var xy2
= g
.toDomCoords(x2
, y1_bottom
);
385 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
387 xy1
= g
.toDomCoords(x2
, y1_middle
);
388 xy2
= g
.toDomCoords(x2
, y2_middle
);
389 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
393 xy1
= g
.toDomCoords(x1
, y1_top
);
394 xy2
= g
.toDomCoords(x2
, y1_top
);
395 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
397 xy1
= g
.toDomCoords(x2
, y1_middle
);
398 xy2
= g
.toDomCoords(x2
, y2_middle
);
399 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
403 xy1
= g
.toDomCoords(x1
, y1_middle
);
404 xy2
= g
.toDomCoords(x2
, y1_middle
);
405 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
407 xy1
= g
.toDomCoords(x2
, y1_middle
);
408 xy2
= g
.toDomCoords(x2
, y2_middle
);
409 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
412 // Test second series (line)
413 for (var i
= 0; i
< data
.length
- 1; i
++) {
415 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0]);
416 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0]);
417 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
420 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][2]);
421 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][2]);
422 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
425 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][1]);
426 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][1]);
427 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);