source: Dev/trunk/d3/src/scale/quantile.js @ 76

Last change on this file since 76 was 76, checked in by fpvanagthoven, 14 years ago

d3

File size: 803 bytes
Line 
1d3.scale.quantile = function() {
2  var domain = [],
3      range = [],
4      thresholds = [];
5
6  function rescale() {
7    var k = 0,
8        n = domain.length,
9        q = range.length;
10    thresholds.length = Math.max(0, q - 1);
11    while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
12  }
13
14  function scale(x) {
15    if (isNaN(x = +x)) return NaN;
16    return range[d3.bisect(thresholds, x)];
17  }
18
19  scale.domain = function(x) {
20    if (!arguments.length) return domain;
21    domain = x.filter(function(d) { return !isNaN(d); }).sort(d3.ascending);
22    rescale();
23    return scale;
24  };
25
26  scale.range = function(x) {
27    if (!arguments.length) return range;
28    range = x;
29    rescale();
30    return scale;
31  };
32
33  scale.quantiles = function() {
34    return thresholds;
35  };
36
37  return scale;
38};
Note: See TracBrowser for help on using the repository browser.