|
1 d3.scale.pow = function() { |
|
2 return d3_scale_pow(d3.scale.linear(), 1); |
|
3 }; |
|
4 |
|
5 function d3_scale_pow(linear, exponent) { |
|
6 var powp = d3_scale_powPow(exponent), |
|
7 powb = d3_scale_powPow(1 / exponent); |
|
8 |
|
9 function scale(x) { |
|
10 return linear(powp(x)); |
|
11 } |
|
12 |
|
13 scale.invert = function(x) { |
|
14 return powb(linear.invert(x)); |
|
15 }; |
|
16 |
|
17 scale.domain = function(x) { |
|
18 if (!arguments.length) return linear.domain().map(powb); |
|
19 linear.domain(x.map(powp)); |
|
20 return scale; |
|
21 }; |
|
22 |
|
23 scale.ticks = function(m) { |
|
24 return d3_scale_linearTicks(scale.domain(), m); |
|
25 }; |
|
26 |
|
27 scale.tickFormat = function(m) { |
|
28 return d3_scale_linearTickFormat(scale.domain(), m); |
|
29 }; |
|
30 |
|
31 scale.nice = function() { |
|
32 return scale.domain(d3_scale_nice(scale.domain(), d3_scale_linearNice)); |
|
33 }; |
|
34 |
|
35 scale.exponent = function(x) { |
|
36 if (!arguments.length) return exponent; |
|
37 var domain = scale.domain(); |
|
38 powp = d3_scale_powPow(exponent = x); |
|
39 powb = d3_scale_powPow(1 / exponent); |
|
40 return scale.domain(domain); |
|
41 }; |
|
42 |
|
43 scale.copy = function() { |
|
44 return d3_scale_pow(linear.copy(), exponent); |
|
45 }; |
|
46 |
|
47 return d3_scale_linearRebind(scale, linear); |
|
48 }; |
|
49 |
|
50 function d3_scale_powPow(e) { |
|
51 return function(x) { |
|
52 return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e); |
|
53 }; |
|
54 } |