UNPKG

1.69 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Identity = void 0;
4const util_1 = require("@antv/util");
5const base_1 = require("./base");
6const wilkinson_extended_1 = require("../tick-methods/wilkinson-extended");
7const utils_1 = require("../utils");
8class Identity extends base_1.Base {
9 /**
10 * 返回需要覆盖的默认选项
11 * @returns 需要覆盖的默认选项
12 */
13 getDefaultOptions() {
14 return {
15 domain: [0, 1],
16 range: [0, 1],
17 tickCount: 5,
18 unknown: undefined,
19 tickMethod: wilkinson_extended_1.wilkinsonExtended,
20 };
21 }
22 /**
23 * 输入和输出满足:y = x
24 * @param x 输入值
25 * @returns 输出值
26 */
27 map(x) {
28 return (0, utils_1.isValid)(x) ? x : this.options.unknown;
29 }
30 /**
31 * map 的逆运算:x = y,在这里和 map 是相同方法
32 * @param x 输出值
33 * @returns 输入值
34 */
35 invert(x) {
36 return this.map(x);
37 }
38 /**
39 * 克隆 Identity Scale
40 * @returns 拥有相同选项且独立的 Identity Scale
41 */
42 clone() {
43 return new Identity(this.options);
44 }
45 /**
46 * 根据比例尺的配置去生成 ticks,该 ticks 主要用于生成坐标轴
47 * @returns 返回一个 ticks 的数组
48 */
49 getTicks() {
50 const { domain, tickCount, tickMethod } = this.options;
51 const [min, max] = domain;
52 if (!(0, util_1.isNumber)(min) || !(0, util_1.isNumber)(max))
53 return [];
54 return tickMethod(min, max, tickCount);
55 }
56}
57exports.Identity = Identity;
58//# sourceMappingURL=identity.js.map
\No newline at end of file