Skip to content

Commit

Permalink
Fix a bug in d3.scale.log ticks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 30, 2011
1 parent b49c878 commit 29efd2a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 57 deletions.
4 changes: 2 additions & 2 deletions d3.js
Original file line number Diff line number Diff line change
@@ -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();
};
Expand Down Expand Up @@ -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 {
Expand Down
106 changes: 53 additions & 53 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3 = {version: "1.8.3"}; // semver
d3 = {version: "1.8.4"}; // semver
2 changes: 1 addition & 1 deletion src/scale/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions tests/test-scale-linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
6 changes: 6 additions & 0 deletions tests/test-scale-linear.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions tests/test-scale-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
6 changes: 6 additions & 0 deletions tests/test-scale-log.out
Original file line number Diff line number Diff line change
Expand Up @@ -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.