UNPKG

1.96 kBTypeScriptView Raw
1import { ScaleConfig, Tick } from './types';
2export default abstract class Scale {
3 /**
4 * 度量的类型
5 */
6 type: string;
7 /**
8 * 是否分类类型的度量
9 */
10 isCategory?: boolean;
11 /**
12 * 是否线性度量,有linear, time 度量
13 */
14 isLinear?: boolean;
15 /**
16 * 是否连续类型的度量,linear,time,log, pow, quantile, quantize 都支持
17 */
18 isContinuous?: boolean;
19 /**
20 * 是否是常量的度量,传入和传出一致
21 */
22 isIdentity: boolean;
23 field?: ScaleConfig['field'];
24 alias?: ScaleConfig['alias'];
25 values: ScaleConfig['values'];
26 min?: ScaleConfig['min'];
27 max?: ScaleConfig['max'];
28 minLimit?: ScaleConfig['minLimit'];
29 maxLimit?: ScaleConfig['maxLimit'];
30 range: ScaleConfig['range'];
31 ticks: ScaleConfig['ticks'];
32 tickCount: ScaleConfig['tickCount'];
33 tickInterval: ScaleConfig['tickInterval'];
34 formatter?: ScaleConfig['formatter'];
35 tickMethod?: ScaleConfig['tickMethod'];
36 protected __cfg__: ScaleConfig;
37 constructor(cfg: ScaleConfig);
38 translate(v: any): any;
39 /** 将定义域转换为值域 */
40 abstract scale(value: any): number;
41 /** 将值域转换为定义域 */
42 abstract invert(scaled: number): any;
43 /** 重新初始化 */
44 change(cfg: ScaleConfig): void;
45 clone(): Scale;
46 /** 获取坐标轴需要的ticks */
47 getTicks(): Tick[];
48 /** 获取Tick的格式化结果 */
49 getText(value: any, key?: number): string;
50 protected getConfig(key: any): any;
51 protected init(): void;
52 protected initCfg(): void;
53 protected setDomain(): void;
54 protected calculateTicks(): any[];
55 protected rangeMin(): number;
56 protected rangeMax(): number;
57 /** 定义域转 0~1 */
58 protected calcPercent(value: any, min: number, max: number): number;
59 /** 0~1转定义域 */
60 protected calcValue(percent: number, min: number, max: number): number;
61}