Permalink
Browse files

Fix a bug in d3.scale.log ticks.

  • Loading branch information...
1 parent b49c878 commit 29efd2a6d5e27cfaa63ed559ec4986af53aaa80a @mbostock mbostock committed Mar 30, 2011
Showing with 85 additions and 57 deletions.
  1. +2 −2 d3.js
  2. +53 −53 d3.min.js
  3. +1 −1 src/core/core.js
  4. +1 −1 src/scale/log.js
  5. +8 −0 tests/test-scale-linear.js
  6. +6 −0 tests/test-scale-linear.out
  7. +8 −0 tests/test-scale-log.js
  8. +6 −0 tests/test-scale-log.out
View
4 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.8.3"}; // semver
+(function(){d3 = {version: "1.8.4"}; // semver
if (!Date.now) Date.now = function() {
return +new Date();
};
@@ -2067,7 +2067,7 @@ d3.scale.log = function() {
j = Math.ceil(d[1]),
u = pow(d[0]),
v = pow(d[1]);
- if (n) {
+ if (log === d3_scale_logn) {
ticks.push(pow(i));
for (; i++ < j;) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
} else {
View
106 d3.min.js

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1 +1 @@
-d3 = {version: "1.8.3"}; // semver
+d3 = {version: "1.8.4"}; // semver
View
@@ -31,7 +31,7 @@ d3.scale.log = function() {
j = Math.ceil(d[1]),
u = pow(d[0]),
v = pow(d[1]);
- if (n) {
+ if (log === d3_scale_logn) {
ticks.push(pow(i));
for (; i++ < j;) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
} else {
@@ -70,3 +70,11 @@ console.log(" Date -> ", x.range([new Date(1990, 0, 1), new Date(1991,
console.log(" Number -> ", x.range([new Number(0), new Number(42)]).invert(new Number(21)));
console.log(" ??? -> ", x.range(["#000", "#fff"]).invert("#999")); // can't be coerced
console.log("");
+
+var x = d3.scale.linear();
+console.log("ticks:");
+console.log(" 1 -> ", x.ticks(1).map(x.tickFormat(1)).join(", "));
+console.log(" 2 -> ", x.ticks(2).map(x.tickFormat(2)).join(", "));
+console.log(" 5 -> ", x.ticks(5).map(x.tickFormat(5)).join(", "));
+console.log(" 10 -> ", x.ticks(10).map(x.tickFormat(10)).join(", "));
+console.log("");
@@ -50,3 +50,9 @@ range coercion, invert:
Number -> 0.5
??? -> NaN
+ticks:
+ 1 -> 0, 1
+ 2 -> 0.0, 0.5, 1.0
+ 5 -> 0.0, 0.2, 0.4, 0.6, 0.8, 1.0
+ 10 -> 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
+
View
@@ -67,3 +67,11 @@ console.log(" 1 -> ", x(1));
console.log(" 5 -> ", x(5));
console.log(" 10 -> ", x(10));
console.log("");
+
+var x = d3.scale.log(), f = x.tickFormat();
+console.log("ticks:");
+console.log(" [.1, 10] -> ", x.ticks().map(f).join(", "));
+console.log(" [.1, 100] -> ", x.domain([.1, 100]).ticks().map(f).join(", "));
+console.log(" [1, 100] -> ", x.domain([1, 100]).ticks().map(f).join(", "));
+console.log(" [-100, -1] -> ", x.domain([-100, -1]).ticks().map(f).join(", "));
+console.log("");
View
@@ -49,3 +49,9 @@ domain([.1, 10]).range(["red", "blue"]).interpolate(hsl):
5 -> #009aff
10 -> #0000ff
+ticks:
+ [.1, 10] -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 1e+1
+ [.1, 100] -> 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1e+1, 2e+1, 3e+1, 4e+1, 5e+1, 6e+1, 7e+1, 8e+1, 9e+1, 1e+2
+ [1, 100] -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 1e+1, 2e+1, 3e+1, 4e+1, 5e+1, 6e+1, 7e+1, 8e+1, 9e+1, 1e+2
+ [-100, -1] -> -1e+2, -9e+1, -8e+1, -7e+1, -6e+1, -5e+1, -4e+1, -3e+1, -2e+1, -1e+1, -9, -8, -7, -6, -5, -4, -3, -2, -1
+

0 comments on commit 29efd2a

Please sign in to comment.