Fix "nice" log scales.
Turns out we just needed to test for reversed domains. Fixes #176.
This commit is contained in:
Родитель
e1daa4764c
Коммит
8421fca43d
|
@ -2279,9 +2279,15 @@ d3.scale.log = function() {
|
||||||
scale.clamp = d3.rebind(scale, linear.clamp);
|
scale.clamp = d3.rebind(scale, linear.clamp);
|
||||||
|
|
||||||
scale.nice = function() {
|
scale.nice = function() {
|
||||||
var d = linear.domain().map(pow);
|
var d = linear.domain().map(pow),
|
||||||
linear.domain([log.floor(d[0]), log.ceil(d[1])].map(log));
|
start = d[0],
|
||||||
return scale;
|
end = d[1],
|
||||||
|
reverse = end < start,
|
||||||
|
min = reverse ? end : start,
|
||||||
|
max = reverse ? start : end,
|
||||||
|
domain = [log.floor(min), log.ceil(max)];
|
||||||
|
if (reverse) domain.reverse();
|
||||||
|
return scale.domain(domain);
|
||||||
};
|
};
|
||||||
|
|
||||||
scale.ticks = function() {
|
scale.ticks = function() {
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -25,9 +25,15 @@ d3.scale.log = function() {
|
||||||
scale.clamp = d3.rebind(scale, linear.clamp);
|
scale.clamp = d3.rebind(scale, linear.clamp);
|
||||||
|
|
||||||
scale.nice = function() {
|
scale.nice = function() {
|
||||||
var d = linear.domain().map(pow);
|
var d = linear.domain().map(pow),
|
||||||
linear.domain([log.floor(d[0]), log.ceil(d[1])].map(log));
|
start = d[0],
|
||||||
return scale;
|
end = d[1],
|
||||||
|
reverse = end < start,
|
||||||
|
min = reverse ? end : start,
|
||||||
|
max = reverse ? start : end,
|
||||||
|
domain = [log.floor(min), log.ceil(max)];
|
||||||
|
if (reverse) domain.reverse();
|
||||||
|
return scale.domain(domain);
|
||||||
};
|
};
|
||||||
|
|
||||||
scale.ticks = function() {
|
scale.ticks = function() {
|
||||||
|
|
|
@ -53,13 +53,13 @@ domain([ 1.100, 10.900 ]).nice():
|
||||||
1.000, 100.000
|
1.000, 100.000
|
||||||
|
|
||||||
domain([ 10.900, 1.100 ]).nice():
|
domain([ 10.900, 1.100 ]).nice():
|
||||||
10.000, 10.000
|
100.000, 1.000
|
||||||
|
|
||||||
domain([ 0.700, 11.001 ]).nice():
|
domain([ 0.700, 11.001 ]).nice():
|
||||||
0.100, 100.000
|
0.100, 100.000
|
||||||
|
|
||||||
domain([ 123.100, 6.700 ]).nice():
|
domain([ 123.100, 6.700 ]).nice():
|
||||||
100.000, 10.000
|
1000.000, 1.000
|
||||||
|
|
||||||
domain([ 0.000, 0.490 ]).nice():
|
domain([ 0.000, 0.490 ]).nice():
|
||||||
0.000, 1.000
|
0.000, 1.000
|
||||||
|
|
Загрузка…
Ссылка в новой задаче