2 * @fileoverview FILL THIS IN
4 * @author danvk@google.com (Dan Vanderkam)
6 var errorBarsTestCase
= TestCase("error-bars");
8 errorBarsTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 errorBarsTestCase
._origFunc
= Dygraph
.getContext
;
13 errorBarsTestCase
.prototype.setUp
= function() {
14 document
.body
.innerHTML
= "<div id='graph'></div>";
15 Dygraph
.getContext
= function(canvas
) {
16 return new Proxy(errorBarsTestCase
._origFunc(canvas
));
20 errorBarsTestCase
.prototype.tearDown
= function() {
21 Dygraph
.getContext
= errorBarsTestCase
._origFunc
;
24 errorBarsTestCase
.prototype.testErrorBarsDrawn
= function() {
47 var graph
= document
.getElementById("graph");
48 var g
= new Dygraph(graph
, data
, opts
);
52 var attrs
= {}; // TODO(danvk): fill in
54 for (var i
= 0; i
< data
.length
- 1; i
++) {
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
);
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
);
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
);
71 g
.updateOptions({logscale
: true});
73 for (var i
= 0; i
< data
.length
- 1; i
++) {
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
);
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
);
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
);
89 g
.destroy(); // Restore balanced saves and restores.
90 CanvasAssertions
.assertBalancedSaveRestore(htx
);
93 errorBarsTestCase
.prototype.testErrorBarsCorrectColors
= function() {
94 // Two constant series with constant error.
96 [0, [100, 50], [200, 50]],
97 [1, [100, 50], [200, 50]]
104 colors
: ['#00ff00', '#0000ff'],
111 valueRange
: [0, 300],
112 labels
: ['X', 'Y1', 'Y2']
114 var graph
= document
.getElementById("graph");
115 var g
= new Dygraph(graph
, data
, opts
);
117 // y-pixels (0=top, 299=bottom)
118 // 0- 48: empty (white)
119 // 49- 98: Y2 error bar
120 // 99: Y2 center line
121 // 100-148: Y2 error bar
122 // 149-198: Y1 error bar
123 // 199: Y1 center line
124 // 200-248: Y1 error bar
125 // 249-299: empty (white)
126 // TODO(danvk): test the edges of these regions.
128 assertEquals([0, 0, 255, 38], Util
.samplePixel(g
.hidden_
, 200, 75));
129 assertEquals([0, 0, 255, 38], Util
.samplePixel(g
.hidden_
, 200, 125));
130 assertEquals([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 175));
131 assertEquals([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 225));
135 // Regression test for http://code.google.com/p/dygraphs/issues/detail
?id
=392
136 errorBarsTestCase
.prototype.testRollingAveragePreservesNaNs
= function() {
137 var graph
= document
.getElementById("graph");
138 var g
= new Dygraph(graph
,
140 [1, [null, null], [3,1]],
141 [2, [2, 1], [null, null]],
142 [3, [null, null], [5,1]],
143 [4, [4, 0.5], [null, null]],
144 [5, [null, null], [7,1]],
145 [6, [NaN
, NaN
], [null, null]],
146 [8, [8, 1], [null, null]],
147 [10, [10, 1], [null, null]]
150 labels
: ['x', 'A', 'B' ],
151 connectSeparatedPoints
: true,
167 assertEquals(null, in_series
[4][1][0]);
168 assertEquals(null, in_series
[4][1][1]);
169 assertNaN(in_series
[5][1][0]);
170 assertNaN(in_series
[5][1][1]);
172 var out_series
= g
.rollingAverage(in_series
, 1);
173 assertNaN(out_series
[5][1][0]);
174 assertNaN(out_series
[5][1][1]);
175 assertNaN(out_series
[5][1][2]);
176 assertEquals(null, out_series
[4][1][0]);
177 assertEquals(null, out_series
[4][1][1]);
178 assertEquals(null, out_series
[4][1][1]);