win-chart 3.0.2 → 3.0.3
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/bun/index.js +5 -0
- package/dist/bun/index.js.map +25 -0
- package/dist/bun/types/components/ChartWrapper.d.ts +1 -0
- package/dist/bun/types/components/EarthChart.d.ts +15 -0
- package/dist/bun/types/components/GanttChart.d.ts +8 -0
- package/dist/bun/types/components/WinChart.d.ts +2 -0
- package/dist/bun/types/components/__tests__/Playground.test.d.ts +1 -0
- package/dist/bun/types/components/__tests__/WinChart.test.d.ts +1 -0
- package/dist/bun/types/index.d.ts +8 -0
- package/dist/bun/types/types/index.d.ts +126 -0
- package/dist/bun/types/utils/const.d.ts +14 -0
- package/dist/bun/types/utils/data.d.ts +20 -0
- package/dist/bun/types/utils/earthMockData.d.ts +7 -0
- package/dist/bun/types/utils/getAreaSpec.d.ts +14 -0
- package/dist/bun/types/utils/getBarSpec.d.ts +14 -0
- package/dist/bun/types/utils/getChartOptions.d.ts +7 -0
- package/dist/bun/types/utils/getColumnSpec.d.ts +14 -0
- package/dist/bun/types/utils/getDualSpec.d.ts +14 -0
- package/dist/bun/types/utils/getFunnelSpec.d.ts +8 -0
- package/dist/bun/types/utils/getLineSpec.d.ts +8 -0
- package/dist/bun/types/utils/getPieSpec.d.ts +13 -0
- package/dist/bun/types/utils/getRadarSpec.d.ts +7 -0
- package/dist/bun/types/utils/tool.d.ts +140 -0
- package/dist/cjs/components/__tests__/Playground.test.cjs +90 -0
- package/dist/cjs/components/__tests__/WinChart.test.cjs +112 -0
- package/dist/cjs/stories/WinChart.stories.cjs +524 -0
- package/dist/cjs/utils/const.cjs +21 -0
- package/dist/cjs/utils/getAreaSpec.cjs +2 -18
- package/dist/cjs/utils/getBarSpec.cjs +7 -21
- package/dist/cjs/utils/getColumnSpec.cjs +3 -18
- package/dist/cjs/utils/getDualSpec.cjs +3 -24
- package/dist/cjs/utils/getFunnelSpec.cjs +2 -3
- package/dist/cjs/utils/getLineSpec.cjs +2 -9
- package/dist/cjs/utils/getPieSpec.cjs +3 -6
- package/dist/cjs/utils/getRadarSpec.cjs +1 -3
- package/dist/cjs/utils/tool.cjs +7 -4
- package/dist/esm/components/__tests__/Playground.test.js +84 -0
- package/dist/esm/components/__tests__/WinChart.test.js +106 -0
- package/dist/esm/stories/WinChart.stories.js +466 -0
- package/dist/esm/utils/const.js +16 -1
- package/dist/esm/utils/getAreaSpec.js +3 -19
- package/dist/esm/utils/getBarSpec.js +8 -22
- package/dist/esm/utils/getColumnSpec.js +3 -18
- package/dist/esm/utils/getDualSpec.js +3 -24
- package/dist/esm/utils/getFunnelSpec.js +2 -3
- package/dist/esm/utils/getLineSpec.js +2 -9
- package/dist/esm/utils/getPieSpec.js +3 -6
- package/dist/esm/utils/getRadarSpec.js +2 -4
- package/dist/esm/utils/tool.js +7 -4
- package/dist/types/components/__tests__/Playground.test.d.ts +1 -0
- package/dist/types/components/__tests__/WinChart.test.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -2
- package/dist/types/utils/const.d.ts +6 -0
- package/dist/types/utils/getDualSpec.d.ts +1 -0
- package/dist/types/utils/tool.d.ts +2 -1
- package/package.json +28 -6
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { IChartInfo, IWinChartProps } from '../types';
|
|
2
|
+
import { graphic } from 'echarts';
|
|
3
|
+
/**
|
|
4
|
+
* 判断是否为一个非空数组
|
|
5
|
+
* @param data 任意类型的数据
|
|
6
|
+
* @returns 如果是非空数组则为真
|
|
7
|
+
*/
|
|
8
|
+
export declare function isNonEmptyArray<T>(data: unknown): data is T[];
|
|
9
|
+
/**
|
|
10
|
+
* 数据转百分比
|
|
11
|
+
* @param value
|
|
12
|
+
* @param num
|
|
13
|
+
*/
|
|
14
|
+
export declare const handleToPercent: (value: unknown, num?: number) => string;
|
|
15
|
+
/**
|
|
16
|
+
* 数组去重
|
|
17
|
+
* @param data
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function arrDeduplication<T>(data?: T[]): T[];
|
|
21
|
+
/**
|
|
22
|
+
* 数组求和
|
|
23
|
+
* @param list
|
|
24
|
+
*/
|
|
25
|
+
export declare const arraySum: (list?: number[]) => number;
|
|
26
|
+
/**
|
|
27
|
+
* 判断是否为一个有效数组(有值,并且长度大于 0)
|
|
28
|
+
* @param data
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const checkEntityArr: (data: unknown) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 处理数据降序
|
|
34
|
+
* @param data
|
|
35
|
+
* @param order
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export declare const dataDescOrder: (data?: IChartInfo[], order?: "asc" | "desc") => IChartInfo[] | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* 获取 X 轴刻度
|
|
41
|
+
* @param winChartProps
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
export declare const getMainAxisLabels: (winChartProps: IWinChartProps) => string[];
|
|
45
|
+
/**
|
|
46
|
+
* 获取 type 数组
|
|
47
|
+
* @param winChartProps
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
export declare const getDataTypes: (winChartProps: IWinChartProps) => string[];
|
|
51
|
+
/**
|
|
52
|
+
* 获取 extra type 数组
|
|
53
|
+
* @param winChartProps
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export declare const getExtraDataTypes: (winChartProps: IWinChartProps) => string[];
|
|
57
|
+
/**
|
|
58
|
+
* 获取 series 数据
|
|
59
|
+
* @param winChartProps
|
|
60
|
+
* @param type
|
|
61
|
+
* @param label
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
export declare const getSeriesDataByType: (winChartProps: IWinChartProps, type: string) => number[];
|
|
65
|
+
/**
|
|
66
|
+
* 获取 series 标签
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export declare const getSeriesLabelConfig: (winChartProps: IWinChartProps) => {
|
|
70
|
+
show: boolean;
|
|
71
|
+
formatter: string;
|
|
72
|
+
position: any;
|
|
73
|
+
showSymbol: boolean;
|
|
74
|
+
} | {
|
|
75
|
+
show: boolean;
|
|
76
|
+
formatter?: undefined;
|
|
77
|
+
position?: undefined;
|
|
78
|
+
showSymbol?: undefined;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 处理主轴标签
|
|
82
|
+
* @param winChartProps
|
|
83
|
+
* @param name
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
export declare const handleMainAxisLabel: (winChartProps: IWinChartProps, name: string) => string;
|
|
87
|
+
/**
|
|
88
|
+
* 获取 X 轴配置
|
|
89
|
+
* @param winChartProps
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
export declare const getXAxisOpt: (winChartProps: IWinChartProps) => echarts.XAXisComponentOption;
|
|
93
|
+
/**
|
|
94
|
+
* 获取渐变颜色
|
|
95
|
+
* @param winChartProps
|
|
96
|
+
* @param color
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
export declare const getGradientColor: (winChartProps: IWinChartProps, color: string) => graphic.LinearGradient;
|
|
100
|
+
/**
|
|
101
|
+
* 根据 value 排序
|
|
102
|
+
* @param arr
|
|
103
|
+
* @param order
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
export declare const sortArray: (arr: IChartInfo[], order: "asc" | "desc") => IChartInfo[];
|
|
107
|
+
/**
|
|
108
|
+
* 根据 label 排序
|
|
109
|
+
* @param arr
|
|
110
|
+
* @param sortedLabels
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
export declare const sortArrayByLabel: (arr: IChartInfo[], sortedLabels: string[]) => IChartInfo[];
|
|
114
|
+
/**
|
|
115
|
+
* 处理数据排序
|
|
116
|
+
* @param winChartProps
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
export declare const handleSort: (winChartProps: IWinChartProps) => IWinChartProps;
|
|
120
|
+
export declare function debounce(func: Function, delay: number): Function;
|
|
121
|
+
/**
|
|
122
|
+
* 合并 series 配置
|
|
123
|
+
* @param option
|
|
124
|
+
* @param seriesOption
|
|
125
|
+
* @returns
|
|
126
|
+
*/
|
|
127
|
+
export declare const mergeSeriesOption: (option: Partial<echarts.EChartsOption>, seriesOption?: echarts.SeriesOption[]) => Partial<import("echarts").EChartsOption>;
|
|
128
|
+
/**
|
|
129
|
+
* 获取 label 颜色
|
|
130
|
+
* @param opt
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
export declare const getLabelColor: (opt: Partial<IWinChartProps>) => "rgba(255, 255, 255, 0.7)" | "rgba(0, 0, 0, 0.7)";
|
|
134
|
+
/**
|
|
135
|
+
* 计算堆叠图汇总数据
|
|
136
|
+
* @param data
|
|
137
|
+
* @param labels 主轴标签列表,用于保证顺序一致
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
export declare function aggregateStackData(data: IChartInfo[], labels?: string[]): number[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_exports__ = {};
|
|
3
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
4
|
+
const external_vitest_namespaceObject = require("vitest");
|
|
5
|
+
const react_namespaceObject = require("@testing-library/react");
|
|
6
|
+
const external_WinChart_cjs_namespaceObject = require("../WinChart.cjs");
|
|
7
|
+
const index_cjs_namespaceObject = require("../../types/index.cjs");
|
|
8
|
+
const mockData = [
|
|
9
|
+
{
|
|
10
|
+
label: 'Mon',
|
|
11
|
+
value: 120,
|
|
12
|
+
type: 'Series A'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: 'Tue',
|
|
16
|
+
value: 200,
|
|
17
|
+
type: 'Series A'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: 'Wed',
|
|
21
|
+
value: 150,
|
|
22
|
+
type: 'Series A'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'Thu',
|
|
26
|
+
value: 80,
|
|
27
|
+
type: 'Series A'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'Fri',
|
|
31
|
+
value: 70,
|
|
32
|
+
type: 'Series A'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'Mon',
|
|
36
|
+
value: 130,
|
|
37
|
+
type: 'Series B'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'Tue',
|
|
41
|
+
value: 180,
|
|
42
|
+
type: 'Series B'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Wed',
|
|
46
|
+
value: 160,
|
|
47
|
+
type: 'Series B'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: 'Thu',
|
|
51
|
+
value: 90,
|
|
52
|
+
type: 'Series B'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: 'Fri',
|
|
56
|
+
value: 60,
|
|
57
|
+
type: 'Series B'
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
(0, external_vitest_namespaceObject.describe)('Playground', ()=>{
|
|
61
|
+
(0, external_vitest_namespaceObject.it)('Development View', async ()=>{
|
|
62
|
+
(0, react_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
63
|
+
style: {
|
|
64
|
+
height: '500px',
|
|
65
|
+
width: '800px',
|
|
66
|
+
border: '1px solid #ccc',
|
|
67
|
+
padding: '20px'
|
|
68
|
+
},
|
|
69
|
+
children: [
|
|
70
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("h2", {
|
|
71
|
+
children: "WinChart Playground"
|
|
72
|
+
}),
|
|
73
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_WinChart_cjs_namespaceObject.WinChart, {
|
|
74
|
+
chartType: index_cjs_namespaceObject.WinChartType.LINE,
|
|
75
|
+
data: mockData,
|
|
76
|
+
extraOption: {
|
|
77
|
+
title: {
|
|
78
|
+
text: 'Development Chart'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
}));
|
|
84
|
+
await new Promise(()=>{});
|
|
85
|
+
}, 100000000);
|
|
86
|
+
});
|
|
87
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
88
|
+
Object.defineProperty(exports, '__esModule', {
|
|
89
|
+
value: true
|
|
90
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_exports__ = {};
|
|
3
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
4
|
+
const external_vitest_namespaceObject = require("vitest");
|
|
5
|
+
const react_namespaceObject = require("@testing-library/react");
|
|
6
|
+
const external_WinChart_cjs_namespaceObject = require("../WinChart.cjs");
|
|
7
|
+
const index_cjs_namespaceObject = require("../../types/index.cjs");
|
|
8
|
+
const mockData = [
|
|
9
|
+
{
|
|
10
|
+
label: 'Mon',
|
|
11
|
+
value: 12000,
|
|
12
|
+
type: 'Series A'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: 'Tue',
|
|
16
|
+
value: 200,
|
|
17
|
+
type: 'Series A'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: 'Wed',
|
|
21
|
+
value: 150,
|
|
22
|
+
type: 'Series A'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'Thu',
|
|
26
|
+
value: 80,
|
|
27
|
+
type: 'Series A'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'Fri',
|
|
31
|
+
value: 70,
|
|
32
|
+
type: 'Series A'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'Mon',
|
|
36
|
+
value: 130,
|
|
37
|
+
type: 'Series B'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'Tue',
|
|
41
|
+
value: 180,
|
|
42
|
+
type: 'Series B'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Wed',
|
|
46
|
+
value: 160,
|
|
47
|
+
type: 'Series B'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: 'Thu',
|
|
51
|
+
value: 90,
|
|
52
|
+
type: 'Series B'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: 'Fri',
|
|
56
|
+
value: 60,
|
|
57
|
+
type: 'Series B'
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
(0, external_vitest_namespaceObject.describe)('WinChart', ()=>{
|
|
61
|
+
(0, external_vitest_namespaceObject.it)('renders without crashing', ()=>{
|
|
62
|
+
(0, react_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
63
|
+
style: {
|
|
64
|
+
height: '400px',
|
|
65
|
+
width: '600px'
|
|
66
|
+
},
|
|
67
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_WinChart_cjs_namespaceObject.WinChart, {
|
|
68
|
+
chartType: index_cjs_namespaceObject.WinChartType.LINE,
|
|
69
|
+
data: mockData
|
|
70
|
+
})
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
(0, external_vitest_namespaceObject.it)('renders with title', ()=>{
|
|
74
|
+
const title = 'Test Chart';
|
|
75
|
+
(0, react_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
76
|
+
style: {
|
|
77
|
+
height: '400px',
|
|
78
|
+
width: '600px'
|
|
79
|
+
},
|
|
80
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_WinChart_cjs_namespaceObject.WinChart, {
|
|
81
|
+
chartType: index_cjs_namespaceObject.WinChartType.LINE,
|
|
82
|
+
data: mockData,
|
|
83
|
+
extraOption: {
|
|
84
|
+
title: {
|
|
85
|
+
text: title
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
style: {
|
|
89
|
+
height: 200
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
(0, external_vitest_namespaceObject.it)('renders canvas element', async ()=>{
|
|
95
|
+
const { container } = (0, react_namespaceObject.render)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
96
|
+
style: {
|
|
97
|
+
height: '400px',
|
|
98
|
+
width: '600px'
|
|
99
|
+
},
|
|
100
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_WinChart_cjs_namespaceObject.WinChart, {
|
|
101
|
+
chartType: index_cjs_namespaceObject.WinChartType.LINE,
|
|
102
|
+
data: mockData
|
|
103
|
+
})
|
|
104
|
+
}));
|
|
105
|
+
const canvas = container.querySelector('canvas');
|
|
106
|
+
(0, external_vitest_namespaceObject.expect)(canvas).toBeTruthy();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
110
|
+
Object.defineProperty(exports, '__esModule', {
|
|
111
|
+
value: true
|
|
112
|
+
});
|