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)
7 import Dygraph from
'../../src/dygraph';
8 import * as utils from
'../../src/dygraph-utils';
9 import CanvasAssertions from
'./CanvasAssertions';
10 import Proxy from
'./Proxy';
12 describe("connect-separated-points", function() {
16 var origFunc
= utils
.getContext
;
18 beforeEach(function() {
19 utils
.getContext
= function(canvas
) {
20 return new Proxy(origFunc(canvas
));
24 afterEach(function() {
25 Dygraph
.getContext
= origFunc
;
28 it('testEdgePointsSimple', function() {
32 labels
: ["x", "series1", "series2", "additionalSeries"],
33 connectSeparatedPoints
: true,
50 var graph
= document
.getElementById("graph");
51 var g
= new Dygraph(graph
, data
, opts
);
53 var htx
= g
.hidden_ctx_
;
57 // Test if series1 is drawn correctly.
58 // ------------------------------------
60 // The first point of the first series
63 var xy1
= g
.toDomCoords(x1
, y1
);
65 // The next valid point of this series
68 var xy2
= g
.toDomCoords(x2
, y2
);
70 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
71 // even if the point is outside the visible range and only one series has a valid value for this point.
72 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
74 // Test if series2 is drawn correctly.
75 // ------------------------------------
77 // The last point of the second series.
80 var xy2
= g
.toDomCoords(x2
, y2
);
82 // The previous valid point of this series
85 var xy1
= g
.toDomCoords(x1
, y1
);
87 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
88 // even if the point is outside the visible range and only one series has a valid value for this point.
89 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
92 it('testEdgePointsCustomBars', function() {
96 labels
: ["x", "series1", "series2", "additionalSeries"],
97 connectSeparatedPoints
: true,
98 dateWindow
: [2.5,7.5],
103 [0,[4,5,6], [1,2,3], [null, null, null]],
104 [1,[null,null,null], [2,3,4], [null, null, null]],
105 [2,[null,null,null], [3,4,5], [null, null, null]],
106 [3,[0,1,2], [2,3,4], [null, null, null]],
107 [4,[1,2,3], [2,3,4], [4, 5, 6]],
108 [5,[1,2,3], [3,4,5], [4, 5, 6]],
109 [6,[0,1,2], [4,5,6], [5, 6, 7]],
110 [7,[0,1,2], [4,5,6], [null, null, null]],
111 [8,[2,3,4], [null,null,null], [null, null, null]],
112 [9,[0,1,2], [2,4,9], [null, null, null]]
116 var graph
= document
.getElementById("graph");
117 var g
= new Dygraph(graph
, data
, opts
);
119 var htx
= g
.hidden_ctx_
;
124 // Test if values of the series1 are drawn correctly.
125 // ------------------------------------
127 // The first point of the first series
129 var y1
= data
[0][1][1];
130 var xy1
= g
.toDomCoords(x1
, y1
);
132 // The next valid point of this series
134 var y2
= data
[3][1][1];
135 var xy2
= g
.toDomCoords(x2
, y2
);
137 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
138 // even if the point is outside the visible range and only one series has a valid value for this point.
139 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
141 // Test if the custom bars of the series1 are drawn correctly
142 // --------------------------------------------
144 // The first min-point of this series
147 xy1
= g
.toDomCoords(x1
, y1
);
149 // The next valid min-point of the second series.
152 xy2
= g
.toDomCoords(x2
, y2
);
154 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
155 // even if the point is outside the visible range and only one series has a valid value for this point.
156 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
158 // The first max-point of this series
161 xy1
= g
.toDomCoords(x1
, y1
);
163 // The next valid max-point of the second series.
166 xy2
= g
.toDomCoords(x2
, y2
);
168 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
169 // even if the point is outside the visible range and only one series has a valid value for this point.
170 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
172 // Test if values of the series2 are drawn correctly.
173 // ------------------------------------
175 // The last point of the second series.
177 var y2
= data
[9][2][1];
178 var xy2
= g
.toDomCoords(x2
, y2
);
180 // The previous valid point of this series
182 var y1
= data
[7][2][1];
183 var xy1
= g
.toDomCoords(x1
, y1
);
185 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
186 // even if the point is outside the visible range and only one series has a valid value for this point.
187 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
189 // Test if the custom bars of the series2 are drawn correctly
190 // --------------------------------------------
192 // The last min-point of the second series.
195 xy2
= g
.toDomCoords(x2
, y2
);
197 // The previous valid min-point of this series
200 xy1
= g
.toDomCoords(x1
, y1
);
202 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
203 // even if the point is outside the visible range and only one series has a valid value for this point.
204 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
206 // The last max-point of the second series.
209 xy2
= g
.toDomCoords(x2
, y2
);
211 // The previous valid max-point of this series
214 xy1
= g
.toDomCoords(x1
, y1
);
216 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
217 // even if the point is outside the visible range and only one series has a valid value for this point.
218 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
221 it('testEdgePointsErrorBars', function() {
225 labels
: ["x", "series1", "series2", "seriesTestHelper"],
226 connectSeparatedPoints
: true,
233 [0,[5,1], [2,1], [null,null]],
234 [1,[null,null], [3,1], [null,null]],
235 [2,[null,null], [4,1], [null,null]],
236 [3,[1,1], [3,1], [null,null]],
237 [4,[2,1], [3,1], [5,1]],
238 [5,[2,1], [4,1], [5,1]],
239 [6,[1,1], [5,1], [6,1]],
240 [7,[1,1], [5,1], [null,null]],
241 [8,[3,1], [null,null], [null,null]],
242 [9,[1,1], [4,1], [null,null]]
246 var graph
= document
.getElementById("graph");
247 var g
= new Dygraph(graph
, data
, opts
);
249 var htx
= g
.hidden_ctx_
;
254 // Test if values of the series1 are drawn correctly.
255 // ------------------------------------
257 // The first point of the first series
259 var y1
= data
[0][1][0];
260 var xy1
= g
.toDomCoords(x1
, y1
);
262 // The next valid point of this series
264 var y2
= data
[3][1][0];
265 var xy2
= g
.toDomCoords(x2
, y2
);
267 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
268 // even if the point is outside the visible range and only one series has a valid value for this point.
269 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
271 // Test if the upper error bars of series1 are drawn correctly
272 // --------------------------------------------
274 // The first upper error-point of this series
276 var y1error
= y1
+ (data
[0][1][1]*2);
277 xy1
= g
.toDomCoords(x1
, y1error
);
279 // The next valid upper error-point of the second series.
281 var y2error
= y2
+ (data
[3][1][1]*2);
282 xy2
= g
.toDomCoords(x2
, y2error
);
284 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
285 // even if the point is outside the visible range and only one series has a valid value for this point.
286 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
288 // Test if the lower error bars of series1 are drawn correctly
289 // --------------------------------------------
291 // The first lower error-point of this series
293 y1error
= y1
- (data
[0][1][1]*2);
294 xy1
= g
.toDomCoords(x1
, y1error
);
296 //The next valid lower error-point of the second series.
298 y2error
= y2
- (data
[3][1][1]*2);
299 xy2
= g
.toDomCoords(x2
, y2error
);
301 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
302 // even if the point is outside the visible range and only one series has a valid value for this point.
303 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
306 // Test if values of the series2 are drawn correctly.
307 // ------------------------------------
309 // The last point of this series
312 xy2
= g
.toDomCoords(x2
, y2
);
314 // The previous valid point of the first series
317 xy1
= g
.toDomCoords(x1
, y1
);
319 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
320 // even if the point is outside the visible range and only one series has a valid value for this point.
321 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
323 // Test if the upper error bars of series2 are drawn correctly
324 // --------------------------------------------
326 // The last upper error-point of the second series.
328 var y2error
= y2
+ (data
[9][2][1]*2);
329 xy2
= g
.toDomCoords(x2
, y2error
);
331 // The previous valid upper error-point of this series
333 var y1error
= y1
+ (data
[7][2][1]*2);
334 xy1
= g
.toDomCoords(x1
, y1error
);
336 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
337 // even if the point is outside the visible range and only one series has a valid value for this point.
338 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
340 // Test if the lower error bars of series1 are drawn correctly
341 // --------------------------------------------
343 // The last lower error-point of the second series.
345 y2error
= y2
- (data
[9][2][1]*2);
346 xy2
= g
.toDomCoords(x2
, y2error
);
348 // The previous valid lower error-point of this series
350 y1error
= y1
- (data
[7][2][1]*2);
351 xy1
= g
.toDomCoords(x1
, y1error
);
353 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
354 // even if the point is outside the visible range and only one series has a valid value for this point.
355 CanvasAssertions
.assertLineDrawn(htx
, xy1
, xy2
, attrs
);
358 it('testConnectSeparatedPointsPerSeries', function() {
359 var assertExpectedLinesDrawnPerSeries
= function(htx
, expectedSeries1
, expectedSeries2
, expectedSeries3
) {
360 var expected
= [expectedSeries1
, expectedSeries2
, expectedSeries3
];
362 CanvasAssertions
.numLinesDrawn(htx
, "#ff0000"),
363 CanvasAssertions
.numLinesDrawn(htx
, "#00ff00"),
364 CanvasAssertions
.numLinesDrawn(htx
, "#0000ff")];
365 assert
.deepEqual(expected
, actual
);
368 var g
= new Dygraph(document
.getElementById("graph"),
379 labels
: ["Date","Series1","Series2","Series3"],
380 connectSeparatedPoints
: false,
381 colors
: ["#ff0000", "#00ff00", "#0000ff"]
384 var htx
= g
.hidden_ctx_
;
385 assertExpectedLinesDrawnPerSeries(htx
, 4, 1, 2);
389 connectSeparatedPoints
: true,
391 assertExpectedLinesDrawnPerSeries(htx
, 5, 3, 3);
395 connectSeparatedPoints
: false,
397 Series1
: { connectSeparatedPoints
: true }
400 assertExpectedLinesDrawnPerSeries(htx
, 5, 1, 2);
405 connectSeparatedPoints
: true,
407 Series1
: { connectSeparatedPoints
: false }
410 assertExpectedLinesDrawnPerSeries(htx
, 4, 3, 3);
413 it('testNaNErrorBars', function() {
418 [3,[null,null,null]],
433 connectSeparatedPoints
: true
436 var graph
= document
.getElementById("graph");
437 var g
= new Dygraph(graph
, data
, opts
);
439 var htx
= g
.hidden_ctx_
;
443 // Line should be drawn across the null gap.
444 CanvasAssertions
.assertLineDrawn(htx
,
445 g
.toDomCoords(data
[2][0], data
[2][1][1]),
446 g
.toDomCoords(data
[4][0], data
[4][1][1]),
449 // No line across the NaN gap, and a single line (not two)
450 // across the null gap.
451 assert
.equal(8, CanvasAssertions
.numLinesDrawn(htx
, '#ff0000'));