X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fmissing_points.js;h=68a5024c90581b22382e3c48c729506c5d99eac2;hb=d66c74ef29a8ad222e7203911af1b46b37f5bde1;hp=9e4cdd59d5a559400f388e1a9ddd5ac0279b5287;hpb=cea0fb7058918a6d81839987e9974d22790bdf34;p=dygraphs.git diff --git a/auto_tests/tests/missing_points.js b/auto_tests/tests/missing_points.js index 9e4cdd5..68a5024 100644 --- a/auto_tests/tests/missing_points.js +++ b/auto_tests/tests/missing_points.js @@ -27,16 +27,16 @@ var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]]; var MissingPointsTestCase = TestCase("missing-points"); -var _origFunc = Dygraph.getContext; +MissingPointsTestCase._origFunc = Dygraph.getContext; MissingPointsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; Dygraph.getContext = function(canvas) { - return new Proxy(_origFunc(canvas)); + return new Proxy(MissingPointsTestCase._origFunc(canvas)); } }; MissingPointsTestCase.prototype.tearDown = function() { - Dygraph.getContext = _origFunc; + Dygraph.getContext = MissingPointsTestCase._origFunc; }; MissingPointsTestCase.prototype.testSeparatedPointsDontDraw = function() { @@ -63,17 +63,6 @@ MissingPointsTestCase.prototype.testSeparatedPointsDontDraw_expanded = function( [4, 14]], { colors: ['blue']}); var htx = g.hidden_ctx_; - /* - var num_lines = 0; - var lines = CanvasAssertions.getLinesDrawn(htx); - for (var idx = 0; idx < lines.length; idx++) { - var line = lines[idx]; - var color = line[1].properties.strokeStyle; - if (color === "#ff0000" || color === "#0000ff") { - console.log(line[0].args, line[1].args, color); - } - } - */ assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); CanvasAssertions.assertLineDrawn(htx, [56, 275], [161, 212], @@ -94,20 +83,87 @@ MissingPointsTestCase.prototype.testSeparatedPointsDontDraw_expanded_connected = { colors: ['blue'], connectSeparatedPoints: true}); var htx = g.hidden_ctx_; var num_lines = 0; - var lines = CanvasAssertions.getLinesDrawn(htx); - for (var idx = 0; idx < lines.length; idx++) { - var line = lines[idx]; - var color = line[1].properties.strokeStyle; - if (color === "#ff0000" || color === "#0000ff") { - console.log(line[0].args, line[1].args, color); - } - } assertEquals(3, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); - CanvasAssertions.assertLineDrawn(htx, [56, 275], [161, 212], - { strokeStyle: '#0000ff', }); - CanvasAssertions.assertLineDrawn(htx, [161, 212], [370, 87], - { strokeStyle: '#0000ff', }); - CanvasAssertions.assertLineDrawn(htx, [370, 87], [475, 25], - { strokeStyle: '#0000ff', }); + CanvasAssertions.assertConsecutiveLinesDrawn(htx, + [[56, 275], [161, 212], [370, 87], [475, 25]], + { strokeStyle: '#0000ff' }); +} + +/** + * At the time of writing this test, the blue series is only points, and not lines. + */ +MissingPointsTestCase.prototype.testConnectSeparatedPoints = function() { + var g = new Dygraph( + document.getElementById("graph"), + [ + [1, null, 3], + [2, 2, null], + [3, null, 7], + [4, 5, null], + [5, null, 5], + [6, 3, null] + ], + { + connectSeparatedPoints: true, + drawPoints: true, + colors: ['red', 'blue'] + } + ); + + var htx = g.hidden_ctx_; + + assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); + CanvasAssertions.assertConsecutiveLinesDrawn(htx, + [[56, 225], [223, 25], [391, 125]], + { strokeStyle: '#0000ff' }); + + assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000')); + CanvasAssertions.assertConsecutiveLinesDrawn(htx, + [[140, 275], [307, 125], [475, 225]], + { strokeStyle: '#ff0000' }); +} + +/** + * At the time of writing this test, the blue series is only points, and not lines. + */ +MissingPointsTestCase.prototype.testConnectSeparatedPointsWithNan = function() { + var g = new Dygraph( + document.getElementById("graph"), + "x,A,B \n" + + "1,,3 \n" + + "2,2, \n" + + "3,,5 \n" + + "4,4, \n" + + "5,,7 \n" + + "6,NaN, \n" + + "8,8, \n" + + "10,10, \n", + { + connectSeparatedPoints: true, + drawPoints: true, + colors: ['red', 'blue'] + } + ); + + var htx = g.hidden_ctx_; + + // Red has two disconnected line segments + assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000')); + CanvasAssertions.assertLineDrawn(htx, [102, 275], [195, 212], { strokeStyle: '#ff0000' }); + CanvasAssertions.assertLineDrawn(htx, [381, 87], [475, 25], { strokeStyle: '#ff0000' }); + + // Blue's lines are consecutive, however. + assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); + CanvasAssertions.assertConsecutiveLinesDrawn(htx, + [[56, 244], [149, 181], [242, 118]], + { strokeStyle: '#0000ff' }); } + +/* These lines contain awesome powa! + var lines = CanvasAssertions.getLinesDrawn(htx, {strokeStyle: "#0000ff"}); + for (var idx = 0; idx < lines.length; idx++) { + var line = lines[idx]; + console.log(line[0].args, line[1].args, line[0].properties.strokeStyle); + } +*/