@antv/scale 0.4.1 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scale.min.js +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/scales/band.js +1 -2
- package/esm/scales/band.js.map +1 -1
- package/esm/scales/constant.d.ts +1 -1
- package/esm/scales/continuous.d.ts +3 -3
- package/esm/scales/continuous.js +4 -4
- package/esm/scales/continuous.js.map +1 -1
- package/esm/scales/identity.js +4 -1
- package/esm/scales/identity.js.map +1 -1
- package/esm/scales/linear.js +2 -2
- package/esm/scales/linear.js.map +1 -1
- package/esm/scales/log.d.ts +2 -2
- package/esm/scales/log.js +2 -2
- package/esm/scales/log.js.map +1 -1
- package/esm/scales/ordinal.d.ts +5 -1
- package/esm/scales/ordinal.js +17 -6
- package/esm/scales/ordinal.js.map +1 -1
- package/esm/scales/pow.js +2 -2
- package/esm/scales/pow.js.map +1 -1
- package/esm/scales/sqrt.d.ts +1 -1
- package/esm/scales/sqrt.js +2 -2
- package/esm/scales/sqrt.js.map +1 -1
- package/esm/scales/time.d.ts +3 -3
- package/esm/scales/time.js +2 -2
- package/esm/scales/time.js.map +1 -1
- package/esm/tick-methods/d3-log.d.ts +1 -1
- package/esm/tick-methods/r-pretty.js +12 -18
- package/esm/tick-methods/r-pretty.js.map +1 -1
- package/esm/tick-methods/wilkinson-extended.js +27 -29
- package/esm/tick-methods/wilkinson-extended.js.map +1 -1
- package/esm/types.d.ts +136 -35
- package/esm/types.js +0 -1
- package/esm/utils/color.d.ts +1 -0
- package/esm/utils/color.js +41 -0
- package/esm/utils/color.js.map +1 -0
- package/esm/utils/index.d.ts +1 -1
- package/esm/utils/index.js +1 -1
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/interpolate.d.ts +11 -3
- package/esm/utils/interpolate.js +38 -3
- package/esm/utils/interpolate.js.map +1 -1
- package/esm/utils/pretty-number.d.ts +1 -0
- package/esm/utils/pretty-number.js +5 -0
- package/esm/utils/pretty-number.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/scales/band.js +1 -2
- package/lib/scales/band.js.map +1 -1
- package/lib/scales/constant.d.ts +1 -1
- package/lib/scales/continuous.d.ts +3 -3
- package/lib/scales/continuous.js +3 -3
- package/lib/scales/continuous.js.map +1 -1
- package/lib/scales/identity.js +4 -1
- package/lib/scales/identity.js.map +1 -1
- package/lib/scales/linear.js +1 -1
- package/lib/scales/linear.js.map +1 -1
- package/lib/scales/log.d.ts +2 -2
- package/lib/scales/log.js +1 -1
- package/lib/scales/log.js.map +1 -1
- package/lib/scales/ordinal.d.ts +5 -1
- package/lib/scales/ordinal.js +17 -6
- package/lib/scales/ordinal.js.map +1 -1
- package/lib/scales/pow.js +1 -1
- package/lib/scales/pow.js.map +1 -1
- package/lib/scales/sqrt.d.ts +1 -1
- package/lib/scales/sqrt.js +1 -1
- package/lib/scales/sqrt.js.map +1 -1
- package/lib/scales/time.d.ts +3 -3
- package/lib/scales/time.js +1 -1
- package/lib/scales/time.js.map +1 -1
- package/lib/tick-methods/d3-log.d.ts +1 -1
- package/lib/tick-methods/d3-log.js +1 -2
- package/lib/tick-methods/d3-log.js.map +1 -1
- package/lib/tick-methods/d3-ticks.js +1 -2
- package/lib/tick-methods/d3-ticks.js.map +1 -1
- package/lib/tick-methods/d3-time.js +1 -2
- package/lib/tick-methods/d3-time.js.map +1 -1
- package/lib/tick-methods/r-pretty.js +12 -19
- package/lib/tick-methods/r-pretty.js.map +1 -1
- package/lib/tick-methods/wilkinson-extended.js +27 -30
- package/lib/tick-methods/wilkinson-extended.js.map +1 -1
- package/lib/types.d.ts +136 -35
- package/lib/utils/color.d.ts +1 -0
- package/lib/utils/color.js +48 -0
- package/lib/utils/color.js.map +1 -0
- package/lib/utils/d3-linear-nice.js +1 -2
- package/lib/utils/d3-linear-nice.js.map +1 -1
- package/lib/utils/d3-log-nice.js +1 -2
- package/lib/utils/d3-log-nice.js.map +1 -1
- package/lib/utils/d3-time-nice.js +1 -2
- package/lib/utils/d3-time-nice.js.map +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +5 -4
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/interpolate.d.ts +11 -3
- package/lib/utils/interpolate.js +39 -6
- package/lib/utils/interpolate.js.map +1 -1
- package/lib/utils/log.js +2 -4
- package/lib/utils/log.js.map +1 -1
- package/lib/utils/pretty-number.d.ts +1 -0
- package/lib/utils/pretty-number.js +9 -0
- package/lib/utils/pretty-number.js.map +1 -0
- package/package.json +6 -3
- package/src/index.ts +4 -1
- package/src/scales/band.ts +1 -2
- package/src/scales/continuous.ts +6 -6
- package/src/scales/identity.ts +3 -1
- package/src/scales/linear.ts +2 -2
- package/src/scales/log.ts +4 -4
- package/src/scales/ordinal.ts +28 -8
- package/src/scales/pow.ts +2 -2
- package/src/scales/sqrt.ts +2 -2
- package/src/scales/time.ts +4 -4
- package/src/tick-methods/d3-log.ts +1 -1
- package/src/tick-methods/r-pretty.ts +12 -19
- package/src/tick-methods/wilkinson-extended.ts +30 -34
- package/src/types.ts +154 -51
- package/src/utils/color.ts +36 -0
- package/src/utils/index.ts +6 -1
- package/src/utils/interpolate.ts +37 -3
- package/src/utils/pretty-number.ts +4 -0
- package/esm/utils/precision-add.d.ts +0 -8
- package/esm/utils/precision-add.js +0 -20
- package/esm/utils/precision-add.js.map +0 -1
- package/esm/utils/sequence.d.ts +0 -9
- package/esm/utils/sequence.js +0 -21
- package/esm/utils/sequence.js.map +0 -1
- package/lib/utils/precision-add.d.ts +0 -8
- package/lib/utils/precision-add.js +0 -24
- package/lib/utils/precision-add.js.map +0 -1
- package/lib/utils/sequence.d.ts +0 -9
- package/lib/utils/sequence.js +0 -25
- package/lib/utils/sequence.js.map +0 -1
- package/src/utils/precision-add.ts +0 -20
- package/src/utils/sequence.ts +0 -23
package/src/types.ts
CHANGED
|
@@ -5,34 +5,25 @@ export type TickMethod<T = number> = (min: T, max: T, n?: number, ...rest: any[]
|
|
|
5
5
|
export type NiceMethod<T = number> = TickMethod<T>;
|
|
6
6
|
|
|
7
7
|
/** 插值器工厂 */
|
|
8
|
-
export type Interpolate = (a:
|
|
8
|
+
export type Interpolate<T = number> = (a: T, b: T) => (t: number) => T;
|
|
9
|
+
|
|
10
|
+
/** 所有支持的插值器工厂 */
|
|
11
|
+
export type Interpolates = Interpolate<number> | Interpolate<string> | Interpolate<number | string>;
|
|
9
12
|
|
|
10
13
|
/** 比较器 */
|
|
11
|
-
export type Comparator = (a:
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export type BaseOptions<D = any, R = D> = {
|
|
14
|
+
export type Comparator = (a: any, b: any) => number;
|
|
15
|
+
|
|
16
|
+
/** tickMethod 和 nice 需要使用的参数 */
|
|
17
|
+
export type TickMethodOptions<T = number | Date> = [T, T, number, number?, boolean?];
|
|
18
|
+
|
|
19
|
+
/** 通用的配置 */
|
|
20
|
+
export type BaseOptions = {
|
|
19
21
|
/** 当需要映射的值不合法的时候,返回的值 */
|
|
20
22
|
unknown?: any;
|
|
21
23
|
/** 值域,默认为 [0, 1] */
|
|
22
|
-
range?:
|
|
24
|
+
range?: any[];
|
|
23
25
|
/** 定义域,默认为 [0, 1] */
|
|
24
|
-
domain?:
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 支持 getTicks 的比例尺的选项
|
|
29
|
-
* T:tickMethod 配置项的类型
|
|
30
|
-
*/
|
|
31
|
-
export type TickOptions<T = number> = {
|
|
32
|
-
/** tick 个数,默认值为 5 */
|
|
33
|
-
tickCount?: number;
|
|
34
|
-
/** 计算 ticks 的算法 */
|
|
35
|
-
tickMethod?: TickMethod<T>;
|
|
26
|
+
domain?: any[];
|
|
36
27
|
};
|
|
37
28
|
|
|
38
29
|
/** 获得比例尺选项中定义域元素的类型 */
|
|
@@ -45,44 +36,114 @@ export type Range<O extends BaseOptions> = O['range'][number];
|
|
|
45
36
|
export type Unknown<O extends BaseOptions> = O['unknown'];
|
|
46
37
|
|
|
47
38
|
/** Identity 比例尺的选项 */
|
|
48
|
-
|
|
39
|
+
|
|
40
|
+
/** Identity 比例尺的选项 */
|
|
41
|
+
export type IdentityOptions = {
|
|
42
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
43
|
+
unknown?: any;
|
|
44
|
+
/** 值域,默认为 [0, 1] */
|
|
45
|
+
range?: any[];
|
|
46
|
+
/** 定义域,默认为 [0, 1] */
|
|
47
|
+
domain?: any[];
|
|
48
|
+
/** tick 个数,默认值为 5 */
|
|
49
|
+
tickCount?: number;
|
|
50
|
+
/** 计算 ticks 的算法 */
|
|
51
|
+
tickMethod?: TickMethod<number>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Constant 比例尺的选项 */
|
|
55
|
+
export type ConstantOptions = {
|
|
56
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
57
|
+
unknown?: any;
|
|
58
|
+
/** 值域,默认为 [0, 1] */
|
|
59
|
+
range?: any[];
|
|
60
|
+
/** 定义域,默认为 [0, 1] */
|
|
61
|
+
domain?: any[];
|
|
62
|
+
/** tick 个数,默认值为 5 */
|
|
63
|
+
tickCount?: number;
|
|
64
|
+
/** 计算 ticks 的算法 */
|
|
65
|
+
tickMethod?: TickMethod<number>;
|
|
66
|
+
};
|
|
49
67
|
|
|
50
68
|
/** Constant 比例尺的选项 */
|
|
51
|
-
export type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
export type ContinuousOptions = {
|
|
70
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
71
|
+
unknown?: any;
|
|
72
|
+
/** 值域,默认为 [0, 1] */
|
|
73
|
+
range?: (number | string)[];
|
|
74
|
+
/** 定义域,默认为 [0, 1] */
|
|
75
|
+
domain?: (number | Date)[];
|
|
76
|
+
/** tick 个数,默认值为 5 */
|
|
77
|
+
tickCount?: number;
|
|
78
|
+
/** 计算 ticks 的算法 */
|
|
79
|
+
tickMethod?: TickMethod<number | Date>;
|
|
80
|
+
/** 是否需要对定义域的范围进行优化 */
|
|
81
|
+
nice?: boolean;
|
|
82
|
+
/** 是否需要限制输入的范围在值域内 */
|
|
83
|
+
clamp?: boolean;
|
|
84
|
+
/** 是否需要对输出进行四舍五入 */
|
|
85
|
+
round?: boolean;
|
|
86
|
+
/** 插值器的工厂函数,返回一个对归一化后的输入在值域指定范围内插值的函数 */
|
|
87
|
+
interpolate?: Interpolates;
|
|
88
|
+
};
|
|
65
89
|
|
|
66
90
|
/** Linear 比例尺的选项 */
|
|
67
|
-
export type LinearOptions =
|
|
91
|
+
export type LinearOptions = {
|
|
92
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
93
|
+
unknown?: any;
|
|
94
|
+
/** 值域,默认为 [0, 1] */
|
|
95
|
+
range?: (number | string)[];
|
|
96
|
+
/** 定义域,默认为 [0, 1] */
|
|
97
|
+
domain?: number[];
|
|
98
|
+
/** tick 个数,默认值为 5 */
|
|
99
|
+
tickCount?: number;
|
|
100
|
+
/** 计算 ticks 的算法 */
|
|
101
|
+
tickMethod?: TickMethod<number>;
|
|
102
|
+
/** 是否需要对定义域的范围进行优化 */
|
|
103
|
+
nice?: boolean;
|
|
104
|
+
/** 是否需要限制输入的范围在值域内 */
|
|
105
|
+
clamp?: boolean;
|
|
106
|
+
/** 是否需要对输出进行四舍五入 */
|
|
107
|
+
round?: boolean;
|
|
108
|
+
/** 插值器的工厂函数,返回一个对归一化后的输入在值域指定范围内插值的函数 */
|
|
109
|
+
interpolate?: Interpolates;
|
|
110
|
+
};
|
|
68
111
|
|
|
69
112
|
/** Pow 比例尺的选项 */
|
|
70
|
-
export type PowOptions =
|
|
113
|
+
export type PowOptions = LinearOptions & {
|
|
71
114
|
/** 指数 */
|
|
72
115
|
exponent?: number;
|
|
73
116
|
};
|
|
74
117
|
|
|
75
118
|
/** Sqrt 比例尺的选项 */
|
|
76
|
-
export type SqrtOptions =
|
|
119
|
+
export type SqrtOptions = LinearOptions;
|
|
77
120
|
|
|
78
121
|
/** Log 比例尺的选项 */
|
|
79
|
-
export type LogOptions =
|
|
122
|
+
export type LogOptions = LinearOptions & {
|
|
80
123
|
/** 底数 */
|
|
81
124
|
base?: number;
|
|
82
125
|
};
|
|
83
126
|
|
|
84
127
|
/** time 比例尺的选项 */
|
|
85
|
-
export type TimeOptions =
|
|
128
|
+
export type TimeOptions = {
|
|
129
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
130
|
+
unknown?: any;
|
|
131
|
+
/** 值域,默认为 [0, 1] */
|
|
132
|
+
range?: (number | string)[];
|
|
133
|
+
/** 定义域,默认为 [0, 1] */
|
|
134
|
+
domain?: Date[];
|
|
135
|
+
/** tick 个数,默认值为 5 */
|
|
136
|
+
tickCount?: number;
|
|
137
|
+
/** 计算 ticks 的算法 */
|
|
138
|
+
tickMethod?: TickMethod<Date>;
|
|
139
|
+
/** 是否需要对定义域的范围进行优化 */
|
|
140
|
+
nice?: boolean;
|
|
141
|
+
/** 是否需要限制输入的范围在值域内 */
|
|
142
|
+
clamp?: boolean;
|
|
143
|
+
/** 是否需要对输出进行四舍五入 */
|
|
144
|
+
round?: boolean;
|
|
145
|
+
/** 插值器的工厂函数,返回一个对归一化后的输入在值域指定范围内插值的函数 */
|
|
146
|
+
interpolate?: Interpolates;
|
|
86
147
|
/** getTick 的时间间隔 */
|
|
87
148
|
tickInterval?: number;
|
|
88
149
|
/** 格式化的形式 */
|
|
@@ -92,10 +153,25 @@ export type TimeOptions = ContinuousOptions<Date, number> & {
|
|
|
92
153
|
};
|
|
93
154
|
|
|
94
155
|
/** OrdinalOptions 比例尺的选项 */
|
|
95
|
-
export type OrdinalOptions =
|
|
156
|
+
export type OrdinalOptions = {
|
|
157
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
158
|
+
unknown?: any;
|
|
159
|
+
/** 值域,默认为 [0, 1] */
|
|
160
|
+
range?: any[];
|
|
161
|
+
/** 定义域,默认为 [0, 1] */
|
|
162
|
+
domain?: any[];
|
|
163
|
+
/** 比较器 */
|
|
164
|
+
compare?: Comparator;
|
|
165
|
+
};
|
|
96
166
|
|
|
97
167
|
/** 详细请参阅 scale/band.ts */
|
|
98
|
-
export type BandOptions =
|
|
168
|
+
export type BandOptions = {
|
|
169
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
170
|
+
unknown?: any;
|
|
171
|
+
/** 值域,默认为 [0, 1] */
|
|
172
|
+
range?: number[];
|
|
173
|
+
/** 定义域,默认为 [0, 1] */
|
|
174
|
+
domain?: any[];
|
|
99
175
|
/** 是否取整 */
|
|
100
176
|
round?: boolean;
|
|
101
177
|
/** 内部边距 */
|
|
@@ -114,14 +190,41 @@ export type BandOptions = BaseOptions<number | string, number> & {
|
|
|
114
190
|
export type PointOptions = Omit<BandOptions, 'paddingInner' | 'paddingOuter'>;
|
|
115
191
|
|
|
116
192
|
/** Threshold 比例尺的选项 */
|
|
117
|
-
export type ThresholdOptions =
|
|
193
|
+
export type ThresholdOptions = {
|
|
194
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
195
|
+
unknown?: any;
|
|
196
|
+
/** 值域,默认为 [0, 1] */
|
|
197
|
+
range?: any[];
|
|
198
|
+
/** 定义域,默认为 [0, 1] */
|
|
199
|
+
domain?: number[];
|
|
200
|
+
};
|
|
118
201
|
|
|
119
202
|
/** Quantize 比例尺的选项 */
|
|
120
|
-
export type QuantizeOptions =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
203
|
+
export type QuantizeOptions = {
|
|
204
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
205
|
+
unknown?: any;
|
|
206
|
+
/** 值域,默认为 [0, 1] */
|
|
207
|
+
range?: any[];
|
|
208
|
+
/** 定义域,默认为 [0, 1] */
|
|
209
|
+
domain?: number[];
|
|
210
|
+
/** 是否需要 nice */
|
|
211
|
+
nice?: boolean;
|
|
212
|
+
/** 期望的 tickCount */
|
|
213
|
+
tickCount?: number;
|
|
214
|
+
/** 计算 ticks 的算法 */
|
|
215
|
+
tickMethod?: TickMethod<number>;
|
|
216
|
+
};
|
|
125
217
|
|
|
126
218
|
/** Quantile 比例尺的选项 */
|
|
127
|
-
export type QuantileOptions =
|
|
219
|
+
export type QuantileOptions = {
|
|
220
|
+
/** 当需要映射的值不合法的时候,返回的值 */
|
|
221
|
+
unknown?: any;
|
|
222
|
+
/** 值域,默认为 [0, 1] */
|
|
223
|
+
range?: any[];
|
|
224
|
+
/** 定义域,默认为 [0, 1] */
|
|
225
|
+
domain?: number[];
|
|
226
|
+
/** 期望的 tickCount */
|
|
227
|
+
tickCount?: number;
|
|
228
|
+
/** 计算 ticks 的算法 */
|
|
229
|
+
tickMethod?: TickMethod<number>;
|
|
230
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import colorString from 'color-string';
|
|
2
|
+
|
|
3
|
+
function hue2rgb(p: number, q: number, m: number) {
|
|
4
|
+
let t = m;
|
|
5
|
+
if (t < 0) t += 1;
|
|
6
|
+
if (t > 1) t -= 1;
|
|
7
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
8
|
+
if (t < 1 / 2) return q;
|
|
9
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
10
|
+
return p;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function hsl2rbg(hsl: number[]) {
|
|
14
|
+
const h = hsl[0] / 360;
|
|
15
|
+
const s = hsl[1] / 100;
|
|
16
|
+
const l = hsl[2] / 100;
|
|
17
|
+
const a = hsl[3];
|
|
18
|
+
|
|
19
|
+
if (s === 0) return [l * 255, l * 255, l * 255, a];
|
|
20
|
+
|
|
21
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
22
|
+
const p = 2 * l - q;
|
|
23
|
+
const r = hue2rgb(p, q, h + 1 / 3);
|
|
24
|
+
const g = hue2rgb(p, q, h);
|
|
25
|
+
const b = hue2rgb(p, q, h - 1 / 3);
|
|
26
|
+
return [r * 255, g * 255, b * 255, a];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function string2rbg(s: string) {
|
|
30
|
+
const color = colorString.get(s);
|
|
31
|
+
if (!color) return null;
|
|
32
|
+
const { model, value } = color;
|
|
33
|
+
if (model === 'rgb') return value;
|
|
34
|
+
if (model === 'hsl') return hsl2rbg(value);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { compose } from './compose';
|
|
2
2
|
export { createNormalize } from './normalize';
|
|
3
|
-
export { createInterpolate, createInterpolateRound } from './interpolate';
|
|
4
3
|
export { createClamp } from './clamp';
|
|
5
4
|
export { bisect } from './bisect';
|
|
6
5
|
export { d3LinearNice } from './d3-linear-nice';
|
|
@@ -10,6 +9,12 @@ export { logs, pows } from './log';
|
|
|
10
9
|
export { d3LogNice } from './d3-log-nice';
|
|
11
10
|
export { tickIncrement, tickStep } from './ticks';
|
|
12
11
|
export { findTickInterval } from './find-tick-interval';
|
|
12
|
+
export {
|
|
13
|
+
createInterpolateValue,
|
|
14
|
+
createInterpolateRound,
|
|
15
|
+
createInterpolateNumber,
|
|
16
|
+
createInterpolateColor,
|
|
17
|
+
} from './interpolate';
|
|
13
18
|
|
|
14
19
|
export {
|
|
15
20
|
DURATION_SECOND,
|
package/src/utils/interpolate.ts
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { Interpolate } from '../types';
|
|
2
|
+
import { string2rbg } from './color';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* 返回一个线性插值器,接受数字
|
|
5
6
|
* @param a 任意值
|
|
6
7
|
* @param b 任意值
|
|
7
8
|
* @returns 线性插值器
|
|
8
9
|
*/
|
|
9
|
-
export const
|
|
10
|
+
export const createInterpolateNumber: Interpolate<number> = (a, b) => {
|
|
11
|
+
return (t) => a * (1 - t) + b * t;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const createInterpolateColor: Interpolate<string> = (a, b) => {
|
|
15
|
+
const c1 = string2rbg(a);
|
|
16
|
+
const c2 = string2rbg(b);
|
|
17
|
+
if (c1 === null || c2 === null) return c1 ? () => a : () => b;
|
|
18
|
+
return (t) => {
|
|
19
|
+
const values = new Array(4);
|
|
20
|
+
for (let i = 0; i < 4; i += 1) {
|
|
21
|
+
const from = c1[i];
|
|
22
|
+
const to = c2[i];
|
|
23
|
+
values[i] = from * (1 - t) + to * t;
|
|
24
|
+
}
|
|
25
|
+
const [r, g, b, a] = values as number[];
|
|
26
|
+
return `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${a})`;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 返回一个线性插值器,接受数字和颜色
|
|
32
|
+
* @param a 任意值
|
|
33
|
+
* @param b 任意值
|
|
34
|
+
* @returns 线性插值器
|
|
35
|
+
*/
|
|
36
|
+
export const createInterpolateValue: Interpolate<number | string> = (a, b) => {
|
|
37
|
+
if (typeof a === 'number' && typeof b === 'number') return createInterpolateNumber(a, b);
|
|
38
|
+
if (typeof a === 'string' && typeof b === 'string') return createInterpolateColor(a, b);
|
|
39
|
+
return () => a;
|
|
40
|
+
};
|
|
10
41
|
|
|
11
42
|
/**
|
|
12
43
|
* 返回一个 round 线性差值器,对输出值进行四舍五入
|
|
@@ -14,4 +45,7 @@ export const createInterpolate: Interpolate = (a, b) => (t) => a * (1 - t) + b *
|
|
|
14
45
|
* @param b 任意值
|
|
15
46
|
* @returns 线性插值器
|
|
16
47
|
*/
|
|
17
|
-
export const createInterpolateRound: Interpolate = (a, b) =>
|
|
48
|
+
export const createInterpolateRound: Interpolate<number> = (a, b) => {
|
|
49
|
+
const interpolateNumber = createInterpolateNumber(a, b);
|
|
50
|
+
return (t) => Math.round(interpolateNumber(t));
|
|
51
|
+
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function digitLength(num) {
|
|
2
|
-
// Get digit length of e
|
|
3
|
-
const eSplit = num.toString().split(/[eE]/);
|
|
4
|
-
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
5
|
-
return len > 0 ? len : 0;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* 高精度加法,解决 0.1 + 0.2 !== 0.3 的经典问题
|
|
9
|
-
*
|
|
10
|
-
* @param num1 加数
|
|
11
|
-
* @param num2 被加数
|
|
12
|
-
* @return {number} 返回值
|
|
13
|
-
*/
|
|
14
|
-
export function precisionAdd(num1, num2) {
|
|
15
|
-
const num1Digits = digitLength(num1);
|
|
16
|
-
const num2Digits = digitLength(num2);
|
|
17
|
-
const baseNum = 10 ** Math.max(num1Digits, num2Digits);
|
|
18
|
-
return (num1 * baseNum + num2 * baseNum) / baseNum;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=precision-add.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"precision-add.js","sourceRoot":"src/","sources":["utils/precision-add.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAC,GAAW;IAC9B,wBAAwB;IACxB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAY;IACrD,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACrD,CAAC"}
|
package/esm/utils/sequence.d.ts
DELETED
package/esm/utils/sequence.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 构造区间 [a1, an) 的等差数列
|
|
3
|
-
*
|
|
4
|
-
* @param a1 起始值
|
|
5
|
-
* @param an 结束值
|
|
6
|
-
* @param d 公差
|
|
7
|
-
* @returns {array[string]} 由每一项组成的数组
|
|
8
|
-
*/
|
|
9
|
-
export function sequence(a1, an, d) {
|
|
10
|
-
const tmp = (an - a1) / d;
|
|
11
|
-
const size = Number.isInteger(tmp) ? tmp : Math.floor(tmp) + 1;
|
|
12
|
-
if (size <= 0) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
const arr = new Array(size - 1);
|
|
16
|
-
for (let i = 0; i < size; i += 1) {
|
|
17
|
-
arr[i] = a1 + i * d;
|
|
18
|
-
}
|
|
19
|
-
return arr;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=sequence.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.js","sourceRoot":"src/","sources":["utils/sequence.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,UAAU,QAAQ,CAAC,EAAU,EAAE,EAAU,EAAE,CAAS;IACxD,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAE/D,IAAI,IAAI,IAAI,CAAC,EAAE;QACb,OAAO,EAAE,CAAC;KACX;IAED,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE;QAChC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;KACrB;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.precisionAdd = void 0;
|
|
4
|
-
function digitLength(num) {
|
|
5
|
-
// Get digit length of e
|
|
6
|
-
const eSplit = num.toString().split(/[eE]/);
|
|
7
|
-
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
8
|
-
return len > 0 ? len : 0;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 高精度加法,解决 0.1 + 0.2 !== 0.3 的经典问题
|
|
12
|
-
*
|
|
13
|
-
* @param num1 加数
|
|
14
|
-
* @param num2 被加数
|
|
15
|
-
* @return {number} 返回值
|
|
16
|
-
*/
|
|
17
|
-
function precisionAdd(num1, num2) {
|
|
18
|
-
const num1Digits = digitLength(num1);
|
|
19
|
-
const num2Digits = digitLength(num2);
|
|
20
|
-
const baseNum = 10 ** Math.max(num1Digits, num2Digits);
|
|
21
|
-
return (num1 * baseNum + num2 * baseNum) / baseNum;
|
|
22
|
-
}
|
|
23
|
-
exports.precisionAdd = precisionAdd;
|
|
24
|
-
//# sourceMappingURL=precision-add.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"precision-add.js","sourceRoot":"src/","sources":["utils/precision-add.ts"],"names":[],"mappings":";;;AAAA,SAAS,WAAW,CAAC,GAAW;IAC9B,wBAAwB;IACxB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,IAAY;IACrD,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC;AACrD,CAAC;AALD,oCAKC"}
|
package/lib/utils/sequence.d.ts
DELETED
package/lib/utils/sequence.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 构造区间 [a1, an) 的等差数列
|
|
4
|
-
*
|
|
5
|
-
* @param a1 起始值
|
|
6
|
-
* @param an 结束值
|
|
7
|
-
* @param d 公差
|
|
8
|
-
* @returns {array[string]} 由每一项组成的数组
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.sequence = void 0;
|
|
12
|
-
function sequence(a1, an, d) {
|
|
13
|
-
const tmp = (an - a1) / d;
|
|
14
|
-
const size = Number.isInteger(tmp) ? tmp : Math.floor(tmp) + 1;
|
|
15
|
-
if (size <= 0) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
const arr = new Array(size - 1);
|
|
19
|
-
for (let i = 0; i < size; i += 1) {
|
|
20
|
-
arr[i] = a1 + i * d;
|
|
21
|
-
}
|
|
22
|
-
return arr;
|
|
23
|
-
}
|
|
24
|
-
exports.sequence = sequence;
|
|
25
|
-
//# sourceMappingURL=sequence.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.js","sourceRoot":"src/","sources":["utils/sequence.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,SAAgB,QAAQ,CAAC,EAAU,EAAE,EAAU,EAAE,CAAS;IACxD,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAE/D,IAAI,IAAI,IAAI,CAAC,EAAE;QACb,OAAO,EAAE,CAAC;KACX;IAED,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE;QAChC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;KACrB;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAbD,4BAaC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function digitLength(num: number) {
|
|
2
|
-
// Get digit length of e
|
|
3
|
-
const eSplit = num.toString().split(/[eE]/);
|
|
4
|
-
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
5
|
-
return len > 0 ? len : 0;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 高精度加法,解决 0.1 + 0.2 !== 0.3 的经典问题
|
|
10
|
-
*
|
|
11
|
-
* @param num1 加数
|
|
12
|
-
* @param num2 被加数
|
|
13
|
-
* @return {number} 返回值
|
|
14
|
-
*/
|
|
15
|
-
export function precisionAdd(num1: number, num2: number) {
|
|
16
|
-
const num1Digits = digitLength(num1);
|
|
17
|
-
const num2Digits = digitLength(num2);
|
|
18
|
-
const baseNum = 10 ** Math.max(num1Digits, num2Digits);
|
|
19
|
-
return (num1 * baseNum + num2 * baseNum) / baseNum;
|
|
20
|
-
}
|
package/src/utils/sequence.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 构造区间 [a1, an) 的等差数列
|
|
3
|
-
*
|
|
4
|
-
* @param a1 起始值
|
|
5
|
-
* @param an 结束值
|
|
6
|
-
* @param d 公差
|
|
7
|
-
* @returns {array[string]} 由每一项组成的数组
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export function sequence(a1: number, an: number, d: number) {
|
|
11
|
-
const tmp = (an - a1) / d;
|
|
12
|
-
const size = Number.isInteger(tmp) ? tmp : Math.floor(tmp) + 1;
|
|
13
|
-
|
|
14
|
-
if (size <= 0) {
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const arr = new Array(size - 1);
|
|
19
|
-
for (let i = 0; i < size; i += 1) {
|
|
20
|
-
arr[i] = a1 + i * d;
|
|
21
|
-
}
|
|
22
|
-
return arr;
|
|
23
|
-
}
|