UNPKG

1.77 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Constant = void 0;
4const util_1 = require("@antv/util");
5const d3_ticks_1 = require("../tick-methods/d3-ticks");
6const base_1 = require("./base");
7class Constant extends base_1.Base {
8 /**
9 * 返回需要覆盖的默认选项
10 * @returns 需要覆盖的默认选项
11 */
12 getDefaultOptions() {
13 return {
14 range: [0],
15 domain: [0, 1],
16 unknown: undefined,
17 tickCount: 5,
18 tickMethod: d3_ticks_1.d3Ticks,
19 };
20 }
21 /**
22 * 输入和输出满足:y = b,其中 b 是一个常量,是 options.range 的第一个元素
23 * @param _ 输入值
24 * @returns 输出值(常量)
25 */
26 // eslint-disable-next-line @typescript-eslint/no-unused-vars
27 map(_) {
28 const [v] = this.options.range;
29 return v !== undefined ? v : this.options.unknown;
30 }
31 /**
32 * 如果 x 是该比例尺的常量(x === b),返回输入值的范围(即定义域),否者返回 []
33 * @param x 输出值 (常量)
34 * @returns 定义域
35 */
36 invert(x) {
37 const [v] = this.options.range;
38 return x === v && v !== undefined ? this.options.domain : [];
39 }
40 getTicks() {
41 const { tickMethod, domain, tickCount } = this.options;
42 const [a, b] = domain;
43 if (!(0, util_1.isNumber)(a) || !(0, util_1.isNumber)(b))
44 return [];
45 return tickMethod(a, b, tickCount);
46 }
47 /**
48 * 克隆 Constant Scale
49 * @returns 拥有相同选项且独立的 Constant Scale
50 */
51 clone() {
52 return new Constant(this.options);
53 }
54}
55exports.Constant = Constant;
56//# sourceMappingURL=constant.js.map
\No newline at end of file