Change x-axis pixel spacing default to 70. wrapped-labels
authorDan Vanderkam <danvdk@gmail.com>
Fri, 28 Nov 2014 19:56:09 +0000 (14:56 -0500)
committerDan Vanderkam <danvdk@gmail.com>
Fri, 28 Nov 2014 19:56:09 +0000 (14:56 -0500)
Also updates tests. The cases where we get one axis label instead of
seven are a bit troubling.

auto_tests/tests/axis_labels-deprecated.js
auto_tests/tests/axis_labels.js
auto_tests/tests/multi_csv.js
auto_tests/tests/multiple_axes-old.js
auto_tests/tests/multiple_axes.js
dygraph.js

index 8133f0b..2a8be09 100644 (file)
@@ -70,7 +70,7 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedAxisLabelFormatter = functi
   var g = new Dygraph(graph, data, opts);
 
   assertEquals(['x0','x2','x4','x6','x8'], Util.getXLabels());
-  assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["y0","y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(2);
   assertEquals("2: y: 4", Util.getLegend());
@@ -106,8 +106,8 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedDateAxisLabelFormatter = fu
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, data, opts);
 
-  assertEquals(["x2011/01/01", "x2011/01/02", "x2011/01/03", "x2011/01/04", "x2011/01/05", "x2011/01/06", "x2011/01/07", "x2011/01/08"], Util.getXLabels());
-  assertEquals(['y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["x2011/01/02"], Util.getXLabels());
+  assertEquals(["y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(0);
   assertEquals("2011/01/01: y: 2", Util.getLegend());
@@ -145,8 +145,7 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedValueFormatter = function (
 
   // the valueFormatter options do not affect the ticks.
   assertEquals(['0','2','4','6','8'], Util.getXLabels());
-  assertEquals(['0','2','4','6','8','10','12','14','16','18'],
-               Util.getYLabels());
+  assertEquals(["0","5","10","15"], Util.getYLabels());
 
   // they do affect the legend, however.
   g.setSelection(2);
@@ -183,8 +182,8 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedDateValueFormatter = functi
   var g = new Dygraph(graph, data, opts);
 
   // valueFormatters do not affect ticks.
-  assertEquals(['01 Jan','02 Jan','03 Jan','04 Jan','05 Jan','06 Jan','07 Jan','08 Jan'], Util.getXLabels());
-  assertEquals(['2','4','6','8','10','12','14','16','18'], Util.getYLabels());
+  assertEquals(["02 Jan"], Util.getXLabels());
+  assertEquals(["5","10","15"], Util.getYLabels());
 
   // the valueFormatter options also affect the legend.
   g.setSelection(2);
@@ -219,7 +218,7 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedAxisLabelFormatterPrecedenc
   var g = new Dygraph(graph, data, opts);
 
   assertEquals(['x0','x2','x4','x6','x8'], Util.getXLabels());
-  assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["y0","y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(9);
   assertEquals("xvf9: y: yvf18", Util.getLegend());
@@ -261,7 +260,7 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedAxisLabelFormatterIncrement
   });
 
   assertEquals(["x0","x2","x4","x6","x8"], Util.getXLabels());
-  assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["y0","y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(9);
   assertEquals("xvf9: y: yvf18", Util.getLegend());
index cbe106e..25a8161 100644 (file)
@@ -74,17 +74,17 @@ AxisLabelsTestCase.prototype.testSmallRangeNearZero = function() {
 
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, data, opts);
-  assertEqualsDelta([-0.1, -0.08, -0.06, -0.04, -0.02, 0, 0.02, 0.04, 0.06, 0.08],
+  assertEqualsDelta([-0.1,-0.05,0,0.05],
                     Util.makeNumbers(Util.getYLabels()), this.kCloseFloat);
 
   opts.valueRange = [-0.05, 0.05];
   g.updateOptions(opts);
-  assertEquals([-0.05, -0.04, -0.03, -0.02, -0.01, 0, 0.01, 0.02, 0.03, 0.04],
+  assertEquals([-0.04,-0.02,0,0.02,0.04],
                Util.makeNumbers(Util.getYLabels()));
 
   opts.valueRange = [-0.01, 0.01];
   g.updateOptions(opts);
-  assertEquals([-0.01, -8.00e-3, -6.00e-3, -4.00e-3, -2.00e-3, 0, 2.00e-3, 4.00e-3, 6.00e-3, 8.00e-3],
+  assertEquals([-0.01,-0.005,0,0.005],
                Util.makeNumbers(Util.getYLabels()));
 
   g.setSelection(1);
@@ -116,7 +116,7 @@ AxisLabelsTestCase.prototype.testSmallRangeAwayFromZero = function() {
   opts.valueRange = [9.999, 10.001];
   g.updateOptions(opts);
   // TODO(danvk): this is even worse!
-  assertEquals(["10","10","10","10","10","10","10","10","10","10"], Util.getYLabels());
+  assertEquals(["10","10","10","10"], Util.getYLabels());
 
   g.setSelection(1);
   assertEquals('1: Y: 0', Util.getLegend());
@@ -189,7 +189,7 @@ AxisLabelsTestCase.prototype.testAxisLabelFormatter = function () {
   var g = new Dygraph(graph, data, opts);
 
   assertEquals(['x0','x2','x4','x6','x8'], Util.getXLabels());
-  assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["y0","y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(2);
   assertEquals("2: y: 4", Util.getLegend());
@@ -229,8 +229,8 @@ AxisLabelsTestCase.prototype.testDateAxisLabelFormatter = function () {
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, data, opts);
 
-  assertEquals(["x2011/01/01", "x2011/01/02", "x2011/01/03", "x2011/01/04", "x2011/01/05", "x2011/01/06", "x2011/01/07", "x2011/01/08"], Util.getXLabels());
-  assertEquals(['y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["x2011/01/02"], Util.getXLabels());
+  assertEquals(["y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(0);
   assertEquals("2011/01/01: y: 2", Util.getLegend());
@@ -274,7 +274,7 @@ AxisLabelsTestCase.prototype.testValueFormatter = function () {
 
   // the valueFormatter options do not affect the ticks.
   assertEquals(['0','2','4','6','8'], Util.getXLabels());
-  assertEquals(['0','2','4','6','8','10','12','14','16','18'],
+  assertEquals(["0","5","10","15"],
                Util.getYLabels());
 
   // they do affect the legend, however.
@@ -318,8 +318,8 @@ AxisLabelsTestCase.prototype.testDateValueFormatter = function () {
   var g = new Dygraph(graph, data, opts);
 
   // valueFormatters do not affect ticks.
-  assertEquals(['01 Jan','02 Jan','03 Jan','04 Jan','05 Jan','06 Jan','07 Jan','08 Jan'], Util.getXLabels());
-  assertEquals(['2','4','6','8','10','12','14','16','18'], Util.getYLabels());
+  assertEquals(["02 Jan"], Util.getXLabels());
+  assertEquals(["5","10","15"], Util.getYLabels());
 
   // the valueFormatter options also affect the legend.
   g.setSelection(2);
@@ -360,7 +360,7 @@ AxisLabelsTestCase.prototype.testAxisLabelFormatterPrecedence = function () {
   var g = new Dygraph(graph, data, opts);
 
   assertEquals(['x0','x2','x4','x6','x8'], Util.getXLabels());
-  assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["y0","y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(9);
   assertEquals("xvf9: y: yvf18", Util.getLegend());
@@ -418,7 +418,7 @@ AxisLabelsTestCase.prototype.testAxisLabelFormatterIncremental = function () {
   });
 
   assertEquals(["x0","x2","x4","x6","x8"], Util.getXLabels());
-  assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util.getYLabels());
+  assertEquals(["y0","y5","y10","y15"], Util.getYLabels());
 
   g.setSelection(9);
   assertEquals("xvf9: y: yvf18", Util.getLegend());
@@ -444,7 +444,7 @@ AxisLabelsTestCase.prototype.testGlobalFormatters = function() {
   var g = new Dygraph(graph, data, opts);
 
   assertEquals(['alf0','alf2','alf4','alf6','alf8'], Util.getXLabels());
-  assertEquals(['alf0','alf2','alf4','alf6','alf8','alf10','alf12','alf14','alf16','alf18'], Util.getYLabels());
+  assertEquals(["alf0","alf5","alf10","alf15"], Util.getYLabels());
 
   g.setSelection(9);
   assertEquals("vf9: y: vf18", Util.getLegend());
@@ -551,7 +551,7 @@ AxisLabelsTestCase.prototype.testLabelKMG2_top = function() {
 AxisLabelsTestCase.prototype.testLogScale = function() {
   var g = new Dygraph("graph", [[0, 5], [1, 1000]], { logscale : true });
   var nonEmptyLabels = Util.getYLabels().filter(function(x) { return x.length > 0; });
-  assertEquals(["6","10","30","60","100","300","600","1000"], nonEmptyLabels);
+  assertEquals(["5","10","20","50","100","200","500","1000"], nonEmptyLabels);
  
   g.updateOptions({ logscale : false });
   assertEquals(['0','200','400','600','800','1000'], Util.getYLabels());
@@ -723,7 +723,7 @@ AxisLabelsTestCase.prototype.testLabelFormatterOverridesLabelsKMB = function() {
         }
       });
   assertEquals(["0:X","500:X","1000:X","1500:X","2000:X"], Util.getYLabels());
-  assertEquals(["1:X","1.5:X","2:X","2.5:X","3:X","3.5:X"], Util.getXLabels());
+  assertEquals(["1:X","2:X","3:X"], Util.getXLabels());
 }
 
 /*
@@ -749,7 +749,7 @@ AxisLabelsTestCase.prototype.testLabelsKMBPerAxis = function() {
 
   // labelsKMB doesn't apply to the x axis. This value should be different.
   // BUG : https://code.google.com/p/dygraphs/issues/detail?id=488
-  assertEquals(["1000", "1500", "2000", "2500", "3000", "3500"], Util.getXLabels());
+  assertEquals(["1000","2000","3000"], Util.getXLabels());
   assertEquals( ["0","500","1000","1500","2000"], Util.getYLabels(1));
   assertEquals(["0","500","1K","1.5K","2K"], Util.getYLabels(2));
 };
@@ -779,7 +779,7 @@ AxisLabelsTestCase.prototype.testLabelsKMBG2IPerAxis = function() {
   // Plus I can't be sure they're doing the same thing as they're done in different
   // bits of code.
   // BUG : https://code.google.com/p/dygraphs/issues/detail?id=488
-  assertEquals(["1024","1536","2048","2560","3072","3584"], Util.getXLabels());
+  assertEquals(["1024","2048","3072"], Util.getXLabels());
   assertEquals( ["0","500","1000","1500","2000"], Util.getYLabels(1));
   assertEquals(["0","500","1000","1.46k","1.95k"], Util.getYLabels(2));
 };
@@ -807,7 +807,7 @@ AxisLabelsTestCase.prototype.testSigFigsPerAxis = function() {
       });
   // sigFigs doesn't apply to the x axis. This value should be different.
   // BUG : https://code.google.com/p/dygraphs/issues/detail?id=488
-  assertEquals(["1000","1500","2000","2500","3000","3500"], Util.getXLabels());
+  assertEquals(["1000","2000","3000"], Util.getXLabels());
   assertEquals(["0.0","5.0e+2","1.0e+3","1.5e+3","2.0e+3"], Util.getYLabels(1));
   assertEquals(["0.00000","500.000","1000.00","1500.00","2000.00"], Util.getYLabels(2));
 }
@@ -852,13 +852,13 @@ AxisLabelsTestCase.prototype.testDigitsAfterDecimalPerAxis = function() {
   // digitsAfterDecimal is ignored for the x-axis.
   // BUG : https://code.google.com/p/dygraphs/issues/detail?id=488
   g.updateOptions({ axes: { x: { digitsAfterDecimal: 3 }}});
-  assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util.getXLabels());
+  assertEquals(["0.006","0.007","0.008"], Util.getXLabels());
   g.updateOptions({ axes: { x: { digitsAfterDecimal: 4 }}});
-  assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util.getXLabels());
+  assertEquals(["0.006","0.007","0.008"], Util.getXLabels());
   g.updateOptions({ axes: { x: { digitsAfterDecimal: 5 }}});
-  assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util.getXLabels());
+  assertEquals(["0.006","0.007","0.008"], Util.getXLabels());
   g.updateOptions({ axes: { x: { digitsAfterDecimal: null }}});
-  assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util.getXLabels());
+  assertEquals(["0.006","0.007","0.008"], Util.getXLabels());
 }
 
 /**
@@ -895,11 +895,11 @@ AxisLabelsTestCase.prototype.testMaxNumberWidthPerAxis = function() {
   // maxNumberWidth is ignored for the x-axis.
   // BUG : https://code.google.com/p/dygraphs/issues/detail?id=488
   g.updateOptions({ axes: { x: { maxNumberWidth: 4 }}});
-  assertEquals(["12401","12401.5","12402","12402.5","12403","12403.5"], Util.getXLabels());
+  assertEquals(["12401","12402","12403"], Util.getXLabels());
   g.updateOptions({ axes: { x: { maxNumberWidth: 5 }}});
-  assertEquals(["12401","12401.5","12402","12402.5","12403","12403.5"], Util.getXLabels());
+  assertEquals(["12401","12402","12403"], Util.getXLabels());
   g.updateOptions({ axes: { x: { maxNumberWidth: null }}});
-  assertEquals(["12401","12401.5","12402","12402.5","12403","12403.5"], Util.getXLabels());
+  assertEquals(["12401","12402","12403"], Util.getXLabels());
 }
 
 /*
index 3594b15..764c402 100644 (file)
@@ -36,7 +36,7 @@ MultiCsvTestCase.prototype.testOneCSV = function() {
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, data, opts);
 
-  assertEquals(['0','0.5','1','1.5','2','2.5'], getXLabels());
+  assertEquals(['0', '1', '2'], getXLabels());
 };
 
 MultiCsvTestCase.prototype.testTwoCSV = function() {
@@ -54,9 +54,9 @@ MultiCsvTestCase.prototype.testTwoCSV = function() {
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, data, opts);
 
-  assertEquals(['0','0.5','1','1.5','2','2.5'], getXLabels());
+  assertEquals(['0', '1', '2'], getXLabels());
 
   g.updateOptions({file: data});
 
-  assertEquals(['0','0.5','1','1.5','2','2.5'], getXLabels());
+  assertEquals(['0', '1', '2'], getXLabels());
 };
index 77e9f89..912b3fd 100644 (file)
@@ -50,8 +50,8 @@ MultipleAxesOldTestCase.prototype.testOldBasicMultipleAxes = function() {
     }
   );
 
-  assertEquals(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"], Util.getYLabels("1"));
-  assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], Util.getYLabels("2"));
+  assertEquals(["0","20","40","60","80","100"], Util.getYLabels("1"));
+  assertEquals(["900K","1.12M","1.34M","1.55M","1.77M","1.99M"], Util.getYLabels("2"));
 };
 
 MultipleAxesOldTestCase.prototype.testOldNewStylePerAxisOptions = function() {
@@ -78,8 +78,8 @@ MultipleAxesOldTestCase.prototype.testOldNewStylePerAxisOptions = function() {
     }
   );
 
-  assertEquals(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"], Util.getYLabels("1"));
-  assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], Util.getYLabels("2"));
+  assertEquals(["0","20","40","60","80","100"], Util.getYLabels("1"));
+  assertEquals(["900K","1.12M","1.34M","1.55M","1.77M","1.99M"], Util.getYLabels("2"));
 };
 
 MultipleAxesOldTestCase.prototype.testOldMultiAxisLayout = function() {
index a995eca..cd59a21 100644 (file)
@@ -55,8 +55,8 @@ MultipleAxesTestCase.prototype.testBasicMultipleAxes = function() {
     }
   );
 
-  assertEquals(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"], Util.getYLabels("1"));
-  assertEquals(["900K", "1.01M", "1.12M", "1.23M", "1.34M", "1.45M", "1.55M", "1.66M", "1.77M", "1.88M", "1.99M"], Util.getYLabels("2"));
+  assertEquals(["0","20","40","60","80","100"], Util.getYLabels("1"));
+  assertEquals(["900K","1.12M","1.34M","1.55M","1.77M","1.99M"], Util.getYLabels("2"));
 };
 
 MultipleAxesTestCase.prototype.testTwoAxisVisibility = function() {
index ab44fac..43768a9 100644 (file)
@@ -358,8 +358,8 @@ Dygraph.DEFAULT_ATTRS = {
   // per-axis options
   axes: {
     x: {
-      pixelsPerLabel: 60,
-      axisLabelWidth: 58,  // TODO(danvk): make these 10-20px different again.
+      pixelsPerLabel: 70,
+      axisLabelWidth: 60,
       axisLabelFormatter: Dygraph.dateAxisLabelFormatter,
       valueFormatter: Dygraph.dateValueFormatter,
       drawGrid: true,