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 |
6 | var StepTestCase = TestCase("connect_separated_points");\r |
7 | \r |
8 | StepTestCase.prototype.setUp = function() {\r |
9 | document.body.innerHTML = "<div id='graph'></div>";\r |
10 | };\r |
11 | \r |
12 | StepTestCase.origFunc = Dygraph.getContext;\r |
13 | \r |
14 | StepTestCase.prototype.setUp = function() {\r |
15 | document.body.innerHTML = "<div id='graph'></div>";\r |
16 | Dygraph.getContext = function(canvas) {\r |
17 | return new Proxy(StepTestCase.origFunc(canvas));\r |
18 | };\r |
19 | };\r |
20 | \r |
21 | StepTestCase.prototype.tearDown = function() {\r |
22 | Dygraph.getContext = StepTestCase.origFunc;\r |
23 | };\r |
24 | \r |
25 | StepTestCase.prototype.testEdgePoints = function() {\r |
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 |
33 | errorBars: false,\r |
34 | labels: ["x", "series1", "series2"],\r |
35 | connectSeparatedPoints: true,\r |
36 | dateWindow: [1.5,6.5]\r |
37 | };\r |
38 | \r |
39 | var data = [\r |
40 | [0,0,2],\r |
41 | [1,null,0.5],\r |
42 | [2,0.5,1],\r |
43 | [3,1,-1],\r |
44 | [4,2,-2],\r |
45 | [5,2.5,-2.5],\r |
46 | [6,3,-3],\r |
47 | [7,4,null],\r |
48 | [8,4,-4],\r |
49 | ];\r |
50 | \r |
51 | var graph = document.getElementById("graph");\r |
52 | var g = new Dygraph(graph, data, opts);\r |
53 | \r |
54 | htx = g.hidden_ctx_;\r |
55 | \r |
56 | var attrs = {}; \r |
57 | \r |
58 | //Test if series1 is drawn correctly.\r |
59 | //------------------------------------\r |
60 | \r |
61 | // The first point of the first series\r |
62 | var x1 = data[0][0];\r |
63 | var y1 = data[0][1];\r |
64 | var xy1 = g.toDomCoords(x1, y1);\r |
65 | \r |
66 | // The third (the second valid) point of the first series\r |
67 | // This series has no value at the second position.\r |
68 | var x2 = data[2][0];\r |
69 | var y2 = data[2][1];\r |
70 | var xy2 = g.toDomCoords(x2, y2);\r |
71 | \r |
72 | // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly\r |
73 | // even if the point is outside the visible range and only one series has a valid value for this point.\r |
74 | CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r |
75 | \r |
76 | //Test if series2 is drawn correctly.\r |
77 | //------------------------------------\r |
78 | \r |
79 | // The sixth point of the second series\r |
80 | // Use the sixth and NOT the seventh point despite this series has eight points \r |
81 | // since this series has no value at the seventh position.\r |
82 | var x1 = data[6][0];\r |
83 | var y1 = data[6][2];\r |
84 | var xy1 = g.toDomCoords(x1, y1);\r |
85 | \r |
86 | // The last point of the second series.\r |
87 | var x2 = data[8][0];\r |
88 | var y2 = data[8][2];\r |
89 | var xy2 = g.toDomCoords(x2, y2);\r |
90 | \r |
91 | // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly\r |
92 | // even if the point is outside the visible range and only one series has a valid value for this point.\r |
93 | CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r |
94 | \r |
95 | \r |
96 | };\r |