BUGFIX: bugfix for issue #451 is now also working for bars
[dygraphs.git] / auto_tests / tests / connect_separated_points.js
CommitLineData
d413f791 1/**\r
2 * @fileoverview Test cases for the option "connectSeparatedPoints" especially for the scenario where not every series has a value for each timestamp.\r
3 *\r
4 * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)\r
5 */\r
126e230e 6var ConnectSeparatedPointsTestCase = TestCase("connect-separated-points");\r
d413f791 7\r
126e230e 8ConnectSeparatedPointsTestCase.prototype.setUp = function() {\r
d413f791 9 document.body.innerHTML = "<div id='graph'></div>";\r
10};\r
11\r
126e230e 12ConnectSeparatedPointsTestCase.origFunc = Dygraph.getContext;\r
d413f791 13\r
126e230e 14ConnectSeparatedPointsTestCase.prototype.setUp = function() {\r
d413f791 15 document.body.innerHTML = "<div id='graph'></div>";\r
16 Dygraph.getContext = function(canvas) {\r
126e230e 17 return new Proxy(ConnectSeparatedPointsTestCase.origFunc(canvas));\r
d413f791 18 };\r
19};\r
20\r
126e230e 21ConnectSeparatedPointsTestCase.prototype.tearDown = function() {\r
22 Dygraph.getContext = ConnectSeparatedPointsTestCase.origFunc;\r
d413f791 23};\r
24\r
126e230e 25ConnectSeparatedPointsTestCase.prototype.testEdgePointsSimple = function() {\r
d413f791 26 var opts = {\r
27 width: 480,\r
28 height: 320,\r
29// drawXGrid: false,\r
30// drawYGrid: false,\r
31// drawXAxis: false,\r
32// drawYAxis: false,\r
126e230e 33// errorBars: false,\r
34 labels: ["x", "series1", "series2", "series3"],\r
d413f791 35 connectSeparatedPoints: true,\r
126e230e 36 drawPoints: true,\r
d413f791 37 dateWindow: [1.5,6.5]\r
38 };\r
39\r
40 var data = [\r
126e230e 41 [-7,-1000,0,null],\r
42 [-6,null,2,null],\r
43 [-5,null,2,null],\r
44 [-4,null,2,null],\r
45 [-3,null,2,null],\r
46 [-2,null,2,null],\r
47 [-1,null,2,null],\r
48 [0,null,2,null],\r
49 [1,null,4,null],\r
50 [2,0.5,0,null],\r
51 [3,1,-1,5],\r
52 [4,2,-2,6],\r
53 [5,2.5,-2.5,7],\r
54 [6,3,-3,4],\r
55 [7,4,null,5],\r
56 [8,4,-10,6],\r
d413f791 57 ];\r
58\r
59 var graph = document.getElementById("graph");\r
60 var g = new Dygraph(graph, data, opts);\r
61 \r
62 htx = g.hidden_ctx_;\r
63\r
64 var attrs = {}; \r
65\r
66 //Test if series1 is drawn correctly.\r
67 //------------------------------------\r
68 \r
69 // The first point of the first series\r
70 var x1 = data[0][0];\r
71 var y1 = data[0][1];\r
72 var xy1 = g.toDomCoords(x1, y1);\r
73 \r
74 // The third (the second valid) point of the first series\r
75 // This series has no value at the second position.\r
126e230e 76 var x2 = data[9][0];\r
77 var y2 = data[9][1];\r
d413f791 78 var xy2 = g.toDomCoords(x2, y2);\r
79 \r
80 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly\r
81 // even if the point is outside the visible range and only one series has a valid value for this point.\r
82 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r
83\r
84 //Test if series2 is drawn correctly.\r
85 //------------------------------------\r
86 \r
87 // The sixth point of the second series\r
88 // Use the sixth and NOT the seventh point despite this series has eight points \r
89 // since this series has no value at the seventh position.\r
126e230e 90 var x1 = data[13][0];\r
91 var y1 = data[13][2];\r
d413f791 92 var xy1 = g.toDomCoords(x1, y1);\r
93 \r
94 // The last point of the second series.\r
126e230e 95 var x2 = data[15][0];\r
96 var y2 = data[15][2];\r
d413f791 97 var xy2 = g.toDomCoords(x2, y2);\r
98 \r
99 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly\r
100 // even if the point is outside the visible range and only one series has a valid value for this point.\r
101 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r
126e230e 102};\r
103\r
104ConnectSeparatedPointsTestCase.prototype.testEdgePointsStacked = function() {\r
105 var opts = {\r
106 width: 480,\r
107 height: 320,\r
108// drawXGrid: false,\r
109// drawYGrid: false,\r
110// drawXAxis: false,\r
111// drawYAxis: false,\r
112// errorBars: false,\r
113 labels: ["x", "series1", "series2", "series3"],\r
114 connectSeparatedPoints: true,\r
115 drawPoints: true,\r
116 stackedGraph: true,\r
117 dateWindow: [1.5,6.5]\r
118 };\r
119\r
120 var data = [\r
121 [-7,null,1,0],\r
122 [-6,null,3,null],\r
123 [-5,null,3,null],\r
124 [-4,null,3,null],\r
125 [-3,null,3,null],\r
126 [-2,null,3,null],\r
127 [-1,null,3,null],\r
128 [0,null,3,null],\r
129 [1,null,3,null],\r
130 [2,null,1,3],\r
131 [3,3,1,1],\r
132 [4,4,2,2],\r
133 [5,3,2,2],\r
134 [6,3,1,3],\r
135 [7,4,null,2],\r
136 [8,5,2,1],\r
137 ];\r
138\r
139 var graph = document.getElementById("graph");\r
140 var g = new Dygraph(graph, data, opts);\r
141 \r
142 htx = g.hidden_ctx_;\r
143\r
144 var attrs = {}; \r
145\r
146 //Test if series1 is drawn correctly.\r
147 //------------------------------------\r
148 \r
149 // The first point of the first series\r
150 var x1 = data[0][0];\r
151 var y1 = data[0][1];\r
152 var xy1 = g.toDomCoords(x1, y1);\r
153 \r
154 // The third (the second valid) point of the first series\r
155 // This series has no value at the second position.\r
156 var x2 = data[9][0];\r
157 var y2 = data[9][1];\r
158 var xy2 = g.toDomCoords(x2, y2);\r
159 \r
160 // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly\r
161 // even if the point is outside the visible range and only one series has a valid value for this point.\r
162 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r
d413f791 163\r
126e230e 164 //Test if series2 is drawn correctly.\r
165 //------------------------------------\r
166 \r
167 // The sixth point of the second series\r
168 // Use the sixth and NOT the seventh point despite this series has eight points \r
169 // since this series has no value at the seventh position.\r
170 var x1 = data[13][0];\r
171 var y1 = data[13][2];\r
172 var xy1 = g.toDomCoords(x1, y1);\r
173 \r
174 // The last point of the second series.\r
175 var x2 = data[15][0];\r
176 var y2 = data[15][2];\r
177 var xy2 = g.toDomCoords(x2, y2);\r
178 \r
179 // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly\r
180 // even if the point is outside the visible range and only one series has a valid value for this point.\r
181 CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r
d413f791 182};\r