MCPcopy Create free account
hub / github.com/breck7/scroll / quantile

Function quantile

external/.d3.js:15483–15536  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15481}
15482
15483function quantile() {
15484 var domain = [],
15485 range = [],
15486 thresholds = [],
15487 unknown;
15488
15489 function rescale() {
15490 var i = 0, n = Math.max(1, range.length);
15491 thresholds = new Array(n - 1);
15492 while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
15493 return scale;
15494 }
15495
15496 function scale(x) {
15497 return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];
15498 }
15499
15500 scale.invertExtent = function(y) {
15501 var i = range.indexOf(y);
15502 return i < 0 ? [NaN, NaN] : [
15503 i > 0 ? thresholds[i - 1] : domain[0],
15504 i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
15505 ];
15506 };
15507
15508 scale.domain = function(_) {
15509 if (!arguments.length) return domain.slice();
15510 domain = [];
15511 for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
15512 domain.sort(ascending$3);
15513 return rescale();
15514 };
15515
15516 scale.range = function(_) {
15517 return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
15518 };
15519
15520 scale.unknown = function(_) {
15521 return arguments.length ? (unknown = _, scale) : unknown;
15522 };
15523
15524 scale.quantiles = function() {
15525 return thresholds.slice();
15526 };
15527
15528 scale.copy = function() {
15529 return quantile()
15530 .domain(domain)
15531 .range(range)
15532 .unknown(unknown);
15533 };
15534
15535 return initRange.apply(scale, arguments);
15536}
15537
15538function quantize() {
15539 var x0 = 0,

Callers

nothing calls this directly

Calls 5

rescaleFunction · 0.85
indexOfMethod · 0.80
sliceMethod · 0.80
sortMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected