1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Threshold = void 0;
|
4 | const base_1 = require("./base");
|
5 | const utils_1 = require("../utils");
|
6 |
|
7 |
|
8 |
|
9 | class Threshold extends base_1.Base {
|
10 | constructor(options) {
|
11 | super(options);
|
12 | }
|
13 | getDefaultOptions() {
|
14 | return {
|
15 | domain: [0.5],
|
16 | range: [0, 1],
|
17 | };
|
18 | }
|
19 | |
20 |
|
21 |
|
22 | map(x) {
|
23 | if (!utils_1.isValid(x))
|
24 | return this.options.unknown;
|
25 | const index = utils_1.bisect(this.getDomain(), x, 0, this.n);
|
26 | return this.options.range[index];
|
27 | }
|
28 | |
29 |
|
30 |
|
31 | invert(y) {
|
32 | const { range } = this.options;
|
33 | const index = range.indexOf(y);
|
34 | const domain = this.getDomain();
|
35 | return [domain[index - 1], domain[index]];
|
36 | }
|
37 | clone() {
|
38 | return new Threshold(this.options);
|
39 | }
|
40 | rescale() {
|
41 | const { domain, range } = this.options;
|
42 | this.n = Math.min(domain.length, range.length - 1);
|
43 | }
|
44 | getDomain() {
|
45 | return this.options.domain;
|
46 | }
|
47 | }
|
48 | exports.Threshold = Threshold;
|
49 |
|
\ | No newline at end of file |