X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Frange_tests.js;h=83a2505f870656e313f22433a1393c10fbb39eca;hb=4c10c8d21b6858ea9029bdb789f487d9103d72f9;hp=561ceeb5a5c0c6f64b6d6ec2e7ff507db6483933;hpb=02eb7ae72eb3d5e83c2bf546d1fc2a6a60b91008;p=dygraphs.git diff --git a/auto_tests/tests/range_tests.js b/auto_tests/tests/range_tests.js index 561ceeb..83a2505 100644 --- a/auto_tests/tests/range_tests.js +++ b/auto_tests/tests/range_tests.js @@ -35,6 +35,9 @@ var ZERO_TO_FIFTY_STEPS = function() { } return a; } (); +var FIVE_TO_ONE_THOUSAND = [ + [ 1, 10 ], [ 2, 20 ], [ 3, 30 ], [ 4, 40 ] , [ 5, 50 ], + [ 6, 60 ], [ 7, 70 ], [ 8, 80 ], [ 9, 90 ] , [ 10, 1000 ]]; var RangeTestCase = TestCase("range-tests"); @@ -67,11 +70,39 @@ RangeTestCase.prototype.testRangeSetOperations = function() { assertEquals([12, 18], g.xAxisRange()); assertEquals([10, 40], g.yAxisRange(0)); + g.updateOptions({ valueRange: [10, NaN] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 44.2], g.yAxisRange(0)); + + g.updateOptions({ valueRange: [10, 40] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 40], g.yAxisRange(0)); + + g.updateOptions({ valueRange: [10, null] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 44.2], g.yAxisRange(0)); + + g.updateOptions({ valueRange: [10, 40] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 40], g.yAxisRange(0)); + + g.updateOptions({ valueRange: [10, undefined] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 44.2], g.yAxisRange(0)); + + g.updateOptions({ valueRange: [10, 40] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 40], g.yAxisRange(0)); + g.updateOptions({ }); assertEquals([12, 18], g.xAxisRange()); assertEquals([10, 40], g.yAxisRange(0)); + + g.updateOptions({valueRange : null, axes: {y:{valueRange : [15, 20]}}}); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([15, 20], g.yAxisRange(0)); - g.updateOptions({ dateWindow : null, valueRange : null }); + g.updateOptions({ dateWindow : null, valueRange : null, axes: null }); assertEquals([10, 20], g.xAxisRange()); assertEquals([0, 55], g.yAxisRange(0)); }; @@ -84,7 +115,6 @@ RangeTestCase.prototype.zoom = function(g, xRange, yRange) { var originalXRange = g.xAxisRange(); var originalYRange = g.yAxisRange(0); - // Editing e.shiftKey post construction doesn't work for Firefox. Damn. DygraphOps.dispatchMouseDown(g, xRange[0], yRange[0]); DygraphOps.dispatchMouseMove(g, xRange[1], yRange[0]); // this is really necessary. DygraphOps.dispatchMouseUp(g, xRange[1], yRange[0]); @@ -115,10 +145,8 @@ RangeTestCase.prototype.testEmptyUpdateOptions_doesntUnzoom = function() { g.updateOptions({}); - // This currently fails. - // See http://code.google.com/p/dygraphs/issues/detail?id=192 assertEqualsDelta([11, 18], g.xAxisRange(), 0.1); - // assertEqualsDelta([35, 40], g.yAxisRange(0), 0.2); + assertEqualsDelta([35, 40], g.yAxisRange(0), 0.2); } /** @@ -135,3 +163,112 @@ RangeTestCase.prototype.testRestoreOriginalRanges_viaUpdateOptions = function() assertEquals([0, 55], g.yAxisRange(0)); assertEquals([10, 20], g.xAxisRange()); } + +/** + * Verify that log scale axis range is properly specified. + */ +RangeTestCase.prototype.testLogScaleExcludesZero = function() { + var g = new Dygraph("graph", FIVE_TO_ONE_THOUSAND, { logscale : true }); + assertEquals([10, 1099], g.yAxisRange(0)); + + g.updateOptions({ logscale : false }); + assertEquals([0, 1099], g.yAxisRange(0)); +} + +/** + * Verify that includeZero range is properly specified. + */ +RangeTestCase.prototype.testIncludeZeroIncludesZero = function() { + var g = new Dygraph("graph", [[0, 500], [500, 1000]], { includeZero : true }); + assertEquals([0, 1100], g.yAxisRange(0)); + + g.updateOptions({ includeZero : false }); + assertEquals([450, 1050], g.yAxisRange(0)); +} + + +/** + * Verify that includeZero range is properly specified per axis. + */ +RangeTestCase.prototype.testIncludeZeroPerAxis = function() { + var g = new Dygraph("graph", + 'X,A,B\n'+ + '0,50,50\n'+ + '50,110,110\n', + { + drawPoints: true, + pointSize:5, + series:{ + A: { + axis: 'y', + pointSize: 10 + }, + B: { + axis: 'y2' + } + }, + axes: { + 'y2': { includeZero: true } + } + }); + + + assertEquals([44, 116], g.yAxisRange(0)); + assertEquals([0, 121], g.yAxisRange(1)); + + g.updateOptions({ + axes: { + 'y2': { includeZero: false } + } + }); + + assertEquals([44, 116], g.yAxisRange(1)); +} + + +/** + * Verify that includeZero range is properly specified per axis with old axis options. + */ +RangeTestCase.prototype.testIncludeZeroPerAxisOld = function() { + var g = new Dygraph("graph", + 'X,A,B\n' + + '0,50,50\n' + + '50,110,110\n', + { + drawPoints: true, + pointSize: 5, + + A: { + pointSize: 10 + }, + B: { + axis: {} + }, + axes: { + 'y': { includeZero: true }, + 'y2': { includeZero: false } + } + }); + + assertEquals([0, 121], g.yAxisRange(0)); + assertEquals([44, 116], g.yAxisRange(1)); + + g.updateOptions({ + axes: { + 'y': { includeZero: false }, + 'y2': { includeZero: true } + } + }); + + assertEquals([44, 116], g.yAxisRange(0)); + assertEquals([0, 121], g.yAxisRange(1)); +} + +/** + * Verify that very large Y ranges don't break things. + */ +RangeTestCase.prototype.testHugeRange = function() { + var g = new Dygraph("graph", [[0, -1e120], [1, 1e230]], { includeZero : true }); + assertEqualsDelta(1, -1e229 / g.yAxisRange(0)[0], 0.001); + assertEqualsDelta(1, 1.1e230 / g.yAxisRange(0)[1], 0.001); +}