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() {
53 var graph
= document
.getElementById("graph");
54 var g
= new Dygraph(graph
, data
, opts
);
58 var attrs
= {}; // TODO(danvk): fill in
60 for (var i
= 0; i
< data
.length
- 1; i
++) {
62 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][0]);
63 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][0]);
64 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
67 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][2]);
68 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][2]);
69 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
72 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][1]);
73 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][1]);
74 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
77 g
.updateOptions({logscale
: true});
79 for (var i
= 0; i
< data
.length
- 1; i
++) {
81 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][0]);
82 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][0]);
83 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
86 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][2]);
87 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][2]);
88 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
91 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][1]);
92 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][1]);
93 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
95 g
.destroy(); // Restore balanced saves and restores.
96 CanvasAssertions
.assertBalancedSaveRestore(htx
);
99 errorBarsTestCase
.prototype.testErrorBarsCorrectColors
= function() {
100 // Two constant series with constant error.
102 [0, [100, 50], [200, 50]],
103 [1, [100, 50], [200, 50]]
110 colors
: ['#00ff00', '#0000ff'],
123 valueRange
: [0, 300],
124 labels
: ['X', 'Y1', 'Y2']
126 var graph
= document
.getElementById("graph");
127 var g
= new Dygraph(graph
, data
, opts
);
129 // y-pixels (0=top, 299=bottom)
130 // 0- 48: empty (white)
131 // 49- 98: Y2 error bar
132 // 99: Y2 center line
133 // 100-148: Y2 error bar
134 // 149-198: Y1 error bar
135 // 199: Y1 center line
136 // 200-248: Y1 error bar
137 // 249-299: empty (white)
138 // TODO(danvk): test the edges of these regions.
140 assertEquals([0, 0, 255, 38], Util
.samplePixel(g
.hidden_
, 200, 75));
141 assertEquals([0, 0, 255, 38], Util
.samplePixel(g
.hidden_
, 200, 125));
142 assertEquals([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 175));
143 assertEquals([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 225));
147 // Regression test for http://code.google.com/p/dygraphs/issues/detail
?id
=392
148 errorBarsTestCase
.prototype.testRollingAveragePreservesNaNs
= function() {
149 var graph
= document
.getElementById("graph");
152 [1, [null, null], [3,1]],
153 [2, [2, 1], [null, null]],
154 [3, [null, null], [5,1]],
155 [4, [4, 0.5], [null, null]],
156 [5, [null, null], [7,1]],
157 [6, [NaN
, NaN
], [null, null]],
158 [8, [8, 1], [null, null]],
159 [10, [10, 1], [null, null]]
161 var g
= new Dygraph(graph
, data
,
163 labels
: ['x', 'A', 'B' ],
164 connectSeparatedPoints
: true,
170 var in_series
= g
.dataHandler_
.extractSeries(data
, 1, g
.attributes_
);
172 assertEquals(null, in_series
[4][1]);
173 assertEquals(null, in_series
[4][2][0]);
174 assertEquals(null, in_series
[4][2][1]);
175 assertNaN(in_series
[5][1]);
176 assertNaN(in_series
[5][2][0]);
177 assertNaN(in_series
[5][2][1]);
179 var out_series
= g
.dataHandler_
.rollingAverage(in_series
, 1, g
.attributes_
);
180 assertNaN(out_series
[5][1]);
181 assertNaN(out_series
[5][2][0]);
182 assertNaN(out_series
[5][2][1]);
183 assertEquals(null, out_series
[4][1]);
184 assertEquals(null, out_series
[4][2][0]);
185 assertEquals(null, out_series
[4][2][1]);