2 * @fileoverview Test cases for the option "connectSeparatedPoints" especially for the scenario where not every series has a value for each timestamp.
4 * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)
6 var ConnectSeparatedPointsTestCase
= TestCase("connect-separated-points");
8 ConnectSeparatedPointsTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 ConnectSeparatedPointsTestCase
.origFunc
= Dygraph
.getContext
;
14 ConnectSeparatedPointsTestCase
.prototype.setUp
= function() {
15 document
.body
.innerHTML
= "<div id='graph'></div>";
16 Dygraph
.getContext
= function(canvas
) {
17 return new Proxy(ConnectSeparatedPointsTestCase
.origFunc(canvas
));
21 ConnectSeparatedPointsTestCase
.prototype.tearDown
= function() {
22 Dygraph
.getContext
= ConnectSeparatedPointsTestCase
.origFunc
;
25 ConnectSeparatedPointsTestCase
.prototype.testEdgePointsSimple
= function() {
29 labels
: ["x", "series1", "series2", "additionalSeries"],
30 connectSeparatedPoints
: true,
47 var graph
= document
.getElementById("graph");
48 var g
= new Dygraph(graph
, data
, opts
);
54 // Test if series1 is drawn correctly.
55 // ------------------------------------
57 // The first point of the first series
60 var xy1
= g
.toDomCoords(x1
, y1
);
62 // The next valid point of this series
65 var xy2
= g
.toDomCoords(x2
, y2
);
67 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
68 // even if the point is outside the visible range and only one series has a valid value for this point.
69 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
71 // Test if series2 is drawn correctly.
72 // ------------------------------------
74 // The last point of the second series.
77 var xy2
= g
.toDomCoords(x2
, y2
);
79 // The previous valid point of this series
82 var xy1
= g
.toDomCoords(x1
, y1
);
84 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
85 // even if the point is outside the visible range and only one series has a valid value for this point.
86 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
89 ConnectSeparatedPointsTestCase
.prototype.testEdgePointsCustomBars
= function() {
93 labels
: ["x", "series1", "series2", "additionalSeries"],
94 connectSeparatedPoints
: true,
95 dateWindow
: [2.5,7.5],
100 [0,[4,5,6], [1,2,3], [null, null, null]],
101 [1,[null,null,null], [2,3,4], [null, null, null]],
102 [2,[null,null,null], [3,4,5], [null, null, null]],
103 [3,[0,1,2], [2,3,4], [null, null, null]],
104 [4,[1,2,3], [2,3,4], [4, 5, 6]],
105 [5,[1,2,3], [3,4,5], [4, 5, 6]],
106 [6,[0,1,2], [4,5,6], [5, 6, 7]],
107 [7,[0,1,2], [4,5,6], [null, null, null]],
108 [8,[2,3,4], [null,null,null], [null, null, null]],
109 [9,[0,1,2], [2,4,9], [null, null, null]]
113 var graph
= document
.getElementById("graph");
114 var g
= new Dygraph(graph
, data
, opts
);
121 // Test if values of the series1 are drawn correctly.
122 // ------------------------------------
124 // The first point of the first series
126 var y1
= data
[0][1][1];
127 var xy1
= g
.toDomCoords(x1
, y1
);
129 // The next valid point of this series
131 var y2
= data
[3][1][1];
132 var xy2
= g
.toDomCoords(x2
, y2
);
134 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
135 // even if the point is outside the visible range and only one series has a valid value for this point.
136 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
138 // Test if the custom bars of the series1 are drawn correctly
139 // --------------------------------------------
141 // The first min-point of this series
144 xy1
= g
.toDomCoords(x1
, y1
);
146 // The next valid min-point of the second series.
149 xy2
= g
.toDomCoords(x2
, y2
);
151 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
152 // even if the point is outside the visible range and only one series has a valid value for this point.
153 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
155 // The first max-point of this series
158 xy1
= g
.toDomCoords(x1
, y1
);
160 // The next valid max-point of the second series.
163 xy2
= g
.toDomCoords(x2
, y2
);
165 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
166 // even if the point is outside the visible range and only one series has a valid value for this point.
167 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
169 // Test if values of the series2 are drawn correctly.
170 // ------------------------------------
172 // The last point of the second series.
174 var y2
= data
[9][2][1];
175 var xy2
= g
.toDomCoords(x2
, y2
);
177 // The previous valid point of this series
179 var y1
= data
[7][2][1];
180 var xy1
= g
.toDomCoords(x1
, y1
);
182 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
183 // even if the point is outside the visible range and only one series has a valid value for this point.
184 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
186 // Test if the custom bars of the series2 are drawn correctly
187 // --------------------------------------------
189 // The last min-point of the second series.
192 xy2
= g
.toDomCoords(x2
, y2
);
194 // The previous valid min-point of this series
197 xy1
= g
.toDomCoords(x1
, y1
);
199 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
200 // even if the point is outside the visible range and only one series has a valid value for this point.
201 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
203 // The last max-point of the second series.
206 xy2
= g
.toDomCoords(x2
, y2
);
208 // The previous valid max-point of this series
211 xy1
= g
.toDomCoords(x1
, y1
);
213 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
214 // even if the point is outside the visible range and only one series has a valid value for this point.
215 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
218 ConnectSeparatedPointsTestCase
.prototype.testEdgePointsErrorBars
= function() {
222 labels
: ["x", "series1", "series2", "seriesTestHelper"],
223 connectSeparatedPoints
: true,
230 [0,[5,1], [2,1], [null,null]],
231 [1,[null,null], [3,1], [null,null]],
232 [2,[null,null], [4,1], [null,null]],
233 [3,[1,1], [3,1], [null,null]],
234 [4,[2,1], [3,1], [5,1]],
235 [5,[2,1], [4,1], [5,1]],
236 [6,[1,1], [5,1], [6,1]],
237 [7,[1,1], [5,1], [null,null]],
238 [8,[3,1], [null,null], [null,null]],
239 [9,[1,1], [4,1], [null,null]]
243 var graph
= document
.getElementById("graph");
244 var g
= new Dygraph(graph
, data
, opts
);
251 // Test if values of the series1 are drawn correctly.
252 // ------------------------------------
254 // The first point of the first series
256 var y1
= data
[0][1][0];
257 var xy1
= g
.toDomCoords(x1
, y1
);
259 // The next valid point of this series
261 var y2
= data
[3][1][0];
262 var xy2
= g
.toDomCoords(x2
, y2
);
264 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
265 // even if the point is outside the visible range and only one series has a valid value for this point.
266 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
268 // Test if the upper error bars of series1 are drawn correctly
269 // --------------------------------------------
271 // The first upper error-point of this series
273 var y1error
= y1
+ (data
[0][1][1]*2);
274 xy1
= g
.toDomCoords(x1
, y1error
);
276 // The next valid upper error-point of the second series.
278 var y2error
= y2
+ (data
[3][1][1]*2);
279 xy2
= g
.toDomCoords(x2
, y2error
);
281 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
282 // even if the point is outside the visible range and only one series has a valid value for this point.
283 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
285 // Test if the lower error bars of series1 are drawn correctly
286 // --------------------------------------------
288 // The first lower error-point of this series
290 y1error
= y1
- (data
[0][1][1]*2);
291 xy1
= g
.toDomCoords(x1
, y1error
);
293 //The next valid lower error-point of the second series.
295 y2error
= y2
- (data
[3][1][1]*2);
296 xy2
= g
.toDomCoords(x2
, y2error
);
298 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
299 // even if the point is outside the visible range and only one series has a valid value for this point.
300 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
303 // Test if values of the series2 are drawn correctly.
304 // ------------------------------------
306 // The last point of this series
309 xy2
= g
.toDomCoords(x2
, y2
);
311 // The previous valid point of the first series
314 xy1
= g
.toDomCoords(x1
, y1
);
316 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
317 // even if the point is outside the visible range and only one series has a valid value for this point.
318 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
320 // Test if the upper error bars of series2 are drawn correctly
321 // --------------------------------------------
323 // The last upper error-point of the second series.
325 var y2error
= y2
+ (data
[9][2][1]*2);
326 xy2
= g
.toDomCoords(x2
, y2error
);
328 // The previous valid upper error-point of this series
330 var y1error
= y1
+ (data
[7][2][1]*2);
331 xy1
= g
.toDomCoords(x1
, y1error
);
333 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
334 // even if the point is outside the visible range and only one series has a valid value for this point.
335 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
337 // Test if the lower error bars of series1 are drawn correctly
338 // --------------------------------------------
340 // The last lower error-point of the second series.
342 y2error
= y2
- (data
[9][2][1]*2);
343 xy2
= g
.toDomCoords(x2
, y2error
);
345 // The previous valid lower error-point of this series
347 y1error
= y1
- (data
[7][2][1]*2);
348 xy1
= g
.toDomCoords(x1
, y1error
);
350 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
351 // even if the point is outside the visible range and only one series has a valid value for this point.
352 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
355 ConnectSeparatedPointsTestCase
.prototype.testConnectSeparatedPointsPerSeries
= function() {
356 var assertExpectedLinesDrawnPerSeries
= function(htx
, expectedSeries1
, expectedSeries2
, expectedSeries3
) {
357 var expected
= [expectedSeries1
, expectedSeries2
, expectedSeries3
];
359 CanvasAssertions
.numLinesDrawn(htx
, "#ff0000"),
360 CanvasAssertions
.numLinesDrawn(htx
, "#00ff00"),
361 CanvasAssertions
.numLinesDrawn(htx
, "#0000ff")];
362 assertEquals(expected
, actual
);
365 var g
= new Dygraph(document
.getElementById("graph"),
376 labels
: ["Date","Series1","Series2","Series3"],
377 connectSeparatedPoints
: false,
378 colors
: ["#ff0000", "#00ff00", "#0000ff"]
382 assertExpectedLinesDrawnPerSeries(htx
, 4, 1, 2);
386 connectSeparatedPoints
: true,
388 assertExpectedLinesDrawnPerSeries(htx
, 5, 3, 3);
392 connectSeparatedPoints
: false,
394 Series1
: { connectSeparatedPoints
: true }
397 assertExpectedLinesDrawnPerSeries(htx
, 5, 1, 2);
402 connectSeparatedPoints
: true,
404 Series1
: { connectSeparatedPoints
: false }
407 assertExpectedLinesDrawnPerSeries(htx
, 4, 3, 3);