@d-matrix/utils 1.17.0 → 1.17.1
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/echarts.d.ts +5 -2
- package/dist/echarts.js +6 -5
- package/package.json +1 -1
- package/readme.md +1 -1
package/dist/echarts.d.ts
CHANGED
|
@@ -17,17 +17,20 @@ export declare function fill<T extends Record<string, any>, XAxisField extends k
|
|
|
17
17
|
* 判断max-min是否被5等分(是否小于0.01),小于0.01表示不能被5等分,基础倍率增加0.1后,再次判断,直到被5等分
|
|
18
18
|
* @param first
|
|
19
19
|
* @param maxDiff
|
|
20
|
+
* @param decimalPlaces
|
|
21
|
+
* @param splitNumber
|
|
20
22
|
* @returns 最大差值倍率
|
|
21
23
|
*/
|
|
22
|
-
export declare const getDiffRate: (first: number, maxDiff: number, splitNumber?: number) => number;
|
|
24
|
+
export declare const getDiffRate: (first: number, maxDiff: number, decimalPlaces?: number, splitNumber?: number) => number;
|
|
23
25
|
/**
|
|
24
26
|
* 计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置
|
|
25
27
|
* @param data 原始数据
|
|
26
28
|
* @param key Y轴字段
|
|
29
|
+
* @param decimalPlaces Y轴值的精度(小数位数)
|
|
27
30
|
* @param splitNumber Y轴splitNumber属性
|
|
28
31
|
* @returns
|
|
29
32
|
*/
|
|
30
|
-
export declare function calcYAxisRange<T extends Record<string, any>, Key extends keyof T>(data: T[], key: Key, splitNumber?: number): {
|
|
33
|
+
export declare function calcYAxisRange<T extends Record<string, any>, Key extends keyof T>(data: T[], key: Key, decimalPlaces?: number, splitNumber?: number): {
|
|
31
34
|
max: number;
|
|
32
35
|
min: number;
|
|
33
36
|
};
|
package/dist/echarts.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
-
import Decimal from 'decimal.js-light';
|
|
3
2
|
import deepmerge from 'deepmerge';
|
|
4
3
|
import { trueTypeOf } from './operator';
|
|
5
4
|
const combineMerge = (target, source, options) => {
|
|
@@ -63,13 +62,14 @@ export function fill(dataSource, xAxisField, yAxisField) {
|
|
|
63
62
|
* 判断max-min是否被5等分(是否小于0.01),小于0.01表示不能被5等分,基础倍率增加0.1后,再次判断,直到被5等分
|
|
64
63
|
* @param first
|
|
65
64
|
* @param maxDiff
|
|
65
|
+
* @param decimalPlaces
|
|
66
|
+
* @param splitNumber
|
|
66
67
|
* @returns 最大差值倍率
|
|
67
68
|
*/
|
|
68
|
-
export const getDiffRate = (first, maxDiff, splitNumber = 5) => {
|
|
69
|
+
export const getDiffRate = (first, maxDiff, decimalPlaces = 2, splitNumber = 5) => {
|
|
69
70
|
let diffRate = 1.2;
|
|
70
71
|
if (first === 0)
|
|
71
72
|
return diffRate;
|
|
72
|
-
const decimalPlaces = new Decimal(first).dp();
|
|
73
73
|
const minDiff = 1 / Math.pow(10, decimalPlaces);
|
|
74
74
|
function calc(f, d) {
|
|
75
75
|
const max = f + d * diffRate;
|
|
@@ -86,10 +86,11 @@ export const getDiffRate = (first, maxDiff, splitNumber = 5) => {
|
|
|
86
86
|
* 计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置
|
|
87
87
|
* @param data 原始数据
|
|
88
88
|
* @param key Y轴字段
|
|
89
|
+
* @param decimalPlaces Y轴值的精度(小数位数)
|
|
89
90
|
* @param splitNumber Y轴splitNumber属性
|
|
90
91
|
* @returns
|
|
91
92
|
*/
|
|
92
|
-
export function calcYAxisRange(data, key, splitNumber = 5) {
|
|
93
|
+
export function calcYAxisRange(data, key, decimalPlaces = 2, splitNumber = 5) {
|
|
93
94
|
var _a, _b;
|
|
94
95
|
const maxValue = (_a = Math.max(...data.map((o) => o[key]))) !== null && _a !== void 0 ? _a : 0;
|
|
95
96
|
const minValue = (_b = Math.min(...data.map((o) => o[key]))) !== null && _b !== void 0 ? _b : 0;
|
|
@@ -104,7 +105,7 @@ export function calcYAxisRange(data, key, splitNumber = 5) {
|
|
|
104
105
|
// 例如:first = 1, max = 1.3, min = 0.6, maxDiff = abs(min - first) = 0.4
|
|
105
106
|
const maxDiff = Math.max(Math.abs(maxValue - firstValue), Math.abs(minValue - firstValue));
|
|
106
107
|
// 差值缩放比例
|
|
107
|
-
const diffRate = getDiffRate(firstValue, maxDiff, splitNumber);
|
|
108
|
+
const diffRate = getDiffRate(firstValue, maxDiff, decimalPlaces, splitNumber);
|
|
108
109
|
const max = firstValue + (maxDiff === 0 ? firstValue / 6 : maxDiff * diffRate);
|
|
109
110
|
const min = firstValue - (maxDiff === 0 ? firstValue / 6 : maxDiff * diffRate);
|
|
110
111
|
return { max, min };
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -446,7 +446,7 @@ deep merge Echarts配置,用法见[测试用例](./tests//echarts/echarts.cy.t
|
|
|
446
446
|
|
|
447
447
|
填充的点的Y轴值为前一个点的值, 时间示例: [9:23, 9:27] => [9:23, 9:25, 9:27, 9:30],更多,见[测试用例](./tests/echarts/fill.cy.ts)
|
|
448
448
|
|
|
449
|
-
- `calcYAxisRange<T extends Record<string, any>, Key extends keyof T>(data: T[], key: Key, splitNumber = 5): { max:number; min:number }`
|
|
449
|
+
- `calcYAxisRange<T extends Record<string, any>, Key extends keyof T>(data: T[], key: Key, decimalPlaces = 2, splitNumber = 5): { max:number; min:number }`
|
|
450
450
|
|
|
451
451
|
计算echarts YAxis的max和min属性,以达到根据实际数据动态调整,使折线图的波动明显。且第一个点始终在Y轴中间位置,[效果图](https://raw.githubusercontent.com/mrdulin/pic-bucket-01/master/Dingtalk_20240724140535.jpg)
|
|
452
452
|
|