Permalink
Browse files

Merge branch 'fix-log-ticks' into 2.9.3

  • Loading branch information...
2 parents 83c6f20 + 0f12c1b commit 0d31c17360b2a59158b173fd5583fb4a9d3aa5b8 @mbostock mbostock committed Jun 14, 2012
Showing with 25 additions and 9 deletions.
  1. +2 −2 d3.v2.js
  2. +4 −4 d3.v2.min.js
  3. +2 −2 src/scale/log.js
  4. +17 −1 test/scale/log-test.js
View
4 d3.v2.js
@@ -2813,11 +2813,11 @@ function d3_scale_log(linear, log) {
scale.tickFormat = function(n, format) {
if (arguments.length < 2) format = d3_scale_logFormat;
if (arguments.length < 1) return format;
- var k = n / scale.ticks().length,
+ var k = Math.max(.1, n / scale.ticks().length),
f = log === d3_scale_logn ? (e = -1e-12, Math.floor) : (e = 1e-12, Math.ceil),
e;
return function(d) {
- return d / pow(f(log(d) + e)) < k ? format(d) : "";
+ return d / pow(f(log(d) + e)) <= k ? format(d) : "";
};
};
View
8 d3.v2.min.js
4 additions, 4 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
4 src/scale/log.js
@@ -51,11 +51,11 @@ function d3_scale_log(linear, log) {
scale.tickFormat = function(n, format) {
if (arguments.length < 2) format = d3_scale_logFormat;
if (arguments.length < 1) return format;
- var k = n / scale.ticks().length,
+ var k = Math.max(.1, n / scale.ticks().length),
f = log === d3_scale_logn ? (e = -1e-12, Math.floor) : (e = 1e-12, Math.ceil),
e;
return function(d) {
- return d / pow(f(log(d) + e)) < k ? format(d) : "";
+ return d / pow(f(log(d) + e)) <= k ? format(d) : "";
};
};
View
18 test/scale/log-test.js
@@ -179,7 +179,7 @@ suite.addBatch({
"can generate fewer ticks, if desired": function(log) {
var x = log();
assert.deepEqual(x.ticks().map(x.tickFormat(5)), [
- "1e+0", "2e+0", "3e+0", "4e+0", "", "", "", "", "",
+ "1e+0", "2e+0", "3e+0", "4e+0", "5e+0", "", "", "", "",
"1e+1"
]);
var x = log().domain([100, 1]);
@@ -189,6 +189,22 @@ suite.addBatch({
"1e+2"
]);
},
+ "generates powers-of-ten ticks, even for huge domains": function(log) {
+ var x = log().domain([1e10, 1]);
+ assert.deepEqual(x.ticks().map(x.tickFormat(10)), [
+ "1e+0", "", "", "", "", "", "", "", "",
+ "1e+1", "", "", "", "", "", "", "", "",
+ "1e+2", "", "", "", "", "", "", "", "",
+ "1e+3", "", "", "", "", "", "", "", "",
+ "1e+4", "", "", "", "", "", "", "", "",
+ "1e+5", "", "", "", "", "", "", "", "",
+ "1e+6", "", "", "", "", "", "", "", "",
+ "1e+7", "", "", "", "", "", "", "", "",
+ "1e+8", "", "", "", "", "", "", "", "",
+ "1e+9", "", "", "", "", "", "", "", "",
+ "1e+10"
+ ]);
+ },
"can override the tick format": function(log) {
var x = log().domain([1000.1, 1]);
assert.deepEqual(x.ticks().map(x.tickFormat(10, d3.format("+,d"))), [

0 comments on commit 0d31c17

Please sign in to comment.