X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Frange_tests.js;h=c2ef95ea9152d8282debf68cb0d9a49e64925ca3;hb=1a19005fada6b8f190aa35b3908dc571ea360d3e;hp=608c05e23372e76293cd5ae28935e6ffbfe00581;hpb=3fc84ab9f2bd242018fd4d91f41a151e6d3b79f1;p=dygraphs.git diff --git a/auto_tests/tests/range_tests.js b/auto_tests/tests/range_tests.js index 608c05e..c2ef95e 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"); @@ -70,8 +73,12 @@ RangeTestCase.prototype.testRangeSetOperations = function() { 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,8 +91,7 @@ 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], function(e) { e.shiftKey = true; }); + 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]); @@ -93,7 +99,7 @@ RangeTestCase.prototype.zoom = function(g, xRange, yRange) { // assertEqualsDelta(originalYRange, g.yAxisRange(0), 0.2); // Not true, it's something in the middle. var midX = (xRange[1] - xRange[0]) / 2; - DygraphOps.dispatchMouseDown(g, midX, yRange[0], function(e) { e.shiftKey = true; }); + DygraphOps.dispatchMouseDown(g, midX, yRange[0]); DygraphOps.dispatchMouseMove(g, midX, yRange[1]); // this is really necessary. DygraphOps.dispatchMouseUp(g, midX, yRange[1]); @@ -110,6 +116,9 @@ RangeTestCase.prototype.testEmptyUpdateOptions_doesntUnzoom = function() { var g = this.createGraph(); this.zoom(g, [ 11, 18 ], [ 35, 40 ]); + assertEqualsDelta([11, 18], g.xAxisRange(), 0.1); + assertEqualsDelta([35, 40], g.yAxisRange(0), 0.2); + g.updateOptions({}); assertEqualsDelta([11, 18], g.xAxisRange(), 0.1); @@ -130,3 +139,34 @@ 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 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); +}