2.0.0 release fixes (#815)
[dygraphs.git] / auto_tests / tests / range_tests.js
index bdb87de..f14d30f 100644 (file)
 // THE SOFTWARE.
 
 
-/** 
+/**
  * @fileoverview Test valueRange and dateWindow changes.
  *
  * @author konigsberg@google.com (Robert Konigsberg)
  */
+
+import Dygraph from '../../src/dygraph';
+
+import DygraphOps from './DygraphOps';
+import {assertDeepCloseTo} from './custom_asserts';
+
 var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
 var ZERO_TO_FIFTY_STEPS = (function() {
   var a = [];
@@ -37,24 +43,23 @@ var ZERO_TO_FIFTY_STEPS = (function() {
 }());
 
 var FIVE_TO_ONE_THOUSAND = [
-    [ 1, 10 ], [ 2, 20 ], [ 3, 30 ], [ 4, 40 ] , [ 5, 50 ], 
+    [ 1, 10 ], [ 2, 20 ], [ 3, 30 ], [ 4, 40 ] , [ 5, 50 ],
     [ 6, 60 ], [ 7, 70 ], [ 8, 80 ], [ 9, 90 ] , [ 10, 1000 ]];
 
 describe("range-tests", function() {
 
-beforeEach(function() {
-  document.body.innerHTML = "<div id='graph'></div>";
-});
+cleanupAfterEach();
 
 var createGraph = function(opts, data, expectRangeX, expectRangeY) {
   if (data === undefined) data = ZERO_TO_FIFTY_STEPS;
   if (expectRangeX === undefined) expectRangeX = [10, 20];
   if (expectRangeY === undefined) expectRangeY = [0, 55];
-  var graph = document.getElementById("graph");
-  var g = new Dygraph(graph, data, opts);
+  if (!opts) opts = {};
+  opts['labels'] = ['X', 'Y'];
+  var g = new Dygraph('graph', data, opts);
 
-  assert.equalsDelta(expectRangeX, g.xAxisRange(), 0.01);
-  assert.equalsDelta(expectRangeY, g.yAxisRange(0), 0.01);
+  assertDeepCloseTo(expectRangeX, g.xAxisRange(), 0.01);
+  assertDeepCloseTo(expectRangeY, g.yAxisRange(0), 0.01);
 
   return g;
 };
@@ -101,7 +106,7 @@ it('testRangeSetOperations', function() {
   g.updateOptions({  });
   assert.deepEqual([12, 18], g.xAxisRange());
   assert.deepEqual([10, 40], g.yAxisRange(0));
-  
+
   g.updateOptions({valueRange : null, axes: {y:{valueRange : [15, 20]}}});
   assert.deepEqual([12, 18], g.xAxisRange());
   assert.deepEqual([15, 20], g.yAxisRange(0));
@@ -123,16 +128,16 @@ var zoom = function(g, xRange, yRange) {
   DygraphOps.dispatchMouseMove(g, xRange[1], yRange[0]); // this is really necessary.
   DygraphOps.dispatchMouseUp(g, xRange[1], yRange[0]);
 
-  assert.equalsDelta(xRange, g.xAxisRange(), 0.2);
-  // assert.equalsDelta(originalYRange, g.yAxisRange(0), 0.2); // Not true, it's something in the middle.
+  assertDeepCloseTo(xRange, g.xAxisRange(), 0.2);
+  // assert.closeTo(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]);
   DygraphOps.dispatchMouseMove(g, midX, yRange[1]); // this is really necessary.
   DygraphOps.dispatchMouseUp(g, midX, yRange[1]);
 
-  assert.equalsDelta(xRange, g.xAxisRange(), 0.2);
-  assert.equalsDelta(yRange, g.yAxisRange(0), 0.2);
+  assertDeepCloseTo(xRange, g.xAxisRange(), 0.2);
+  assertDeepCloseTo(yRange, g.yAxisRange(0), 0.2);
 }
 
 
@@ -144,13 +149,13 @@ it('testEmptyUpdateOptions_doesntUnzoom', function() {
   var g = createGraph();
   zoom(g, [ 11, 18 ], [ 35, 40 ]);
 
-  assert.equalsDelta([11, 18], g.xAxisRange(), 0.1);
-  assert.equalsDelta([35, 40], g.yAxisRange(0), 0.2);
+  assertDeepCloseTo([11, 18], g.xAxisRange(), 0.1);
+  assertDeepCloseTo([35, 40], g.yAxisRange(0), 0.2);
 
   g.updateOptions({});
 
-  assert.equalsDelta([11, 18], g.xAxisRange(), 0.1);
-  assert.equalsDelta([35, 40], g.yAxisRange(0), 0.2);
+  assertDeepCloseTo([11, 18], g.xAxisRange(), 0.1);
+  assertDeepCloseTo([35, 40], g.yAxisRange(0), 0.2);
 });
 
 /**
@@ -172,9 +177,12 @@ it('testRestoreOriginalRanges_viaUpdateOptions', function() {
  * Verify that log scale axis range is properly specified.
  */
 it('testLogScaleExcludesZero', function() {
-  var g = new Dygraph("graph", FIVE_TO_ONE_THOUSAND, { logscale : true });
+  var g = new Dygraph("graph", FIVE_TO_ONE_THOUSAND, {
+    logscale: true,
+    labels: ['X', 'Y']
+  });
   assert.deepEqual([10, 1099], g.yAxisRange(0));
+
   g.updateOptions({ logscale : false });
   assert.deepEqual([0, 1099], g.yAxisRange(0));
 });
@@ -183,9 +191,12 @@ it('testLogScaleExcludesZero', function() {
  * Verify that includeZero range is properly specified.
  */
 it('testIncludeZeroIncludesZero', function() {
-  var g = new Dygraph("graph", [[0, 500], [500, 1000]], { includeZero : true });
+  var g = new Dygraph("graph", [[0, 500], [500, 1000]], {
+    includeZero: true,
+    labels: ['X', 'Y']
+  });
   assert.deepEqual([0, 1100], g.yAxisRange(0));
+
   g.updateOptions({ includeZero : false });
   assert.deepEqual([450, 1050], g.yAxisRange(0));
 });
@@ -195,14 +206,14 @@ it('testIncludeZeroIncludesZero', function() {
  * Verify that includeZero range is properly specified per axis.
  */
 it('testIncludeZeroPerAxis', function() {
-  var g = new Dygraph("graph", 
+  var g = new Dygraph("graph",
     'X,A,B\n'+
     '0,50,50\n'+
     '50,110,110\n',
     {
       drawPoints: true,
       pointSize:5,
-      series:{ 
+      series:{
         A: {
           axis: 'y',
           pointSize: 10
@@ -210,7 +221,7 @@ it('testIncludeZeroPerAxis', function() {
         B: {
           axis: 'y2'
         }
-      },  
+      },
       axes: {
         'y2': { includeZero: true }
       }
@@ -231,20 +242,14 @@ it('testIncludeZeroPerAxis', function() {
 
 /**
  * Verify that very large Y ranges don't break things.
- */ 
-it('testHugeRange', function() {
-  var g = new Dygraph("graph", [[0, -1e120], [1, 1e230]], { includeZero : true });
-  assert.equalsDelta(1, -1e229 / g.yAxisRange(0)[0], 0.001);
-  assert.equalsDelta(1, 1.1e230 / g.yAxisRange(0)[1], 0.001);
-});
-
-/**
- * Verify old-style avoidMinZero option.
  */
-it('testAvoidMinZero', function() {
-  var g = createGraph({
-      avoidMinZero: true,
-    }, ZERO_TO_FIFTY_STEPS, [10, 20], [-5, 55]);
+it('testHugeRange', function() {
+  var g = new Dygraph("graph", [[0, -1e120], [1, 1e230]], {
+    includeZero: true,
+    labels: ['X', 'Y']
+  });
+  assert.closeTo(1, -1e229 / g.yAxisRange(0)[0], 0.001);
+  assert.closeTo(1, 1.1e230 / g.yAxisRange(0)[1], 0.001);
 });
 
 /**
@@ -328,24 +333,7 @@ it('testLogscalePad', function() {
       yRangePad: 30
     },
     [[-10, 10], [10, 10], [30, 1000]],
-    [-10, 30], [5.01691, 1993.25801]);
-});
-
-/**
- * Verify scrolling all-zero region, traditional.
- */
-it('testZeroScroll', function() {
-  var g = new Dygraph(
-      document.getElementById("graph"),
-      "X,Y\n" +
-      "1,0\n" +
-      "8,0\n" +
-      "9,0.1\n",
-      {
-        drawAxesAtZero: true,
-        animatedZooms: true,
-        avoidMinZero: true
-      });
+    [-10, 30], [5.623, 1778.279]);
 });
 
 /**