805a65adc6cbe83e825326b4506062b84ee52035
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 * TODO(danvk): delete this test once dpxdt screenshot tests are part of the
5 * main dygraphs repo. The tests have extremely specific expectations about
6 * how drawing is performed. It's more realistic to test the resulting
9 * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)
12 import Dygraph from
'../../src/dygraph';
13 import * as utils from
'../../src/dygraph-utils';
15 import Proxy from
'./Proxy';
16 import CanvasAssertions from
'./CanvasAssertions';
18 describe("step-plot-per-series", function() {
21 useProxyCanvas(utils
, Proxy
);
23 it('testMixedModeStepAndLineFilled', function() {
38 labels
: ["X", "Idle", "Used"],
40 Idle
: {stepPlot
: false},
41 Used
: {stepPlot
: true}
56 var graph
= document
.getElementById("graph");
57 var g
= new Dygraph(graph
, data
, opts
);
59 var htx
= g
.hidden_ctx_
;
64 for (var i
= 0; i
< data
.length
- 1; i
++) {
67 var x2
= data
[i
+ 1][0];
70 var y2
= data
[i
+ 1][1];
72 // First series (line)
73 var xy1
= g
.toDomCoords(x1
, y1
);
74 var xy2
= g
.toDomCoords(x2
, y2
);
75 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
80 // Seconds series (step)
82 xy1
= g
.toDomCoords(x1
, y1
);
83 xy2
= g
.toDomCoords(x2
, y1
);
84 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
86 xy1
= g
.toDomCoords(x2
, y1
);
87 xy2
= g
.toDomCoords(x2
, y2
);
88 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
92 it('testMixedModeStepAndLineStackedAndFilled', function() {
107 labels
: ["X", "Idle", "Used", "NotUsed", "Active"],
109 Idle
: {stepPlot
: false},
110 Used
: {stepPlot
: true},
111 NotUsed
: {stepPlot
: false},
112 Active
: {stepPlot
: true}
127 var graph
= document
.getElementById("graph");
128 var g
= new Dygraph(graph
, data
, opts
);
130 var htx
= g
.hidden_ctx_
;
135 for (var i
= 0; i
< data
.length
- 1; i
++) {
138 var x2
= data
[i
+ 1][0];
142 var y2
= data
[i
+ 1][4];
144 // Fourth series (step)
147 var xy1
= g
.toDomCoords(x1
, y1
);
148 var xy2
= g
.toDomCoords(x2
, y1
);
149 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
151 xy1
= g
.toDomCoords(x2
, y1
);
152 xy2
= g
.toDomCoords(x2
, y2
);
153 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
155 // Test edges of areas (also drawn by dygraphs as lines)
156 xy1
= g
.toDomCoords(x1
, y1
);
157 xy2
= g
.toDomCoords(x2
, y1
);
158 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
160 xy2
= g
.toDomCoords(x2
, y2base
);
161 // CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
163 xy2
= g
.toDomCoords(x1
, y1base
);
164 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
165 // The last edge can not be tested via assertLineDrawn since it wasn't drawn as a line but via clossePath.
166 // But a rectangle is completely tested with three of its four edges.
171 y2
+= data
[i
+ 1][3];
173 // Third series (line)
175 xy1
= g
.toDomCoords(x1
, y1
);
176 xy2
= g
.toDomCoords(x2
, y2
);
177 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
179 // Test edges of areas (also drawn by dygraphs as lines)
180 xy1
= g
.toDomCoords(x1
, y1
);
181 xy2
= g
.toDomCoords(x2
, y2
);
182 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
184 xy2
= g
.toDomCoords(x2
, y2base
);
185 // CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
187 xy2
= g
.toDomCoords(x1
, y1base
);
188 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
189 // The last edge can not be tested via assertLineDrawn since it wasn't drawn as a line but via clossePath.
190 // But a rectangle is completely tested with three of its four edges.
195 y2
+= data
[i
+ 1][2];
197 // Second series (step)
200 xy1
= g
.toDomCoords(x1
, y1
);
201 xy2
= g
.toDomCoords(x2
, y1
);
202 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
204 xy1
= g
.toDomCoords(x2
, y1
);
205 xy2
= g
.toDomCoords(x2
, y2
);
206 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
208 // Test edges of areas (also drawn by dygraphs as lines)
209 xy1
= g
.toDomCoords(x1
, y1
);
210 xy2
= g
.toDomCoords(x2
, y1
);
211 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
213 xy2
= g
.toDomCoords(x2
, y2base
);
214 // CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
216 xy2
= g
.toDomCoords(x1
, y1base
);
217 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
218 // The last edge can not be tested via assertLineDrawn since it wasn't drawn as a line but via clossePath.
219 // But a rectangle is completely tested with three of its four edges.
224 y2
+= data
[i
+ 1][1];
226 // First series (line)
228 xy1
= g
.toDomCoords(x1
, y1
);
229 xy2
= g
.toDomCoords(x2
, y2
);
230 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
232 // Test edges of areas (also drawn by dygraphs as lines)
233 xy1
= g
.toDomCoords(x1
, y1
);
234 xy2
= g
.toDomCoords(x2
, y2
);
235 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
237 xy2
= g
.toDomCoords(x2
, y2base
);
238 // CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
240 xy2
= g
.toDomCoords(x1
, y1base
);
241 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
242 // The last edge can not be tested via assertLineDrawn since it wasn't drawn as a line but via clossePath.
243 // But a rectangle is completely tested with three of its four edges.
247 it('testMixedModeStepAndLineErrorBars', function() {
263 labels
: ["X", "Data1", "Data2"],
265 Data1
: {stepPlot
: true},
266 Data2
: {stepPlot
: false}
270 [1, [75, 2], [50, 3]],
271 [2, [70, 5], [90, 4]],
272 [3, [80, 7], [112, 5]],
273 [4, [55, 3], [100, 2]],
274 [5, [69, 4], [85, 6]]
277 var graph
= document
.getElementById("graph");
278 var g
= new Dygraph(graph
, data
, opts
);
280 var htx
= g
.hidden_ctx_
;
284 // Test first series (step)
285 for (var i
= 0; i
< data
.length
- 1; i
++) {
287 var x2
= data
[i
+ 1][0];
289 var y1_middle
= data
[i
][1][0];
290 var y2_middle
= data
[i
+ 1][1][0];
292 var y1_top
= y1_middle
+ data
[i
][1][1];
293 var y2_top
= y2_middle
+ data
[i
+ 1][1][1];
295 var y1_bottom
= y1_middle
- data
[i
][1][1];
296 var y2_bottom
= y2_middle
- data
[i
+ 1][1][1];
298 var xy1
= g
.toDomCoords(x1
, y1_bottom
);
299 var xy2
= g
.toDomCoords(x2
, y1_bottom
);
300 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
303 xy1
= g
.toDomCoords(x1
, y1_top
);
304 xy2
= g
.toDomCoords(x2
, y1_top
);
305 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 // Test edges of error bar areas(also drawn by dygraphs as lines)
313 xy1
= g
.toDomCoords(x1
, y1_top
);
314 xy2
= g
.toDomCoords(x2
, y1_top
);
315 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
317 xy2
= g
.toDomCoords(x2
, y1_bottom
);
318 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
320 xy2
= g
.toDomCoords(x1
, y1_bottom
);
321 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
322 // The last edge can not be tested via assertLineDrawn since it wasn't drawn as a line but via clossePath.
323 // But a rectangle is completely tested with three of its four edges.
326 // Test second series (line)
327 for (var i
= 0; i
< data
.length
- 1; i
++) {
329 var xy1
= g
.toDomCoords(data
[i
][0], (data
[i
][2][0] - data
[i
][2][1]));
330 var xy2
= g
.toDomCoords(data
[i
+ 1][0], (data
[i
+ 1][2][0] - data
[i
+ 1][2][1]));
331 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
334 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0] + data
[i
][2][1]);
335 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0] + data
[i
+ 1][2][1]);
336 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
339 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0]);
340 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0]);
341 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
346 it('testMixedModeStepAndLineCustomBars', function() {
361 labels
: ["X", "Data1", "Data2"],
363 Data1
: {stepPlot
: true},
364 Data2
: {stepPlot
: false}
368 [1, [73, 75, 78], [50, 55, 70]],
369 [2, [65, 70, 75], [83, 91, 99]],
370 [3, [75, 85, 90], [98, 107, 117]],
371 [4, [55, 58, 61], [93, 102, 105]],
372 [5, [69, 73, 85], [80, 85, 87]]
375 var graph
= document
.getElementById("graph");
376 var g
= new Dygraph(graph
, data
, opts
);
378 var htx
= g
.hidden_ctx_
;
382 // Test first series (step)
383 for (var i
= 0; i
< data
.length
- 1; i
++) {
386 var x2
= data
[i
+ 1][0];
388 var y1_middle
= data
[i
][1][1];
389 var y2_middle
= data
[i
+ 1][1][1];
391 var y1_top
= data
[i
][1][2];
392 var y2_top
= data
[i
+ 1][1][2];
394 var y1_bottom
= data
[i
][1][0];
395 var y2_bottom
= data
[i
+ 1][1][0];
398 var xy1
= g
.toDomCoords(x1
, y1_bottom
);
399 var xy2
= g
.toDomCoords(x2
, y1_bottom
);
400 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
403 xy1
= g
.toDomCoords(x1
, y1_top
);
404 xy2
= g
.toDomCoords(x2
, y1_top
);
405 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
408 xy1
= g
.toDomCoords(x1
, y1_middle
);
409 xy2
= g
.toDomCoords(x2
, y1_middle
);
410 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
412 // Test edges of custom bar areas(also drawn by dygraphs as lines)
413 xy1
= g
.toDomCoords(x1
, y1_top
);
414 xy2
= g
.toDomCoords(x2
, y1_top
);
415 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
417 xy2
= g
.toDomCoords(x2
, y1_bottom
);
418 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
420 xy2
= g
.toDomCoords(x1
, y1_bottom
);
421 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
422 // The last edge can not be tested via assertLineDrawn since it wasn't drawn as a line but via clossePath.
423 // But a rectangle is completely tested with three of its four edges.
426 // Test second series (line)
427 for (var i
= 0; i
< data
.length
- 1; i
++) {
429 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][0]);
430 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][0]);
431 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
434 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][2]);
435 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][2]);
436 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
439 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][2][1]);
440 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][2][1]);
441 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);