@d-matrix/utils 1.27.0 → 1.28.0
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/algorithm/binary.d.ts +8 -8
- package/dist/algorithm/binary.js +38 -38
- package/dist/algorithm/index.d.ts +2 -2
- package/dist/algorithm/index.js +2 -2
- package/dist/algorithm/tree.d.ts +34 -34
- package/dist/algorithm/tree.js +124 -124
- package/dist/array.d.ts +46 -5
- package/dist/array.js +129 -37
- package/dist/clipboard.d.ts +12 -12
- package/dist/clipboard.js +107 -107
- package/dist/color.d.ts +7 -7
- package/dist/color.js +41 -41
- package/dist/date.d.ts +34 -34
- package/dist/date.js +62 -62
- package/dist/decimal.d.ts +17 -17
- package/dist/decimal.js +23 -23
- package/dist/dom.d.ts +11 -11
- package/dist/dom.js +27 -27
- package/dist/echarts.d.ts +36 -36
- package/dist/echarts.js +112 -112
- package/dist/file.d.ts +49 -49
- package/dist/file.js +154 -154
- package/dist/i18n.d.ts +10 -10
- package/dist/i18n.js +12 -12
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/number.d.ts +2 -2
- package/dist/number.js +4 -4
- package/dist/object.d.ts +13 -13
- package/dist/object.js +28 -28
- package/dist/operator.d.ts +6 -6
- package/dist/operator.js +6 -6
- package/dist/react/enhancedComponent.d.ts +12 -12
- package/dist/react/enhancedComponent.js +16 -16
- package/dist/react/index.d.ts +15 -12
- package/dist/react/index.js +15 -12
- package/dist/react/renderToString.d.ts +3 -3
- package/dist/react/renderToString.js +30 -30
- package/dist/react/types.d.ts +9 -9
- package/dist/react/types.js +1 -1
- package/dist/react/useCopyToClipboard.d.ts +21 -21
- package/dist/react/useCopyToClipboard.js +44 -44
- package/dist/react/useDeepCompareRef.d.ts +2 -2
- package/dist/react/useDeepCompareRef.js +11 -11
- package/dist/react/useDisableContextMenu.d.ts +7 -7
- package/dist/react/useDisableContextMenu.js +24 -24
- package/dist/react/useEventCallback.d.ts +7 -0
- package/dist/react/useEventCallback.js +19 -0
- package/dist/react/useForwardRef.d.ts +9 -9
- package/dist/react/useForwardRef.js +22 -22
- package/dist/react/useId.d.ts +1 -0
- package/dist/react/useId.js +12 -0
- package/dist/react/useIsFirstRender.d.ts +6 -6
- package/dist/react/useIsFirstRender.js +14 -14
- package/dist/react/useIsMounted.d.ts +2 -2
- package/dist/react/useIsMounted.js +13 -13
- package/dist/react/useIsomorphicLayoutEffect.d.ts +2 -2
- package/dist/react/useIsomorphicLayoutEffect.js +2 -2
- package/dist/react/useMediaQuery.d.ts +14 -14
- package/dist/react/useMediaQuery.js +42 -42
- package/dist/react/useSafeTimeout.d.ts +12 -0
- package/dist/react/useSafeTimeout.js +28 -0
- package/dist/react/useStateCallback.d.ts +2 -2
- package/dist/react/useStateCallback.js +17 -17
- package/dist/support.d.ts +12 -12
- package/dist/support.js +12 -12
- package/dist/timer.d.ts +5 -5
- package/dist/timer.js +5 -5
- package/dist/types.d.ts +128 -21
- package/dist/types.js +1 -1
- package/package.json +2 -2
- package/readme.md +5 -1
package/dist/dom.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 元素滚动条滚动到顶部
|
|
3
|
-
*/
|
|
4
|
-
export function scrollToTop(element) {
|
|
5
|
-
if (element) {
|
|
6
|
-
if (element.scrollTop === 0) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
// 兼容低版本浏览器
|
|
10
|
-
if (typeof element.scrollTo === 'function') {
|
|
11
|
-
element.scrollTo({ top: 0 });
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
element.scrollTop = 0;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Strips HTML tags from a given string and returns the plain text content.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} html - The HTML string to strip tags from.
|
|
22
|
-
* @return {string} The plain text content of the HTML string.
|
|
23
|
-
*/
|
|
24
|
-
export function strip(html) {
|
|
25
|
-
let doc = new DOMParser().parseFromString(html !== null && html !== void 0 ? html : '', 'text/html');
|
|
26
|
-
return doc.body.textContent || '';
|
|
27
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 元素滚动条滚动到顶部
|
|
3
|
+
*/
|
|
4
|
+
export function scrollToTop(element) {
|
|
5
|
+
if (element) {
|
|
6
|
+
if (element.scrollTop === 0) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
// 兼容低版本浏览器
|
|
10
|
+
if (typeof element.scrollTo === 'function') {
|
|
11
|
+
element.scrollTo({ top: 0 });
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
element.scrollTop = 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Strips HTML tags from a given string and returns the plain text content.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} html - The HTML string to strip tags from.
|
|
22
|
+
* @return {string} The plain text content of the HTML string.
|
|
23
|
+
*/
|
|
24
|
+
export function strip(html) {
|
|
25
|
+
let doc = new DOMParser().parseFromString(html !== null && html !== void 0 ? html : '', 'text/html');
|
|
26
|
+
return doc.body.textContent || '';
|
|
27
|
+
}
|
package/dist/echarts.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import deepmerge from 'deepmerge';
|
|
2
|
-
import { EChartsOption } from 'echarts';
|
|
3
|
-
export declare function mergeOption(defaults: EChartsOption, overrides: EChartsOption, option?: deepmerge.Options): EChartsOption;
|
|
4
|
-
/**
|
|
5
|
-
* 场景:后端接口返回某几个时间的点的数据,需求是在接口数据的基础上每隔5分钟补一个点,以达到图中的效果
|
|
6
|
-
* https://raw.githubusercontent.com/mrdulin/pic-bucket-01/master/Dingtalk_20240724140535.jpg
|
|
7
|
-
* 每5分钟补一个点, Y轴值为前一个点的值
|
|
8
|
-
* 时间示例: [9:23, 9:27] => [9:23, 9:25, 9:27, 9:30]
|
|
9
|
-
*
|
|
10
|
-
* 填充的点只包含x,y轴字段,入参数据保持不变
|
|
11
|
-
*/
|
|
12
|
-
export declare function fill<T extends Record<string, any>, XAxisField extends keyof T, YAxisField extends keyof T>(dataSource: T[], xAxisField: XAxisField, yAxisField: YAxisField): {
|
|
13
|
-
[x: string]: number | T[YAxisField];
|
|
14
|
-
}[];
|
|
15
|
-
/**
|
|
16
|
-
* 最大差值倍率计算;基础倍率1.2,Y轴刻度精度为0.01,并且Y轴刻度需要被5等分(即max - min需要被5等分),否则会出现重复的刻度;
|
|
17
|
-
* 判断max-min是否被5等分(是否小于0.01),小于0.01表示不能被5等分,基础倍率增加0.1后,再次判断,直到被5等分
|
|
18
|
-
* @param first
|
|
19
|
-
* @param maxDiff
|
|
20
|
-
* @param decimalPlaces
|
|
21
|
-
* @param splitNumber
|
|
22
|
-
* @returns 最大差值倍率
|
|
23
|
-
*/
|
|
24
|
-
export declare const getDiffRate: (first: number, maxDiff: number, decimalPlaces?: number, splitNumber?: number) => number;
|
|
25
|
-
/**
|
|
26
|
-
* 计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置
|
|
27
|
-
* @param data 原始数据
|
|
28
|
-
* @param key Y轴字段
|
|
29
|
-
* @param decimalPlaces Y轴值的精度(小数位数)
|
|
30
|
-
* @param splitNumber Y轴splitNumber属性
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
export declare function calcYAxisRange<T extends Record<string, any>, Key extends keyof T>(data: T[], key: Key, decimalPlaces?: number, splitNumber?: number): {
|
|
34
|
-
max: number;
|
|
35
|
-
min: number;
|
|
36
|
-
};
|
|
1
|
+
import deepmerge from 'deepmerge';
|
|
2
|
+
import { EChartsOption } from 'echarts';
|
|
3
|
+
export declare function mergeOption(defaults: EChartsOption, overrides: EChartsOption, option?: deepmerge.Options): EChartsOption;
|
|
4
|
+
/**
|
|
5
|
+
* 场景:后端接口返回某几个时间的点的数据,需求是在接口数据的基础上每隔5分钟补一个点,以达到图中的效果
|
|
6
|
+
* https://raw.githubusercontent.com/mrdulin/pic-bucket-01/master/Dingtalk_20240724140535.jpg
|
|
7
|
+
* 每5分钟补一个点, Y轴值为前一个点的值
|
|
8
|
+
* 时间示例: [9:23, 9:27] => [9:23, 9:25, 9:27, 9:30]
|
|
9
|
+
*
|
|
10
|
+
* 填充的点只包含x,y轴字段,入参数据保持不变
|
|
11
|
+
*/
|
|
12
|
+
export declare function fill<T extends Record<string, any>, XAxisField extends keyof T, YAxisField extends keyof T>(dataSource: T[], xAxisField: XAxisField, yAxisField: YAxisField): {
|
|
13
|
+
[x: string]: number | T[YAxisField];
|
|
14
|
+
}[];
|
|
15
|
+
/**
|
|
16
|
+
* 最大差值倍率计算;基础倍率1.2,Y轴刻度精度为0.01,并且Y轴刻度需要被5等分(即max - min需要被5等分),否则会出现重复的刻度;
|
|
17
|
+
* 判断max-min是否被5等分(是否小于0.01),小于0.01表示不能被5等分,基础倍率增加0.1后,再次判断,直到被5等分
|
|
18
|
+
* @param first
|
|
19
|
+
* @param maxDiff
|
|
20
|
+
* @param decimalPlaces
|
|
21
|
+
* @param splitNumber
|
|
22
|
+
* @returns 最大差值倍率
|
|
23
|
+
*/
|
|
24
|
+
export declare const getDiffRate: (first: number, maxDiff: number, decimalPlaces?: number, splitNumber?: number) => number;
|
|
25
|
+
/**
|
|
26
|
+
* 计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置
|
|
27
|
+
* @param data 原始数据
|
|
28
|
+
* @param key Y轴字段
|
|
29
|
+
* @param decimalPlaces Y轴值的精度(小数位数)
|
|
30
|
+
* @param splitNumber Y轴splitNumber属性
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare function calcYAxisRange<T extends Record<string, any>, Key extends keyof T>(data: T[], key: Key, decimalPlaces?: number, splitNumber?: number): {
|
|
34
|
+
max: number;
|
|
35
|
+
min: number;
|
|
36
|
+
};
|
package/dist/echarts.js
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import deepmerge from 'deepmerge';
|
|
3
|
-
import { trueTypeOf } from './operator';
|
|
4
|
-
const combineMerge = (target, source, options) => {
|
|
5
|
-
const destination = target.slice();
|
|
6
|
-
source.forEach((item, index) => {
|
|
7
|
-
if (typeof destination[index] === 'undefined') {
|
|
8
|
-
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
|
|
9
|
-
}
|
|
10
|
-
else if (options.isMergeableObject(item)) {
|
|
11
|
-
destination[index] = deepmerge(target[index], item, options);
|
|
12
|
-
}
|
|
13
|
-
else if (target.indexOf(item) === -1) {
|
|
14
|
-
destination.push(item);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return destination;
|
|
18
|
-
};
|
|
19
|
-
export function mergeOption(defaults, overrides, option) {
|
|
20
|
-
return deepmerge(defaults, overrides, Object.assign({ arrayMerge: combineMerge }, option));
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 场景:后端接口返回某几个时间的点的数据,需求是在接口数据的基础上每隔5分钟补一个点,以达到图中的效果
|
|
24
|
-
* https://raw.githubusercontent.com/mrdulin/pic-bucket-01/master/Dingtalk_20240724140535.jpg
|
|
25
|
-
* 每5分钟补一个点, Y轴值为前一个点的值
|
|
26
|
-
* 时间示例: [9:23, 9:27] => [9:23, 9:25, 9:27, 9:30]
|
|
27
|
-
*
|
|
28
|
-
* 填充的点只包含x,y轴字段,入参数据保持不变
|
|
29
|
-
*/
|
|
30
|
-
// TODO improve TS types
|
|
31
|
-
export function fill(dataSource, xAxisField, yAxisField) {
|
|
32
|
-
const data = [];
|
|
33
|
-
for (let i = 0; i < dataSource.length; i++) {
|
|
34
|
-
const current = dataSource[i];
|
|
35
|
-
const next = dataSource[i + 1];
|
|
36
|
-
data.push(Object.assign(Object.assign({}, current), { [xAxisField]: dayjs(current[xAxisField]).valueOf(), [yAxisField]: current[yAxisField] }));
|
|
37
|
-
if (next !== null && next !== undefined) {
|
|
38
|
-
let currentDate = dayjs(current[xAxisField]);
|
|
39
|
-
const nextDate = dayjs(next[xAxisField]);
|
|
40
|
-
const timeDiff = dayjs(next[xAxisField]).diff(dayjs(current[xAxisField]), 'minute');
|
|
41
|
-
let count = Math.ceil(timeDiff / 5);
|
|
42
|
-
const remainder = currentDate.minute() % 5;
|
|
43
|
-
if (remainder > 0 && nextDate.minute() % 5 !== 0) {
|
|
44
|
-
currentDate = dayjs(current[xAxisField]).add(5 - remainder, 'minute');
|
|
45
|
-
data.push({ [xAxisField]: currentDate.valueOf(), [yAxisField]: current[yAxisField] });
|
|
46
|
-
}
|
|
47
|
-
for (let j = 1; j < count; j++) {
|
|
48
|
-
data.push({
|
|
49
|
-
[xAxisField]: currentDate
|
|
50
|
-
.clone()
|
|
51
|
-
.add(5 * j, 'minute')
|
|
52
|
-
.valueOf(),
|
|
53
|
-
[yAxisField]: current[yAxisField],
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 最大差值倍率计算;基础倍率1.2,Y轴刻度精度为0.01,并且Y轴刻度需要被5等分(即max - min需要被5等分),否则会出现重复的刻度;
|
|
62
|
-
* 判断max-min是否被5等分(是否小于0.01),小于0.01表示不能被5等分,基础倍率增加0.1后,再次判断,直到被5等分
|
|
63
|
-
* @param first
|
|
64
|
-
* @param maxDiff
|
|
65
|
-
* @param decimalPlaces
|
|
66
|
-
* @param splitNumber
|
|
67
|
-
* @returns 最大差值倍率
|
|
68
|
-
*/
|
|
69
|
-
export const getDiffRate = (first, maxDiff, decimalPlaces = 2, splitNumber = 5) => {
|
|
70
|
-
let diffRate = 1.2;
|
|
71
|
-
if (first === 0 || maxDiff === 0)
|
|
72
|
-
return diffRate;
|
|
73
|
-
const minDiff = 1 / Math.pow(10, decimalPlaces);
|
|
74
|
-
function calc(f, d) {
|
|
75
|
-
const max = f + d * diffRate;
|
|
76
|
-
const min = f - d * diffRate;
|
|
77
|
-
if ((max - min) / splitNumber < minDiff) {
|
|
78
|
-
diffRate += 0.1;
|
|
79
|
-
return calc(f, d);
|
|
80
|
-
}
|
|
81
|
-
return diffRate;
|
|
82
|
-
}
|
|
83
|
-
return calc(first, maxDiff);
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* 计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置
|
|
87
|
-
* @param data 原始数据
|
|
88
|
-
* @param key Y轴字段
|
|
89
|
-
* @param decimalPlaces Y轴值的精度(小数位数)
|
|
90
|
-
* @param splitNumber Y轴splitNumber属性
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
export function calcYAxisRange(data, key, decimalPlaces = 2, splitNumber = 5) {
|
|
94
|
-
var _a, _b;
|
|
95
|
-
const maxValue = (_a = Math.max(...data.map((o) => o[key]))) !== null && _a !== void 0 ? _a : 0;
|
|
96
|
-
const minValue = (_b = Math.min(...data.map((o) => o[key]))) !== null && _b !== void 0 ? _b : 0;
|
|
97
|
-
let firstValue = 0;
|
|
98
|
-
for (const item of data) {
|
|
99
|
-
if (trueTypeOf(item[key]) === 'number') {
|
|
100
|
-
firstValue = item[key];
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// 最大值与第一个点的差值,最小值与第一个点的差值,取最大
|
|
105
|
-
// 例如:first = 1, max = 1.3, min = 0.6, maxDiff = abs(min - first) = 0.4
|
|
106
|
-
const maxDiff = Math.max(Math.abs(maxValue - firstValue), Math.abs(minValue - firstValue));
|
|
107
|
-
// 差值缩放比例
|
|
108
|
-
const diffRate = getDiffRate(firstValue, maxDiff, decimalPlaces, splitNumber);
|
|
109
|
-
const max = firstValue + (maxDiff === 0 ? firstValue / 6 : maxDiff * diffRate);
|
|
110
|
-
const min = firstValue - (maxDiff === 0 ? firstValue / 6 : maxDiff * diffRate);
|
|
111
|
-
return { max, min };
|
|
112
|
-
}
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
import { trueTypeOf } from './operator';
|
|
4
|
+
const combineMerge = (target, source, options) => {
|
|
5
|
+
const destination = target.slice();
|
|
6
|
+
source.forEach((item, index) => {
|
|
7
|
+
if (typeof destination[index] === 'undefined') {
|
|
8
|
+
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options);
|
|
9
|
+
}
|
|
10
|
+
else if (options.isMergeableObject(item)) {
|
|
11
|
+
destination[index] = deepmerge(target[index], item, options);
|
|
12
|
+
}
|
|
13
|
+
else if (target.indexOf(item) === -1) {
|
|
14
|
+
destination.push(item);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return destination;
|
|
18
|
+
};
|
|
19
|
+
export function mergeOption(defaults, overrides, option) {
|
|
20
|
+
return deepmerge(defaults, overrides, Object.assign({ arrayMerge: combineMerge }, option));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 场景:后端接口返回某几个时间的点的数据,需求是在接口数据的基础上每隔5分钟补一个点,以达到图中的效果
|
|
24
|
+
* https://raw.githubusercontent.com/mrdulin/pic-bucket-01/master/Dingtalk_20240724140535.jpg
|
|
25
|
+
* 每5分钟补一个点, Y轴值为前一个点的值
|
|
26
|
+
* 时间示例: [9:23, 9:27] => [9:23, 9:25, 9:27, 9:30]
|
|
27
|
+
*
|
|
28
|
+
* 填充的点只包含x,y轴字段,入参数据保持不变
|
|
29
|
+
*/
|
|
30
|
+
// TODO improve TS types
|
|
31
|
+
export function fill(dataSource, xAxisField, yAxisField) {
|
|
32
|
+
const data = [];
|
|
33
|
+
for (let i = 0; i < dataSource.length; i++) {
|
|
34
|
+
const current = dataSource[i];
|
|
35
|
+
const next = dataSource[i + 1];
|
|
36
|
+
data.push(Object.assign(Object.assign({}, current), { [xAxisField]: dayjs(current[xAxisField]).valueOf(), [yAxisField]: current[yAxisField] }));
|
|
37
|
+
if (next !== null && next !== undefined) {
|
|
38
|
+
let currentDate = dayjs(current[xAxisField]);
|
|
39
|
+
const nextDate = dayjs(next[xAxisField]);
|
|
40
|
+
const timeDiff = dayjs(next[xAxisField]).diff(dayjs(current[xAxisField]), 'minute');
|
|
41
|
+
let count = Math.ceil(timeDiff / 5);
|
|
42
|
+
const remainder = currentDate.minute() % 5;
|
|
43
|
+
if (remainder > 0 && nextDate.minute() % 5 !== 0) {
|
|
44
|
+
currentDate = dayjs(current[xAxisField]).add(5 - remainder, 'minute');
|
|
45
|
+
data.push({ [xAxisField]: currentDate.valueOf(), [yAxisField]: current[yAxisField] });
|
|
46
|
+
}
|
|
47
|
+
for (let j = 1; j < count; j++) {
|
|
48
|
+
data.push({
|
|
49
|
+
[xAxisField]: currentDate
|
|
50
|
+
.clone()
|
|
51
|
+
.add(5 * j, 'minute')
|
|
52
|
+
.valueOf(),
|
|
53
|
+
[yAxisField]: current[yAxisField],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 最大差值倍率计算;基础倍率1.2,Y轴刻度精度为0.01,并且Y轴刻度需要被5等分(即max - min需要被5等分),否则会出现重复的刻度;
|
|
62
|
+
* 判断max-min是否被5等分(是否小于0.01),小于0.01表示不能被5等分,基础倍率增加0.1后,再次判断,直到被5等分
|
|
63
|
+
* @param first
|
|
64
|
+
* @param maxDiff
|
|
65
|
+
* @param decimalPlaces
|
|
66
|
+
* @param splitNumber
|
|
67
|
+
* @returns 最大差值倍率
|
|
68
|
+
*/
|
|
69
|
+
export const getDiffRate = (first, maxDiff, decimalPlaces = 2, splitNumber = 5) => {
|
|
70
|
+
let diffRate = 1.2;
|
|
71
|
+
if (first === 0 || maxDiff === 0)
|
|
72
|
+
return diffRate;
|
|
73
|
+
const minDiff = 1 / Math.pow(10, decimalPlaces);
|
|
74
|
+
function calc(f, d) {
|
|
75
|
+
const max = f + d * diffRate;
|
|
76
|
+
const min = f - d * diffRate;
|
|
77
|
+
if ((max - min) / splitNumber < minDiff) {
|
|
78
|
+
diffRate += 0.1;
|
|
79
|
+
return calc(f, d);
|
|
80
|
+
}
|
|
81
|
+
return diffRate;
|
|
82
|
+
}
|
|
83
|
+
return calc(first, maxDiff);
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* 计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置
|
|
87
|
+
* @param data 原始数据
|
|
88
|
+
* @param key Y轴字段
|
|
89
|
+
* @param decimalPlaces Y轴值的精度(小数位数)
|
|
90
|
+
* @param splitNumber Y轴splitNumber属性
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
export function calcYAxisRange(data, key, decimalPlaces = 2, splitNumber = 5) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
const maxValue = (_a = Math.max(...data.map((o) => o[key]))) !== null && _a !== void 0 ? _a : 0;
|
|
96
|
+
const minValue = (_b = Math.min(...data.map((o) => o[key]))) !== null && _b !== void 0 ? _b : 0;
|
|
97
|
+
let firstValue = 0;
|
|
98
|
+
for (const item of data) {
|
|
99
|
+
if (trueTypeOf(item[key]) === 'number') {
|
|
100
|
+
firstValue = item[key];
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 最大值与第一个点的差值,最小值与第一个点的差值,取最大
|
|
105
|
+
// 例如:first = 1, max = 1.3, min = 0.6, maxDiff = abs(min - first) = 0.4
|
|
106
|
+
const maxDiff = Math.max(Math.abs(maxValue - firstValue), Math.abs(minValue - firstValue));
|
|
107
|
+
// 差值缩放比例
|
|
108
|
+
const diffRate = getDiffRate(firstValue, maxDiff, decimalPlaces, splitNumber);
|
|
109
|
+
const max = firstValue + (maxDiff === 0 ? firstValue / 6 : maxDiff * diffRate);
|
|
110
|
+
const min = firstValue - (maxDiff === 0 ? firstValue / 6 : maxDiff * diffRate);
|
|
111
|
+
return { max, min };
|
|
112
|
+
}
|
package/dist/file.d.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
declare type FileURL = string;
|
|
2
|
-
/**
|
|
3
|
-
* 转换BlobPart或者文件地址为图片对象
|
|
4
|
-
* @param file 传入文件 或者 url
|
|
5
|
-
* @returns 返回 一个图片详情对象
|
|
6
|
-
*/
|
|
7
|
-
export declare const toImage: (file: BlobPart | FileURL, options?: BlobPropertyBag | undefined) => Promise<HTMLImageElement>;
|
|
8
|
-
export interface ImageSizeValidationResult {
|
|
9
|
-
isOk: boolean;
|
|
10
|
-
width: number;
|
|
11
|
-
height: number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 图片宽,高校验
|
|
15
|
-
* @param file 传入文件 或者 url
|
|
16
|
-
* @param limitSize 限制宽度, 高度
|
|
17
|
-
* @returns isOK: 是否超出宽高; width, height: 图片的宽高
|
|
18
|
-
*/
|
|
19
|
-
export declare const validateImageSize: (file: BlobPart | FileURL, limitSize: {
|
|
20
|
-
width: number;
|
|
21
|
-
height: number;
|
|
22
|
-
}, options?: BlobPropertyBag | undefined) => Promise<ImageSizeValidationResult>;
|
|
23
|
-
/**
|
|
24
|
-
* 检测图片地址是否可用
|
|
25
|
-
* @param src 图片地址
|
|
26
|
-
* @param img HTMLImageElement
|
|
27
|
-
* @returns Promise<boolean>
|
|
28
|
-
*/
|
|
29
|
-
export declare function isImageExists(src: string, img?: HTMLImageElement): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* 从Content-Disposition中获取文件名
|
|
32
|
-
* @param header 包含Content-Disposition, 值为'attachment;filename=%E5%A4%A7%E8%A1%8C%E6%8C%87%E5%AF%BC2024-06-27-2024-06-28.xlsx'
|
|
33
|
-
* @returns string
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export declare function getFilenameFromContentDispositionHeader(header: {
|
|
37
|
-
['content-disposition']: string;
|
|
38
|
-
}): string;
|
|
39
|
-
declare const HyperLinkTargets: readonly ["_self", "_blank", "_parent", "_top"];
|
|
40
|
-
export declare type HyperLinkTarget = (typeof HyperLinkTargets)[number];
|
|
41
|
-
export declare function download(source: Blob, fileName?: string): void;
|
|
42
|
-
export declare function download(source: string, fileName?: string, target?: HyperLinkTarget): void;
|
|
43
|
-
/**
|
|
44
|
-
* 通过创建iframe进行文件下载
|
|
45
|
-
* @param source
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
export declare function downloadFileByIframe(source: string): boolean;
|
|
49
|
-
export {};
|
|
1
|
+
declare type FileURL = string;
|
|
2
|
+
/**
|
|
3
|
+
* 转换BlobPart或者文件地址为图片对象
|
|
4
|
+
* @param file 传入文件 或者 url
|
|
5
|
+
* @returns 返回 一个图片详情对象
|
|
6
|
+
*/
|
|
7
|
+
export declare const toImage: (file: BlobPart | FileURL, options?: BlobPropertyBag | undefined) => Promise<HTMLImageElement>;
|
|
8
|
+
export interface ImageSizeValidationResult {
|
|
9
|
+
isOk: boolean;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 图片宽,高校验
|
|
15
|
+
* @param file 传入文件 或者 url
|
|
16
|
+
* @param limitSize 限制宽度, 高度
|
|
17
|
+
* @returns isOK: 是否超出宽高; width, height: 图片的宽高
|
|
18
|
+
*/
|
|
19
|
+
export declare const validateImageSize: (file: BlobPart | FileURL, limitSize: {
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
}, options?: BlobPropertyBag | undefined) => Promise<ImageSizeValidationResult>;
|
|
23
|
+
/**
|
|
24
|
+
* 检测图片地址是否可用
|
|
25
|
+
* @param src 图片地址
|
|
26
|
+
* @param img HTMLImageElement
|
|
27
|
+
* @returns Promise<boolean>
|
|
28
|
+
*/
|
|
29
|
+
export declare function isImageExists(src: string, img?: HTMLImageElement): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* 从Content-Disposition中获取文件名
|
|
32
|
+
* @param header 包含Content-Disposition, 值为'attachment;filename=%E5%A4%A7%E8%A1%8C%E6%8C%87%E5%AF%BC2024-06-27-2024-06-28.xlsx'
|
|
33
|
+
* @returns string
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare function getFilenameFromContentDispositionHeader(header: {
|
|
37
|
+
['content-disposition']: string;
|
|
38
|
+
}): string;
|
|
39
|
+
declare const HyperLinkTargets: readonly ["_self", "_blank", "_parent", "_top"];
|
|
40
|
+
export declare type HyperLinkTarget = (typeof HyperLinkTargets)[number];
|
|
41
|
+
export declare function download(source: Blob, fileName?: string): void;
|
|
42
|
+
export declare function download(source: string, fileName?: string, target?: HyperLinkTarget): void;
|
|
43
|
+
/**
|
|
44
|
+
* 通过创建iframe进行文件下载
|
|
45
|
+
* @param source
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function downloadFileByIframe(source: string): boolean;
|
|
49
|
+
export {};
|