From 126e230e59594a8fdaaf169f1670097b7c1073ce Mon Sep 17 00:00:00 2001 From: eichsjul Date: Fri, 12 Apr 2013 08:51:37 +0200 Subject: [PATCH] TEST: adapted test for bugfix --- auto_tests/tests/connect_separated_points.js | 138 ++++++++++++++++++++++----- 1 file changed, 112 insertions(+), 26 deletions(-) diff --git a/auto_tests/tests/connect_separated_points.js b/auto_tests/tests/connect_separated_points.js index 65baf91..0f40d90 100644 --- a/auto_tests/tests/connect_separated_points.js +++ b/auto_tests/tests/connect_separated_points.js @@ -3,26 +3,26 @@ * * @author julian.eichstaedt@ch.sauter-bc.com (Fr. Sauter AG) */ -var StepTestCase = TestCase("connect_separated_points"); +var ConnectSeparatedPointsTestCase = TestCase("connect-separated-points"); -StepTestCase.prototype.setUp = function() { +ConnectSeparatedPointsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; }; -StepTestCase.origFunc = Dygraph.getContext; +ConnectSeparatedPointsTestCase.origFunc = Dygraph.getContext; -StepTestCase.prototype.setUp = function() { +ConnectSeparatedPointsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; Dygraph.getContext = function(canvas) { - return new Proxy(StepTestCase.origFunc(canvas)); + return new Proxy(ConnectSeparatedPointsTestCase.origFunc(canvas)); }; }; -StepTestCase.prototype.tearDown = function() { - Dygraph.getContext = StepTestCase.origFunc; +ConnectSeparatedPointsTestCase.prototype.tearDown = function() { + Dygraph.getContext = ConnectSeparatedPointsTestCase.origFunc; }; -StepTestCase.prototype.testEdgePoints = function() { +ConnectSeparatedPointsTestCase.prototype.testEdgePointsSimple = function() { var opts = { width: 480, height: 320, @@ -30,22 +30,30 @@ StepTestCase.prototype.testEdgePoints = function() { // drawYGrid: false, // drawXAxis: false, // drawYAxis: false, - errorBars: false, - labels: ["x", "series1", "series2"], +// errorBars: false, + labels: ["x", "series1", "series2", "series3"], connectSeparatedPoints: true, + drawPoints: true, dateWindow: [1.5,6.5] }; var data = [ - [0,0,2], - [1,null,0.5], - [2,0.5,1], - [3,1,-1], - [4,2,-2], - [5,2.5,-2.5], - [6,3,-3], - [7,4,null], - [8,4,-4], + [-7,-1000,0,null], + [-6,null,2,null], + [-5,null,2,null], + [-4,null,2,null], + [-3,null,2,null], + [-2,null,2,null], + [-1,null,2,null], + [0,null,2,null], + [1,null,4,null], + [2,0.5,0,null], + [3,1,-1,5], + [4,2,-2,6], + [5,2.5,-2.5,7], + [6,3,-3,4], + [7,4,null,5], + [8,4,-10,6], ]; var graph = document.getElementById("graph"); @@ -65,8 +73,8 @@ StepTestCase.prototype.testEdgePoints = function() { // The third (the second valid) point of the first series // This series has no value at the second position. - var x2 = data[2][0]; - var y2 = data[2][1]; + var x2 = data[9][0]; + var y2 = data[9][1]; var xy2 = g.toDomCoords(x2, y2); // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly @@ -79,18 +87,96 @@ StepTestCase.prototype.testEdgePoints = function() { // The sixth point of the second series // Use the sixth and NOT the seventh point despite this series has eight points // since this series has no value at the seventh position. - var x1 = data[6][0]; - var y1 = data[6][2]; + var x1 = data[13][0]; + var y1 = data[13][2]; var xy1 = g.toDomCoords(x1, y1); // The last point of the second series. - var x2 = data[8][0]; - var y2 = data[8][2]; + var x2 = data[15][0]; + var y2 = data[15][2]; var xy2 = g.toDomCoords(x2, y2); // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly // even if the point is outside the visible range and only one series has a valid value for this point. CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs); +}; + +ConnectSeparatedPointsTestCase.prototype.testEdgePointsStacked = function() { + var opts = { + width: 480, + height: 320, +// drawXGrid: false, +// drawYGrid: false, +// drawXAxis: false, +// drawYAxis: false, +// errorBars: false, + labels: ["x", "series1", "series2", "series3"], + connectSeparatedPoints: true, + drawPoints: true, + stackedGraph: true, + dateWindow: [1.5,6.5] + }; + + var data = [ + [-7,null,1,0], + [-6,null,3,null], + [-5,null,3,null], + [-4,null,3,null], + [-3,null,3,null], + [-2,null,3,null], + [-1,null,3,null], + [0,null,3,null], + [1,null,3,null], + [2,null,1,3], + [3,3,1,1], + [4,4,2,2], + [5,3,2,2], + [6,3,1,3], + [7,4,null,2], + [8,5,2,1], + ]; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, opts); + + htx = g.hidden_ctx_; + + var attrs = {}; + + //Test if series1 is drawn correctly. + //------------------------------------ + + // The first point of the first series + var x1 = data[0][0]; + var y1 = data[0][1]; + var xy1 = g.toDomCoords(x1, y1); + + // The third (the second valid) point of the first series + // This series has no value at the second position. + var x2 = data[9][0]; + var y2 = data[9][1]; + var xy2 = g.toDomCoords(x2, y2); + + // Check if both points are connected at the left edge of the canvas and if the option "connectSeparatedPoints" works properly + // even if the point is outside the visible range and only one series has a valid value for this point. + CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs); - + //Test if series2 is drawn correctly. + //------------------------------------ + + // The sixth point of the second series + // Use the sixth and NOT the seventh point despite this series has eight points + // since this series has no value at the seventh position. + var x1 = data[13][0]; + var y1 = data[13][2]; + var xy1 = g.toDomCoords(x1, y1); + + // The last point of the second series. + var x2 = data[15][0]; + var y2 = data[15][2]; + var xy2 = g.toDomCoords(x2, y2); + + // Check if both points are connected at the right edge of the canvas and if the option "connectSeparatedPoints" works properly + // even if the point is outside the visible range and only one series has a valid value for this point. + CanvasAssertions.assertLineDrawn(htx, xy1, xy2, attrs); }; -- 2.7.4