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

Function quantize

external/.d3.js:15538–15589  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15536}
15537
15538function quantize() {
15539 var x0 = 0,
15540 x1 = 1,
15541 n = 1,
15542 domain = [0.5],
15543 range = [0, 1],
15544 unknown;
15545
15546 function scale(x) {
15547 return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
15548 }
15549
15550 function rescale() {
15551 var i = -1;
15552 domain = new Array(n);
15553 while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
15554 return scale;
15555 }
15556
15557 scale.domain = function(_) {
15558 return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
15559 };
15560
15561 scale.range = function(_) {
15562 return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
15563 };
15564
15565 scale.invertExtent = function(y) {
15566 var i = range.indexOf(y);
15567 return i < 0 ? [NaN, NaN]
15568 : i < 1 ? [x0, domain[0]]
15569 : i >= n ? [domain[n - 1], x1]
15570 : [domain[i - 1], domain[i]];
15571 };
15572
15573 scale.unknown = function(_) {
15574 return arguments.length ? (unknown = _, scale) : scale;
15575 };
15576
15577 scale.thresholds = function() {
15578 return domain.slice();
15579 };
15580
15581 scale.copy = function() {
15582 return quantize()
15583 .domain([x0, x1])
15584 .range(range)
15585 .unknown(unknown);
15586 };
15587
15588 return initRange.apply(linearish(scale), arguments);
15589}
15590
15591function threshold() {
15592 var domain = [0.5],

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected