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 | getDefaultOptions() {
|
11 | return {
|
12 | domain: [0.5],
|
13 | range: [0, 1],
|
14 | };
|
15 | }
|
16 | constructor(options) {
|
17 | super(options);
|
18 | }
|
19 | |
20 |
|
21 |
|
22 | map(x) {
|
23 | if (!(0, utils_1.isValid)(x))
|
24 | return this.options.unknown;
|
25 | const index = (0, utils_1.bisect)(this.thresholds, 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.thresholds;
|
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 | this.thresholds = domain;
|
44 | }
|
45 | }
|
46 | exports.Threshold = Threshold;
|
47 |
|
\ | No newline at end of file |