FEATURE: added test for issue #451
authoreichsjul <julian.eichstaedt@ch.sauter-bc.com>
Thu, 11 Apr 2013 09:49:29 +0000 (11:49 +0200)
committereichsjul <julian.eichstaedt@ch.sauter-bc.com>
Thu, 11 Apr 2013 09:49:29 +0000 (11:49 +0200)
auto_tests/misc/local.html
auto_tests/tests/connect_separated_points.js [new file with mode: 0644]

index 3841372..fb99a26 100644 (file)
@@ -23,6 +23,7 @@
   <script type="text/javascript" src="../tests/axis_labels.js"></script>
   <script type="text/javascript" src="../tests/axis_labels-deprecated.js"></script>
   <script type="text/javascript" src="../tests/callback.js"></script>
+  <script type="text/javascript" src="../tests/connect_separated_points.js"></script>
   <script type="text/javascript" src="../tests/css.js"></script>
   <script type="text/javascript" src="../tests/custom_bars.js"></script>
   <script type="text/javascript" src="../tests/date_formats.js"></script>
diff --git a/auto_tests/tests/connect_separated_points.js b/auto_tests/tests/connect_separated_points.js
new file mode 100644 (file)
index 0000000..65baf91
--- /dev/null
@@ -0,0 +1,96 @@
+/**\r
+ * @fileoverview Test cases for the option "connectSeparatedPoints" especially for the scenario where not every series has a value for each timestamp.\r
+ *\r
+ * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG)\r
+ */\r
+var StepTestCase = TestCase("connect_separated_points");\r
+\r
+StepTestCase.prototype.setUp = function() {\r
+  document.body.innerHTML = "<div id='graph'></div>";\r
+};\r
+\r
+StepTestCase.origFunc = Dygraph.getContext;\r
+\r
+StepTestCase.prototype.setUp = function() {\r
+  document.body.innerHTML = "<div id='graph'></div>";\r
+  Dygraph.getContext = function(canvas) {\r
+    return new Proxy(StepTestCase.origFunc(canvas));\r
+  };\r
+};\r
+\r
+StepTestCase.prototype.tearDown = function() {\r
+  Dygraph.getContext = StepTestCase.origFunc;\r
+};\r
+\r
+StepTestCase.prototype.testEdgePoints = function() {\r
+  var opts = {\r
+    width: 480,\r
+    height: 320,\r
+//    drawXGrid: false,\r
+//    drawYGrid: false,\r
+//    drawXAxis: false,\r
+//    drawYAxis: false,\r
+    errorBars: false,\r
+    labels: ["x", "series1", "series2"],\r
+    connectSeparatedPoints: true,\r
+    dateWindow: [1.5,6.5]\r
+  };\r
+\r
+  var data = [\r
+              [0,0,2],\r
+              [1,null,0.5],\r
+              [2,0.5,1],\r
+              [3,1,-1],\r
+              [4,2,-2],\r
+              [5,2.5,-2.5],\r
+              [6,3,-3],\r
+              [7,4,null],\r
+              [8,4,-4],\r
+             ];\r
+\r
+  var graph = document.getElementById("graph");\r
+  var g = new Dygraph(graph, data, opts);\r
+  \r
+  htx = g.hidden_ctx_;\r
+\r
+  var attrs = {};  \r
+\r
+  //Test if series1 is drawn correctly.\r
+  //------------------------------------\r
+  \r
+  // The first point of the first series\r
+  var x1 = data[0][0];\r
+  var y1 = data[0][1];\r
+  var xy1 = g.toDomCoords(x1, y1);\r
+  \r
+  // The third (the second valid) point of the first series\r
+  // This series has no value at the second position.\r
+  var x2 = data[2][0];\r
+  var y2 = data[2][1];\r
+  var xy2 = g.toDomCoords(x2, y2);\r
+  \r
+  // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly\r
+  // even if the point is outside the visible range and only one series has a valid value for this point.\r
+  CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r
+\r
+  //Test if series2 is drawn correctly.\r
+  //------------------------------------\r
+  \r
+  // The sixth point of the second series\r
+  // Use the sixth and NOT the seventh point despite this series has eight points \r
+  // since this series has no value at the seventh position.\r
+  var x1 = data[6][0];\r
+  var y1 = data[6][2];\r
+  var xy1 = g.toDomCoords(x1, y1);\r
+  \r
+  // The last point of the second series.\r
+  var x2 = data[8][0];\r
+  var y2 = data[8][2];\r
+  var xy2 = g.toDomCoords(x2, y2);\r
+  \r
+  // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly\r
+  // even if the point is outside the visible range and only one series has a valid value for this point.\r
+  CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs);\r
+\r
+    \r
+};\r