Add some power to the canvas assertions. Also, the canvas assertions weren't actually...
[dygraphs.git] / auto_tests / tests / error_bars.js
CommitLineData
f35016e8
DV
1/**
2 * @fileoverview FILL THIS IN
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
6var errorBarsTestCase = TestCase("error-bars");
7
8errorBarsTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10};
11
12var _origFunc = Dygraph.getContext;
13errorBarsTestCase.prototype.setUp = function() {
14 document.body.innerHTML = "<div id='graph'></div>";
15 Dygraph.getContext = function(canvas) {
16 return new Proxy(_origFunc(canvas));
17 }
18};
19
20errorBarsTestCase.prototype.tearDown = function() {
21 Dygraph.getContext = _origFunc;
22};
23
97583b90 24errorBarsTestCase.prototype.testErrorBarsDrawn = function() {
f35016e8
DV
25 var opts = {
26 width: 480,
27 height: 320,
28 drawXGrid: false,
29 drawYGrid: false,
30 drawXAxis: false,
31 drawYAxis: false,
32 customBars: true,
33 errorBars: true
34 };
35 var data = [
36 [1, [10, 10, 100]],
37 [2, [15, 20, 110]],
38 [3, [10, 30, 100]],
39 [4, [15, 40, 110]],
40 [5, [10, 120, 100]],
41 [6, [15, 50, 110]],
42 [7, [10, 70, 100]],
43 [8, [15, 90, 110]],
44 [9, [10, 50, 100]]
45 ];
46
47 var graph = document.getElementById("graph");
48 var g = new Dygraph(graph, data, opts);
49
50 htx = g.hidden_ctx_;
51
52 var attrs = {}; // TODO(danvk): fill in
53
54 for (var i = 0; i < data.length - 1; i++) {
55 // bottom line
56 var xy1 = g.toDomCoords(data[i][0], data[i][1][0]);
57 var xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][0]);
58 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
59
60 // top line
61 xy1 = g.toDomCoords(data[i][0], data[i][1][2]);
62 xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][2]);
63 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
64
65 // middle line
66 xy1 = g.toDomCoords(data[i][0], data[i][1][1]);
67 xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][1]);
68 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
69 }
70
71 g.updateOptions({logscale: true});
72
73 for (var i = 0; i < data.length - 1; i++) {
74 // bottom line
75 var xy1 = g.toDomCoords(data[i][0], data[i][1][0]);
76 var xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][0]);
77 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
78
79 // top line
80 xy1 = g.toDomCoords(data[i][0], data[i][1][2]);
81 xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][2]);
82 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
83
84 // middle line
85 xy1 = g.toDomCoords(data[i][0], data[i][1][1]);
86 xy2 = g.toDomCoords(data[i + 1][0], data[i + 1][1][1]);
87 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
88 }
6278f6fe 89 CanvasAssertions.assertBalancedSaveRestore(htx);
f35016e8
DV
90};
91