From: Sergey Date: Mon, 16 Sep 2013 21:19:09 +0000 (-0400) Subject: Modifying the numericTicks algorithm to include the last 'nice' tick X-Git-Tag: v1.1.0~86^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=9146b6c0fa1656936f8511cdb5bf1509de9268b6;p=dygraphs.git Modifying the numericTicks algorithm to include the last 'nice' tick (either at range end or just past it). This has the effect of making a (grid lines, axis label) pair always show up together or not at all. Previously it was possible to get a label but no gridline at the edge of the chart. Squashed commit of the following: commit 32955f836c3c32c11f009ae250cd35682d641e5c Merge: d3b7c40 0b99641 Author: Dan Vanderkam Date: Mon Sep 16 17:18:40 2013 -0400 Merge branch 'master' of https://github.com/blindmonkey/dygraphs into 269-end-ticks commit 0b996410efcb7a53315347c8cea38dc225f069ee Author: Sergey Date: Mon Sep 16 17:08:36 2013 -0400 Reverting multi-csv commit 3f72c23c3ebc23adc64dd2605175ff163491d8e2 Author: Sergey Date: Mon Sep 16 17:07:26 2013 -0400 Changing it so that the right-most X axis tick isn't displayed, and changing the tests to reflect that commit 3605ec18fb45718dca3dbd3bfb818adb5acc79eb Author: Sergey Date: Mon Sep 16 16:40:18 2013 -0400 Reverting whitespace stuff commit 11959a26e45be3481425f3ba68d78e63730eab4a Author: Sergey Date: Mon Sep 16 14:43:41 2013 -0400 Reverting multiple axes old test commit 4d91af0850a1fa72f693c497ac62e88e35c505eb Author: Sergey Date: Mon Sep 16 14:42:56 2013 -0400 Reverting multiple axes test commit 40b6ea279591df646f10d3ec44f760a20b42cf8a Author: Sergey Date: Fri Sep 13 14:14:29 2013 -0400 Changing layout to not layout ticks whose gridline is slightly offscreen. commit cec9c2857c3c03b14521ccfb4a44bbb4d7163776 Author: Sergey Date: Thu Sep 12 13:26:12 2013 -0400 Adding tests for the numeric ticker algorithm change. commit 106c0318cdf6c763a06545cf25f6ef66084cadf7 Author: Sergey Date: Thu Sep 12 12:16:35 2013 -0400 Changing numericTicks so that it returns the last nice value that might be just outside the axis --- diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index f85b0ff..42c2c06 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -38,6 +38,7 @@ + diff --git a/auto_tests/tests/axis_labels-deprecated.js b/auto_tests/tests/axis_labels-deprecated.js index 972362a..f1c7ea3 100644 --- a/auto_tests/tests/axis_labels-deprecated.js +++ b/auto_tests/tests/axis_labels-deprecated.js @@ -103,7 +103,7 @@ 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", "x2011/01/09"], Util.getXLabels()); + 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()); g.setSelection(0); @@ -179,7 +179,7 @@ DeprecatedAxisLabelsTestCase.prototype.testDeprecatedDateValueFormatter = functi var g = new Dygraph(graph, data, opts); // valueFormatters do not affect ticks. - assertEquals(['01Jan','02Jan','03Jan','04Jan','05Jan','06Jan','07Jan','08Jan','09Jan'], Util.getXLabels()); + assertEquals(['01Jan','02Jan','03Jan','04Jan','05Jan','06Jan','07Jan','08Jan'], Util.getXLabels()); assertEquals(['2','4','6','8','10','12','14','16','18'], Util.getYLabels()); // the valueFormatter options also affect the legend. diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index c9f60f8..10b7a09 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -228,7 +228,7 @@ 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", "x2011/01/09"], Util.getXLabels()); + 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()); g.setSelection(0); @@ -316,7 +316,7 @@ AxisLabelsTestCase.prototype.testDateValueFormatter = function () { var g = new Dygraph(graph, data, opts); // valueFormatters do not affect ticks. - assertEquals(['01Jan','02Jan','03Jan','04Jan','05Jan','06Jan','07Jan','08Jan','09Jan'], Util.getXLabels()); + assertEquals(['01Jan','02Jan','03Jan','04Jan','05Jan','06Jan','07Jan','08Jan'], Util.getXLabels()); assertEquals(['2','4','6','8','10','12','14','16','18'], Util.getYLabels()); // the valueFormatter options also affect the legend. diff --git a/auto_tests/tests/numeric_ticker.js b/auto_tests/tests/numeric_ticker.js new file mode 100644 index 0000000..fcda671 --- /dev/null +++ b/auto_tests/tests/numeric_ticker.js @@ -0,0 +1,72 @@ +/** + * @fileoverview Test cases for the numeric tick-generating functions. + * These were generated by adding logging code to the old ticker functions. The + * tests serve to track existing behavior should it change in the future. + * + * @author danvdk@gmail.com (Dan Vanderkam) + */ + +var NumericTickerTestCase = TestCase("numeric-ticker-tests"); + +NumericTickerTestCase.prototype.setUp = function() { + document.body.innerHTML = "
"; +}; + +NumericTickerTestCase.prototype.createOptionsViewForAxis = function(axis, dict) { + return function (x) { + if (dict && dict.hasOwnProperty(x)) { + return dict[x]; + } + if (Dygraph.DEFAULT_ATTRS.axes[axis].hasOwnProperty(x)) { + return Dygraph.DEFAULT_ATTRS.axes[axis][x]; + } + if (Dygraph.DEFAULT_ATTRS.hasOwnProperty(x)) { + return Dygraph.DEFAULT_ATTRS[x]; + } + if (x == 'axisLabelFormatter') return null; + throw "mysterious " + axis + "-axis option: " + x; + }; +}; + +NumericTickerTestCase.prototype.testBasicNumericTicker = function() { + var opts = {"logscale":null,"labelsKMG2":false,"labelsKMB":false}; + var options = this.createOptionsViewForAxis('y', opts); + + var ticks = Dygraph.numericTicks(-0.4, 4.4, 320, options); + var expected_ticks = [ + {"v":-0.5,"label":"-0.5"}, + {"v":0,"label":"0"}, + {"v":0.5,"label":"0.5"}, + {"v":1,"label":"1"}, + {"v":1.5,"label":"1.5"}, + {"v":2,"label":"2"}, + {"v":2.5,"label":"2.5"}, + {"v":3,"label":"3"}, + {"v":3.5,"label":"3.5"}, + {"v":4,"label":"4"}, + {"v":4.5,"label":"4.5"}]; + assertEquals(expected_ticks, ticks); + + ticks = Dygraph.numericTicks(1, 84, 540, options); + var expected_ticks = [ + {"v":0,"label":"0"}, + {"v":5,"label":"5"}, + {"v":10,"label":"10"}, + {"v":15,"label":"15"}, + {"v":20,"label":"20"}, + {"v":25,"label":"25"}, + {"v":30,"label":"30"}, + {"v":35,"label":"35"}, + {"v":40,"label":"40"}, + {"v":45,"label":"45"}, + {"v":50,"label":"50"}, + {"v":55,"label":"55"}, + {"v":60,"label":"60"}, + {"v":65,"label":"65"}, + {"v":70,"label":"70"}, + {"v":75,"label":"75"}, + {"v":80,"label":"80"}, + {"v":85,"label":"85"} + ]; + assertEquals(expected_ticks, ticks); +}; diff --git a/dygraph-layout.js b/dygraph-layout.js index 93e0c3a..56fdc3b 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -278,7 +278,7 @@ DygraphLayout.prototype._evaluateLineTicks = function() { tick = this.xTicks_[i]; label = tick.label; pos = this.xscale * (tick.v - this.minxval); - if ((pos >= 0.0) && (pos <= 1.0)) { + if ((pos >= 0.0) && (pos < 1.0)) { this.xticks.push([pos, label]); } } @@ -290,7 +290,7 @@ DygraphLayout.prototype._evaluateLineTicks = function() { tick = axis.ticks[j]; label = tick.label; pos = this.dygraph_.toPercentYCoord(tick.v, i); - if ((pos >= 0.0) && (pos <= 1.0)) { + if ((pos > 0.0) && (pos <= 1.0)) { this.yticks.push([i, pos, label]); } } diff --git a/dygraph-tickers.js b/dygraph-tickers.js index f4778b1..d2e1003 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -184,7 +184,7 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { // Construct the set of ticks. // Allow reverse y-axis if it's explicitly requested. if (low_val > high_val) scale *= -1; - for (i = 0; i < nTicks; i++) { + for (i = 0; i <= nTicks; i++) { tickV = low_val + i * scale; ticks.push( {v: tickV} ); }