1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Quantize = void 0;
|
4 | const threshold_1 = require("./threshold");
|
5 | const wilkinson_extended_1 = require("../tick-methods/wilkinson-extended");
|
6 | const utils_1 = require("../utils");
|
7 |
|
8 |
|
9 |
|
10 | class Quantize extends threshold_1.Threshold {
|
11 | getDefaultOptions() {
|
12 | return {
|
13 | domain: [0, 1],
|
14 | range: [0.5],
|
15 | nice: false,
|
16 | tickCount: 5,
|
17 | tickMethod: wilkinson_extended_1.wilkinsonExtended,
|
18 | };
|
19 | }
|
20 | constructor(options) {
|
21 | super(options);
|
22 | }
|
23 | nice() {
|
24 | const { nice } = this.options;
|
25 | if (nice) {
|
26 | const [min, max, tickCount] = this.getTickMethodOptions();
|
27 | this.options.domain = (0, utils_1.d3LinearNice)(min, max, tickCount);
|
28 | }
|
29 | }
|
30 | getTicks() {
|
31 | const { tickMethod } = this.options;
|
32 | const [min, max, tickCount] = this.getTickMethodOptions();
|
33 | return tickMethod(min, max, tickCount);
|
34 | }
|
35 | getTickMethodOptions() {
|
36 | const { domain, tickCount } = this.options;
|
37 | const min = domain[0];
|
38 | const max = domain[domain.length - 1];
|
39 | return [min, max, tickCount];
|
40 | }
|
41 | rescale() {
|
42 | this.nice();
|
43 | const { range, domain } = this.options;
|
44 | const [x0, x1] = domain;
|
45 | this.n = range.length - 1;
|
46 | this.thresholds = new Array(this.n);
|
47 | for (let i = 0; i < this.n; i += 1) {
|
48 | this.thresholds[i] = ((i + 1) * x1 - (i - this.n) * x0) / (this.n + 1);
|
49 | }
|
50 | }
|
51 | |
52 |
|
53 |
|
54 | invert(y) {
|
55 | const [a, b] = super.invert(y);
|
56 | const [x0, x1] = this.options.domain;
|
57 | return a === undefined && b === undefined ? [a, b] : [a || x0, b || x1];
|
58 | }
|
59 | getThresholds() {
|
60 | return this.thresholds;
|
61 | }
|
62 | clone() {
|
63 | return new Quantize(this.options);
|
64 | }
|
65 | }
|
66 | exports.Quantize = Quantize;
|
67 |
|
\ | No newline at end of file |