1
d3.scale.log = function() {
2
return d3_scale_log(d3.scale.linear(), d3_scale_logp);
5
function d3_scale_log(linear, log) {
12
scale.invert = function(x) {
13
return pow(linear.invert(x));
16
scale.domain = function(x) {
17
if (!arguments.length) return linear.domain().map(pow);
18
log = x[0] < 0 ? d3_scale_logn : d3_scale_logp;
20
linear.domain(x.map(log));
24
scale.nice = function() {
25
linear.domain(d3_scale_nice(linear.domain(), d3_scale_niceDefault));
29
scale.ticks = function() {
30
var extent = d3_scaleExtent(linear.domain()),
32
if (extent.every(isFinite)) {
33
var i = Math.floor(extent[0]),
34
j = Math.ceil(extent[1]),
37
if (log === d3_scale_logn) {
39
for (; i++ < j;) for (var k = 9; k > 0; k--) ticks.push(pow(i) * k);
41
for (; i < j; i++) for (var k = 1; k < 10; k++) ticks.push(pow(i) * k);
44
for (i = 0; ticks[i] < u; i++) {} // strip small values
45
for (j = ticks.length; ticks[j - 1] > v; j--) {} // strip big values
46
ticks = ticks.slice(i, j);
51
scale.tickFormat = function(n, format) {
52
if (arguments.length < 2) format = d3_scale_logFormat;
53
if (arguments.length < 1) return format;
54
var k = Math.max(.1, n / scale.ticks().length),
55
f = log === d3_scale_logn ? (e = -1e-12, Math.floor) : (e = 1e-12, Math.ceil),
58
return d / pow(f(log(d) + e)) <= k ? format(d) : "";
62
scale.copy = function() {
63
return d3_scale_log(linear.copy(), log);
66
return d3_scale_linearRebind(scale, linear);
69
var d3_scale_logFormat = d3.format(".0e");
71
function d3_scale_logp(x) {
72
return Math.log(x < 0 ? 0 : x) / Math.LN10;
75
function d3_scale_logn(x) {
76
return -Math.log(x > 0 ? 0 : -x) / Math.LN10;
79
d3_scale_logp.pow = function(x) {
80
return Math.pow(10, x);
83
d3_scale_logn.pow = function(x) {
84
return -Math.pow(10, -x);