From 8b9d9eba95fa35afc9c72de14639c872329c25ab Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Wed, 10 Aug 2011 12:19:46 -0400 Subject: [PATCH] never use valueFormatters for ticks --- auto_tests/tests/axis_labels.js | 27 +++++++++++---------------- dygraph-tickers.js | 2 +- dygraph.js | 2 ++ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index c8b3bab..fedf22b 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -192,10 +192,10 @@ AxisLabelsTestCase.prototype.testDateAxisLabelFormatter = function () { var opts = { width: 480, height: 320, - xAxisLabelFormatter: function(x, granularity) { + xAxisLabelFormatter: function(x, granularity, b) { return 'x' + x.strftime('%Y/%m/%d'); }, - yAxisLabelFormatter: function(y) { + yAxisLabelFormatter: function(y, a, b) { return 'y' + y; }, labels: ['x', 'y'] @@ -236,14 +236,12 @@ AxisLabelsTestCase.prototype.testValueFormatter = function () { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); - assertEquals(["0","2","4","6","8"], getXLabels()); - - // This would be more consistent with the behavior of yValueFormatter: - // assertEquals(['x0','x2','x4','x6','x8'], getXLabels()); - - assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], getYLabels()); + // the valueFormatter options do not affect the ticks. + assertEquals(['0','2','4','6','8'], getXLabels()); + assertEquals(['0','2','4','6','8','10','12','14','16','18'], + getYLabels()); - // the valueFormatter options also affect the legend. + // they do affect the legend, however. g.setSelection(2); assertEquals("x2: y:y4", getLegend()); }; @@ -268,16 +266,13 @@ AxisLabelsTestCase.prototype.testDateValueFormatter = function () { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); - // This is the existing behavior: - assertEquals(["01Jan","02Jan","03Jan","04Jan","05Jan","06Jan","07Jan","08Jan","09Jan"], getXLabels()); - - // This would be more consistent with the yValueFormatter behavior: - // 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", "x2011/01/09"], getXLabels()); - assertEquals(['y2','y4','y6','y8','y10','y12','y14','y16','y18'], getYLabels()); + // valueFormatters do not affect ticks. + assertEquals(['01Jan','02Jan','03Jan','04Jan','05Jan','06Jan','07Jan','08Jan','09Jan'], getXLabels()); + assertEquals(['2','4','6','8','10','12','14','16','18'], getYLabels()); // the valueFormatter options also affect the legend. g.setSelection(2); - assertEquals("x2011/01/03: y:y6", getLegend()); + assertEquals('x2011/01/03: y:y6', getLegend()); }; // This test verifies that when both a valueFormatter and an axisLabelFormatter diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 4073076..a0c8187 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -158,7 +158,7 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { k_labels = [ "k", "M", "G", "T" ]; } - var formatter = opts('axisLabelFormatter') || opts('valueFormatter'); + var formatter = opts('axisLabelFormatter'); // Add labels to the ticks. for (var i = 0; i < ticks.length; i++) { diff --git a/dygraph.js b/dygraph.js index 48b48f1..dd857d6 100644 --- a/dygraph.js +++ b/dygraph.js @@ -243,11 +243,13 @@ Dygraph.DEFAULT_ATTRS = { y: { pixelsPerLabel: 30, valueFormatter: Dygraph.numberFormatter, + axisLabelFormatter: Dygraph.numberFormatter, ticker: null // will be set in dygraph-tickers.js }, y2: { pixelsPerLabel: 30, valueFormatter: Dygraph.numberFormatter, + axisLabelFormatter: Dygraph.numberFormatter, ticker: null // will be set in dygraph-tickers.js } } -- 2.7.4