Skip to content

Commit

Permalink
Fix #9 - nice twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 16, 2015
1 parent fa5db52 commit e1c6e75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ export function linearish(scale) {
scale.nice = function(count) {
var d = domain(),
i = d.length - 1,
k = tickStep(d[0], d[i], count == null ? 10 : count);
if (k) {
d[0] = Math.floor(d[0] / k) * k;
d[i] = Math.ceil(d[i] / k) * k;
n = count == null ? 10 : count,
start = d[0],
stop = d[i],
step = tickStep(start, stop, n);

if (step) {
step = tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n);
d[0] = Math.floor(start / step) * step;
d[i] = Math.ceil(stop / step) * step;
domain(d);
}

return scale;
};

Expand Down
1 change: 1 addition & 0 deletions test/linear-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ tape("linear.nice(count) extends the domain to match the desired ticks", functio
test.deepEqual(scale.linear().domain([0, -96]).nice(10).domain(), [0, -100]);
test.deepEqual(scale.linear().domain([-.96, 0]).nice(10).domain(), [-1, 0]);
test.deepEqual(scale.linear().domain([-96, 0]).nice(10).domain(), [-100, 0]);
test.deepEqual(scale.linear().domain([-0.1, 51.1]).nice(8).domain(), [-10, 60]);
test.end();
});

Expand Down

0 comments on commit e1c6e75

Please sign in to comment.