Check for new options before updating synchronised graphs (Fixes #760)
[dygraphs.git] / auto_tests / tests / axis_labels.js
index abff8b2..c390392 100644 (file)
@@ -3,14 +3,16 @@
  *
  * @author dan@dygraphs.com (Dan Vanderkam)
  */
-describe("axis-labels", function() {
 
-beforeEach(function() {
-  document.body.innerHTML = "<div id='graph'></div>";
-});
+import Dygraph from '../../src/dygraph';
+import * as utils from '../../src/dygraph-utils';
+import DEFAULT_ATTRS from '../../src/dygraph-default-attrs';
+import Util from './Util';
+import {assertDeepCloseTo} from './custom_asserts';
 
-afterEach(function() {
-});
+describe("axis-labels", function() {
+
+cleanupAfterEach();
 
 var simpleData =
     "X,Y,Y2\n" +
@@ -204,7 +206,7 @@ it('testDateAxisLabelFormatter', function() {
       x : {
         pixelsPerLabel: 60,
         axisLabelFormatter : function(x, granularity, opts, dg) {
-          assert.isTrue(Dygraph.isDateLike(x));
+          assert.isTrue(utils.isDateLike(x));
           assert.equal('number', typeof(granularity));
           assert.equal('function', typeof(opts));
           assert.equal('[Dygraph graph]', dg.toString());
@@ -686,6 +688,33 @@ it('testLogScale', function() {
 });
 
 /**
+ * Verify that log scale axis range works with yRangePad.
+ *
+ * This is a regression test for https://github.com/danvk/dygraphs/issues/661 .
+ */
+it('testLogScalePad', function() {
+  var g = new Dygraph("graph",
+                      [[0, 1e-5], [1, 0.25], [2, 1], [3, 3], [4, 10]], {
+                        width: 250,
+                        height: 130,
+                        logscale: true,
+                        yRangePad: 30,
+                        axes: {y: {valueRange: [1, 10]}},
+                        labels: ['X', 'Y']
+                      });
+  var nonEmptyLabels = Util.getYLabels().filter(function(x) { return x.length > 0; });
+  assert.deepEqual(['1', '7', '30'], nonEmptyLabels);
+
+  g.updateOptions({ yRangePad: 10, axes: {y: {valueRange: [0.25005, 3]}} });
+  nonEmptyLabels = Util.getYLabels().filter(function(x) { return x.length > 0; });
+  assert.deepEqual(['0.4', '1', '3'], nonEmptyLabels);
+
+  g.updateOptions({ axes: {y: {valueRange: [0.01, 3]}} });
+  nonEmptyLabels = Util.getYLabels().filter(function(x) { return x.length > 0; });
+  assert.deepEqual(['0.01','0.1','0.7','5'], nonEmptyLabels);
+});
+
+/**
  * Verify that include zero range is properly specified.
  */
 it('testIncludeZero', function() {
@@ -705,7 +734,7 @@ it('testAxisLabelFontSize', function() {
   var g = new Dygraph(graph, simpleData, {});
 
   // Be sure we're dealing with a 14-point default.
-  assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+  assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize);
 
   var assertFontSize = function(selector, expected) {
     Util.assertStyleOfChildren(selector, "font-size", expected);
@@ -763,7 +792,7 @@ it('testAxisLabelFontSizeNull', function() {
   };
 
   // Be sure we're dealing with a 14-point default.
-  assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+  assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize);
 
   assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "14px");
   assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px");
@@ -774,7 +803,7 @@ it('testAxisLabelColor', function() {
   var g = new Dygraph(graph, simpleData, {});
 
   // Be sure we're dealing with a black default.
-  assert.equal("black", Dygraph.DEFAULT_ATTRS.axisLabelColor);
+  assert.equal("black", DEFAULT_ATTRS.axisLabelColor);
 
   var assertColor = function(selector, expected) {
     Util.assertStyleOfChildren(selector, "color", expected);
@@ -832,7 +861,7 @@ it('testAxisLabelColorNull', function() {
   }
 
   // Be sure we're dealing with a 14-point default.
-  assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+  assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize);
 
   assertColor(document.querySelectorAll(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
   assertColor(document.querySelectorAll(".dygraph-axis-label-y"), "rgb(0, 0, 0)");