equal
deleted
inserted
replaced
|
1 d3.scale.quantile = function() { |
|
2 return d3_scale_quantile([], []); |
|
3 }; |
|
4 |
|
5 function d3_scale_quantile(domain, range) { |
|
6 var thresholds; |
|
7 |
|
8 function rescale() { |
|
9 var k = 0, |
|
10 n = domain.length, |
|
11 q = range.length; |
|
12 thresholds = []; |
|
13 while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q); |
|
14 return scale; |
|
15 } |
|
16 |
|
17 function scale(x) { |
|
18 if (isNaN(x = +x)) return NaN; |
|
19 return range[d3.bisect(thresholds, x)]; |
|
20 } |
|
21 |
|
22 scale.domain = function(x) { |
|
23 if (!arguments.length) return domain; |
|
24 domain = x.filter(function(d) { return !isNaN(d); }).sort(d3.ascending); |
|
25 return rescale(); |
|
26 }; |
|
27 |
|
28 scale.range = function(x) { |
|
29 if (!arguments.length) return range; |
|
30 range = x; |
|
31 return rescale(); |
|
32 }; |
|
33 |
|
34 scale.quantiles = function() { |
|
35 return thresholds; |
|
36 }; |
|
37 |
|
38 scale.copy = function() { |
|
39 return d3_scale_quantile(domain, range); // copy on write! |
|
40 }; |
|
41 |
|
42 return rescale(); |
|
43 }; |