FEATURE: added test for issue #451
[dygraphs.git] / auto_tests / tests / connect_separated_points.js
1 /**
2 * @fileoverview Test cases for the option "connectSeparatedPoints" especially for the scenario where not every series has a value for each timestamp.
3 *
4 * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)
5 */
6 var StepTestCase = TestCase("connect_separated_points");
7
8 StepTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10 };
11
12 StepTestCase.origFunc = Dygraph.getContext;
13
14 StepTestCase.prototype.setUp = function() {
15 document.body.innerHTML = "<div id='graph'></div>";
16 Dygraph.getContext = function(canvas) {
17 return new Proxy(StepTestCase.origFunc(canvas));
18 };
19 };
20
21 StepTestCase.prototype.tearDown = function() {
22 Dygraph.getContext = StepTestCase.origFunc;
23 };
24
25 StepTestCase.prototype.testEdgePoints = function() {
26 var opts = {
27 width: 480,
28 height: 320,
29 // drawXGrid: false,
30 // drawYGrid: false,
31 // drawXAxis: false,
32 // drawYAxis: false,
33 errorBars: false,
34 labels: ["x", "series1", "series2"],
35 connectSeparatedPoints: true,
36 dateWindow: [1.5,6.5]
37 };
38
39 var data = [
40 [0,0,2],
41 [1,null,0.5],
42 [2,0.5,1],
43 [3,1,-1],
44 [4,2,-2],
45 [5,2.5,-2.5],
46 [6,3,-3],
47 [7,4,null],
48 [8,4,-4],
49 ];
50
51 var graph = document.getElementById("graph");
52 var g = new Dygraph(graph, data, opts);
53
54 htx = g.hidden_ctx_;
55
56 var attrs = {};
57
58 //Test if series1 is drawn correctly.
59 //------------------------------------
60
61 // The first point of the first series
62 var x1 = data[0][0];
63 var y1 = data[0][1];
64 var xy1 = g.toDomCoords(x1, y1);
65
66 // The third (the second valid) point of the first series
67 // This series has no value at the second position.
68 var x2 = data[2][0];
69 var y2 = data[2][1];
70 var xy2 = g.toDomCoords(x2, y2);
71
72 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly
73 // even if the point is outside the visible range and only one series has a valid value for this point.
74 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
75
76 //Test if series2 is drawn correctly.
77 //------------------------------------
78
79 // The sixth point of the second series
80 // Use the sixth and NOT the seventh point despite this series has eight points
81 // since this series has no value at the seventh position.
82 var x1 = data[6][0];
83 var y1 = data[6][2];
84 var xy1 = g.toDomCoords(x1, y1);
85
86 // The last point of the second series.
87 var x2 = data[8][0];
88 var y2 = data[8][2];
89 var xy2 = g.toDomCoords(x2, y2);
90
91 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly
92 // even if the point is outside the visible range and only one series has a valid value for this point.
93 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);
94
95
96 };