package.src.threshold.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of d3-scale Show documentation
Show all versions of d3-scale Show documentation
Encodings that map abstract data to visual representation.
The newest version!
import {bisect} from "d3-array";
import {initRange} from "./init.js";
export default function threshold() {
var domain = [0.5],
range = [0, 1],
unknown,
n = 1;
function scale(x) {
return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
}
scale.domain = function(_) {
return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
};
scale.range = function(_) {
return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
};
scale.invertExtent = function(y) {
var i = range.indexOf(y);
return [domain[i - 1], domain[i]];
};
scale.unknown = function(_) {
return arguments.length ? (unknown = _, scale) : unknown;
};
scale.copy = function() {
return threshold()
.domain(domain)
.range(range)
.unknown(unknown);
};
return initRange.apply(scale, arguments);
}