UNPKG

1.87 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Quantile = void 0;
4const threshold_1 = require("./threshold");
5const wilkinson_extended_1 = require("../tick-methods/wilkinson-extended");
6const create_quartile_1 = require("../utils/create-quartile");
7/**
8 * 类似 Threshold 比例尺,区别在于分位数比例尺 (Quantile) 将一个离散的输入域映射到一个离散的输出域
9 * 输入域被指定为一组离散的样本值,输出域中的值的数量决定了分位数的数量。
10 */
11class Quantile extends threshold_1.Threshold {
12 getDefaultOptions() {
13 return {
14 domain: [],
15 range: [],
16 tickCount: 5,
17 unknown: undefined,
18 tickMethod: wilkinson_extended_1.wilkinsonExtended,
19 };
20 }
21 constructor(options) {
22 super(options);
23 }
24 rescale() {
25 const { domain, range } = this.options;
26 this.n = range.length - 1;
27 this.thresholds = (0, create_quartile_1.createQuartile)(domain, this.n + 1, false);
28 }
29 /**
30 * 如果是在第一段后或者最后一段就把两端的值添加上
31 */
32 invert(y) {
33 const [a, b] = super.invert(y);
34 const { domain } = this.options;
35 const dMin = domain[0];
36 const dMax = domain[domain.length - 1];
37 return a === undefined && b === undefined ? [a, b] : [a || dMin, b || dMax];
38 }
39 getThresholds() {
40 return this.thresholds;
41 }
42 clone() {
43 return new Quantile(this.options);
44 }
45 getTicks() {
46 const { tickCount, domain, tickMethod } = this.options;
47 const lastIndex = domain.length - 1;
48 const min = domain[0];
49 const max = domain[lastIndex];
50 return tickMethod(min, max, tickCount);
51 }
52}
53exports.Quantile = Quantile;
54//# sourceMappingURL=quantile.js.map
\No newline at end of file