4fd3369867af36086fad4bd5fe0a330a6f1d0bfe
2 * @fileoverview FILL THIS IN
4 * @author danvk@google.com (Dan Vanderkam)
7 import Dygraph from
'../../src/dygraph';
8 import * as utils from
'../../src/dygraph-utils';
9 import Util from
'./Util';
10 import Proxy from
'./Proxy';
11 import CanvasAssertions from
'./CanvasAssertions';
13 describe("error-bars", function() {
16 useProxyCanvas(utils
, Proxy
);
18 it('testErrorBarsDrawn', function() {
48 var graph
= document
.getElementById("graph");
49 var g
= new Dygraph(graph
, data
, opts
);
51 var htx
= g
.hidden_ctx_
;
53 var attrs
= {}; // TODO(danvk): fill in
55 for (var i
= 0; i
< data
.length
- 1; i
++) {
57 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][0]);
58 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][0]);
59 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
62 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][2]);
63 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][2]);
64 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
67 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][1]);
68 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][1]);
69 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
72 g
.updateOptions({logscale
: true});
74 for (var i
= 0; i
< data
.length
- 1; i
++) {
76 var xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][0]);
77 var xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][0]);
78 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
81 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][2]);
82 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][2]);
83 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
86 xy1
= g
.toDomCoords(data
[i
][0], data
[i
][1][1]);
87 xy2
= g
.toDomCoords(data
[i
+ 1][0], data
[i
+ 1][1][1]);
88 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
90 g
.destroy(); // Restore balanced saves and restores.
91 CanvasAssertions
.assertBalancedSaveRestore(htx
);
94 it('testErrorBarsCorrectColors', function() {
95 // Two constant series with constant error.
97 [0, [100, 50], [200, 50]],
98 [1, [100, 50], [200, 50]]
105 colors
: ['#00ff00', '#0000ff'],
118 valueRange
: [0, 300],
119 labels
: ['X', 'Y1', 'Y2']
121 var graph
= document
.getElementById("graph");
122 var g
= new Dygraph(graph
, data
, opts
);
124 // y-pixels (0=top, 299=bottom)
125 // 0- 48: empty (white)
126 // 49- 98: Y2 error bar
127 // 99: Y2 center line
128 // 100-148: Y2 error bar
129 // 149-198: Y1 error bar
130 // 199: Y1 center line
131 // 200-248: Y1 error bar
132 // 249-299: empty (white)
133 // TODO(danvk): test the edges of these regions.
135 assert
.deepEqual([0, 0, 255, 38], Util
.samplePixel(g
.hidden_
, 200, 75));
136 assert
.deepEqual([0, 0, 255, 38], Util
.samplePixel(g
.hidden_
, 200, 125));
137 assert
.deepEqual([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 175));
138 assert
.deepEqual([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 200, 225));
141 // Regression test for https://github.com/danvk/dygraphs/issues/517
142 // This verifies that the error bars have alpha=fillAlpha, even if the series
143 // color has its own alpha value.
144 it('testErrorBarsForAlphaSeriesCorrectColors', function() {
155 colors
: ['rgba(0, 255, 0, 0.5)'],
168 valueRange
: [0, 300],
171 var graph
= document
.getElementById("graph");
172 var g
= new Dygraph(graph
, data
, opts
);
174 // y-pixels (0=top, 299=bottom)
175 // 0-148: empty (white)
176 // 149-198: Y error bar
177 // 199: Y center line
178 // 200-248: Y error bar
179 // 249-299: empty (white)
181 // 38 = 255 * 0.15 (fillAlpha)
182 // 146 = 255 * (0.15 * 0.5 + 1 * 0.5) (fillAlpha from error bar + alpha from series line)
183 assert
.deepEqual([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 1, 175));
184 assert
.deepEqual([0, 255, 0, 146], Util
.samplePixel(g
.hidden_
, 200, 199));
185 assert
.deepEqual([0, 255, 0, 38], Util
.samplePixel(g
.hidden_
, 1, 225));
189 // Regression test for http://code.google.com/p/dygraphs/issues/detail
?id
=392
190 it('testRollingAveragePreservesNaNs', function() {
191 var graph
= document
.getElementById("graph");
194 [1, [null, null], [3,1]],
195 [2, [2, 1], [null, null]],
196 [3, [null, null], [5,1]],
197 [4, [4, 0.5], [null, null]],
198 [5, [null, null], [7,1]],
199 [6, [NaN
, NaN
], [null, null]],
200 [8, [8, 1], [null, null]],
201 [10, [10, 1], [null, null]]
203 var g
= new Dygraph(graph
, data
,
205 labels
: ['x', 'A', 'B' ],
206 connectSeparatedPoints
: true,
212 var in_series
= g
.dataHandler_
.extractSeries(data
, 1, g
.attributes_
);
214 assert
.equal(null, in_series
[4][1]);
215 assert
.equal(null, in_series
[4][2][0]);
216 assert
.equal(null, in_series
[4][2][1]);
217 assert(isNaN(in_series
[5][1]));
218 assert(isNaN(in_series
[5][2][0]));
219 assert(isNaN(in_series
[5][2][1]));
221 var out_series
= g
.dataHandler_
.rollingAverage(in_series
, 1, g
.attributes_
);
222 assert(isNaN(out_series
[5][1]));
223 assert(isNaN(out_series
[5][2][0]));
224 assert(isNaN(out_series
[5][2][1]));
225 assert
.equal(null, out_series
[4][1]);
226 assert
.equal(null, out_series
[4][2][0]);
227 assert
.equal(null, out_series
[4][2][1]);