UNPKG

1.78 kBTypeScriptView Raw
1import { Base } from './base';
2import { ContinuousOptions, Domain, Range, NiceMethod, TickMethodOptions } from '../types';
3/** 柯里化后的函数的类型,对输入的值进行处理 */
4export declare type Transform = (x: any) => any;
5/** 柯里化后的函数的工厂函数类型 */
6export declare type CreateTransform = (...args: any[]) => Transform;
7/**
8 * Continuous 比例尺 的输入 x 和输出 y 满足:y = a * f(x) + b
9 * 通过函数柯里化和复合函数可以在映射过程中去掉分支,提高性能。
10 * 参考:https://github.com/d3/d3-scale/blob/master/src/continuous.js
11 */
12export declare abstract class Continuous<O extends ContinuousOptions> extends Base<O> {
13 /** 实际上将 x 映射为 y 的函数 */
14 protected output: Transform;
15 /** 实际上将 y 映射为 x 的函数 */
16 protected input: Transform;
17 /**
18 * 根据比例尺 和 options 选择对应的 transform 和 untransform 函数
19 * y = a * f(x) + b
20 * x = a * f'(y) + b
21 * @returns [f(x), f'(y)]
22 */
23 protected abstract chooseTransforms(): Transform[];
24 protected getDefaultOptions(): O;
25 /**
26 * y = interpolate(normalize(clamp(transform(x))))
27 */
28 map(x: Domain<O>): any;
29 /**
30 * x = transform(clamp(interpolate(normalize(y))))
31 */
32 invert(x: Range<O>): any;
33 protected nice(): void;
34 getTicks(): (number | Date)[];
35 protected getTickMethodOptions(): TickMethodOptions;
36 protected chooseNice(): NiceMethod<number | Date>;
37 protected rescale(): void;
38 protected chooseClamp(transform: Transform): (x: number) => number;
39 protected composeOutput(transform: Transform, clamp: Transform): void;
40 protected composeInput(transform: Transform, untransform: Transform, clamp: Transform): void;
41}