win-chart 2.13.0 → 3.0.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.
Files changed (62) hide show
  1. package/README.md +55 -7
  2. package/dist/cjs/components/ChartWrapper.cjs +39 -0
  3. package/dist/cjs/components/EarthChart.cjs +168 -0
  4. package/dist/cjs/components/GanttChart.cjs +302 -0
  5. package/dist/cjs/components/WinChart.cjs +125 -0
  6. package/dist/cjs/index.cjs +58 -0
  7. package/dist/cjs/types/index.cjs +51 -0
  8. package/dist/cjs/utils/const.cjs +68 -0
  9. package/dist/cjs/utils/data.cjs +9382 -0
  10. package/dist/cjs/utils/earthMockData.cjs +6017 -0
  11. package/dist/cjs/utils/getAreaSpec.cjs +143 -0
  12. package/dist/cjs/utils/getBarSpec.cjs +171 -0
  13. package/dist/cjs/utils/getChartOptions.cjs +78 -0
  14. package/dist/cjs/utils/getColumnSpec.cjs +127 -0
  15. package/dist/cjs/utils/getDualSpec.cjs +171 -0
  16. package/dist/cjs/utils/getFunnelSpec.cjs +89 -0
  17. package/dist/cjs/utils/getLineSpec.cjs +72 -0
  18. package/dist/cjs/utils/getPieSpec.cjs +140 -0
  19. package/dist/cjs/utils/getRadarSpec.cjs +100 -0
  20. package/dist/cjs/utils/tool.cjs +240 -0
  21. package/dist/esm/components/ChartWrapper.js +5 -0
  22. package/dist/esm/components/EarthChart.js +134 -0
  23. package/dist/esm/components/GanttChart.js +268 -0
  24. package/dist/esm/components/WinChart.js +79 -0
  25. package/dist/esm/index.js +6 -0
  26. package/dist/esm/types/index.js +17 -0
  27. package/dist/esm/utils/const.js +31 -0
  28. package/dist/esm/utils/data.js +9342 -0
  29. package/dist/esm/utils/earthMockData.js +5983 -0
  30. package/dist/esm/utils/getAreaSpec.js +106 -0
  31. package/dist/esm/utils/getBarSpec.js +134 -0
  32. package/dist/esm/utils/getChartOptions.js +44 -0
  33. package/dist/esm/utils/getColumnSpec.js +90 -0
  34. package/dist/esm/utils/getDualSpec.js +134 -0
  35. package/dist/esm/utils/getFunnelSpec.js +55 -0
  36. package/dist/esm/utils/getLineSpec.js +38 -0
  37. package/dist/esm/utils/getPieSpec.js +103 -0
  38. package/dist/esm/utils/getRadarSpec.js +66 -0
  39. package/dist/esm/utils/tool.js +146 -0
  40. package/dist/index.js +1219 -0
  41. package/dist/types/components/GanttChart.d.ts +0 -1
  42. package/dist/types/demos/DualSystemComparisonChart.d.ts +1 -0
  43. package/dist/types/demos/EastWestResourceComparisonChart.d.ts +1 -0
  44. package/dist/types/demos/PolicyGrowthChart.d.ts +1 -0
  45. package/dist/types/demos/PolicyOpennessChart.d.ts +1 -0
  46. package/dist/types/demos/PracticalUsageTrendChart.d.ts +1 -0
  47. package/dist/types/demos/index.d.ts +5 -0
  48. package/dist/types/types/index.d.ts +14 -14
  49. package/dist/types/utils/getAreaSpec.d.ts +1 -1
  50. package/dist/types/utils/getBarSpec.d.ts +1 -1
  51. package/dist/types/utils/getChartOptions.d.ts +1 -1
  52. package/dist/types/utils/getColumnSpec.d.ts +1 -1
  53. package/dist/types/utils/getDualSpec.d.ts +1 -1
  54. package/dist/types/utils/getFunnelSpec.d.ts +1 -1
  55. package/dist/types/utils/getLineSpec.d.ts +1 -1
  56. package/dist/types/utils/getPieSpec.d.ts +1 -1
  57. package/dist/types/utils/getRadarSpec.d.ts +1 -1
  58. package/dist/types/utils/tool.d.ts +59 -3
  59. package/package.json +33 -32
  60. package/dist/bundle.esm.js +0 -22
  61. package/dist/index.d.ts +0 -147
  62. package/dist/types/app.d.ts +0 -1
@@ -0,0 +1,103 @@
1
+ import { arraySum, dataDescOrder, getLabelColor, handleToPercent } from "./tool.js";
2
+ const getPieOpt = (winChartProps)=>{
3
+ const total = arraySum(winChartProps.data?.map((item)=>item.value));
4
+ return {
5
+ tooltip: {
6
+ trigger: 'item'
7
+ },
8
+ legend: {
9
+ bottom: 0,
10
+ type: 'scroll'
11
+ },
12
+ series: [
13
+ {
14
+ top: -30,
15
+ type: 'pie',
16
+ radius: '50%',
17
+ data: dataDescOrder(winChartProps.data)?.map((item)=>({
18
+ value: item.value,
19
+ name: winChartProps.reserveValueWithLabelType ? item.label : item.type
20
+ })),
21
+ label: {
22
+ show: true,
23
+ fontSize: 12,
24
+ color: getLabelColor(winChartProps),
25
+ position: 'outside',
26
+ formatter: (data)=>handleToPercent(data.value / (total || 1))
27
+ },
28
+ emphasis: {
29
+ itemStyle: {
30
+ shadowBlur: 10,
31
+ shadowOffsetX: 0,
32
+ shadowColor: 'rgba(0, 0, 0, 0.5)'
33
+ }
34
+ }
35
+ }
36
+ ]
37
+ };
38
+ };
39
+ const getPieCycleOpt = (winChartProps)=>{
40
+ const total = arraySum(winChartProps.data?.map((item)=>item.value));
41
+ return {
42
+ tooltip: {
43
+ trigger: 'item'
44
+ },
45
+ legend: {
46
+ bottom: 0,
47
+ type: 'scroll'
48
+ },
49
+ series: [
50
+ {
51
+ top: -30,
52
+ type: 'pie',
53
+ radius: [
54
+ '60%',
55
+ '48%'
56
+ ],
57
+ data: dataDescOrder(winChartProps.data, winChartProps.sort)?.map((item)=>({
58
+ value: item.value,
59
+ name: winChartProps.reserveValueWithLabelType ? item.label : item.type
60
+ })),
61
+ label: {
62
+ show: true,
63
+ fontSize: 12,
64
+ color: getLabelColor(winChartProps),
65
+ position: 'outside',
66
+ formatter: (data)=>handleToPercent(data.value / (total || 1))
67
+ },
68
+ emphasis: {
69
+ itemStyle: {
70
+ shadowBlur: 10,
71
+ shadowOffsetX: 0,
72
+ shadowColor: 'rgba(0, 0, 0, 0.5)'
73
+ }
74
+ }
75
+ }
76
+ ],
77
+ graphic: [
78
+ {
79
+ type: 'text',
80
+ left: 'center',
81
+ top: winChartProps.cycleCenterConfig?.content?.top ?? 76,
82
+ style: {
83
+ text: winChartProps.cycleCenterConfig?.content?.value ?? Number(total.toFixed(2)).toString(),
84
+ fill: 'dark' === winChartProps.theme ? '#fff' : '#12161F',
85
+ fontFamily: 'roboto',
86
+ fontSize: winChartProps.cycleCenterConfig?.content?.fontSize ?? 28,
87
+ fontWeight: 'bold'
88
+ }
89
+ },
90
+ {
91
+ type: 'text',
92
+ left: 'center',
93
+ top: winChartProps.cycleCenterConfig?.title?.top ?? 112,
94
+ style: {
95
+ text: winChartProps.cycleCenterConfig?.title?.value ?? '总计',
96
+ fill: 'dark' === winChartProps.theme ? '#fff' : '#394252 ',
97
+ fontSize: winChartProps.cycleCenterConfig?.title?.fontSize ?? 14
98
+ }
99
+ }
100
+ ]
101
+ };
102
+ };
103
+ export { getPieCycleOpt, getPieOpt };
@@ -0,0 +1,66 @@
1
+ import { rgba } from "polished";
2
+ import { COLOR_LIST } from "./const.js";
3
+ import { arrDeduplication } from "./tool.js";
4
+ const getRadarOpt = (winChartProps)=>{
5
+ const typeList = arrDeduplication(winChartProps.data?.map((item)=>winChartProps.reserveValueWithLabelType ? item.label : item.type));
6
+ return {
7
+ tooltip: {
8
+ trigger: 'item'
9
+ },
10
+ legend: {
11
+ bottom: 0,
12
+ type: 'scroll'
13
+ },
14
+ radar: {
15
+ shape: 'circle',
16
+ radius: '60%',
17
+ indicator: arrDeduplication(winChartProps.data?.map((item)=>winChartProps.reserveValueWithLabelType ? item.type : item.label)).map((name)=>({
18
+ name
19
+ })),
20
+ axisName: {
21
+ color: '#5d677a'
22
+ },
23
+ splitArea: {
24
+ areaStyle: {
25
+ color: [
26
+ 'transparent'
27
+ ]
28
+ }
29
+ },
30
+ axisLine: {
31
+ lineStyle: {
32
+ color: 'rgba(226, 229, 235, .3)'
33
+ }
34
+ },
35
+ splitLine: {
36
+ lineStyle: {
37
+ color: '#e2e5eb',
38
+ type: 'dashed',
39
+ dashOffset: 1.5
40
+ }
41
+ }
42
+ },
43
+ series: [
44
+ {
45
+ type: 'radar',
46
+ data: typeList.map((name, index)=>({
47
+ name,
48
+ value: winChartProps.data?.filter((item)=>winChartProps.reserveValueWithLabelType ? item.label : item.type === name).map((item)=>item.value),
49
+ areaStyle: {
50
+ color: rgba(COLOR_LIST[index], 0.2)
51
+ },
52
+ label: {
53
+ show: winChartProps.reserveValueWithLabelType,
54
+ formatter: (params)=>params.value?.toString()
55
+ }
56
+ })),
57
+ emphasis: {
58
+ lineStyle: {
59
+ width: 4
60
+ }
61
+ }
62
+ }
63
+ ]
64
+ };
65
+ };
66
+ export { getRadarOpt };
@@ -0,0 +1,146 @@
1
+ import { graphic } from "echarts";
2
+ import { rgba } from "polished";
3
+ function isNonEmptyArray(data) {
4
+ return Array.isArray(data) && data.length > 0;
5
+ }
6
+ const handleToPercent = (value, num = 2)=>'number' == typeof value ? `${Number((100 * value).toFixed(num))}%` : '-%';
7
+ function arrDeduplication(data) {
8
+ if (Array.isArray(data)) return [
9
+ ...new Set(data)
10
+ ];
11
+ return [];
12
+ }
13
+ const arraySum = (list)=>{
14
+ if (Array.isArray(list) && 0 !== list.length) return list.reduce((a, b)=>{
15
+ const temp = Number(b);
16
+ return a + (Object.is(temp, NaN) ? 0 : temp);
17
+ }, 0);
18
+ return 0;
19
+ };
20
+ const checkEntityArr = (data)=>Array.isArray(data) && data.length > 0;
21
+ const dataDescOrder = (data, order = 'desc')=>{
22
+ if (Array.isArray(data) && 'asc' === order) {
23
+ const _data = JSON.parse(JSON.stringify(data));
24
+ return _data.sort((a, b)=>a.value - b.value);
25
+ }
26
+ if (Array.isArray(data) && 'desc' === order) {
27
+ const _data = JSON.parse(JSON.stringify(data));
28
+ return _data.sort((a, b)=>b.value - a.value);
29
+ }
30
+ return data;
31
+ };
32
+ const getMainAxisLabels = (winChartProps)=>{
33
+ const data = [
34
+ ...winChartProps.data ?? [],
35
+ ...winChartProps.extraData ?? []
36
+ ];
37
+ return arrDeduplication(data.map((item)=>item.label));
38
+ };
39
+ const getDataTypes = (winChartProps)=>arrDeduplication(winChartProps.data?.filter((item)=>!!item.type).map((item)=>item.type)) ?? [];
40
+ const getExtraDataTypes = (winChartProps)=>arrDeduplication(winChartProps.extraData?.filter((item)=>!!item.type).map((item)=>item.type)) ?? [];
41
+ const getSeriesDataByType = (winChartProps, type)=>{
42
+ const data = [
43
+ ...winChartProps.data ?? [],
44
+ ...winChartProps.extraData ?? []
45
+ ];
46
+ return getMainAxisLabels(winChartProps).map((label)=>data.find((item)=>item.type === type && item.label === label)?.value ?? 0);
47
+ };
48
+ const getSeriesLabelConfig = (winChartProps)=>winChartProps.showLabel ? {
49
+ show: true,
50
+ formatter: '{c}',
51
+ position: 'top',
52
+ showSymbol: true
53
+ } : {
54
+ show: false
55
+ };
56
+ const handleMainAxisLabel = (winChartProps, name)=>{
57
+ const configLength = winChartProps.xAxisLabelLength;
58
+ if ('number' == typeof configLength && name.length > configLength) return `${name.slice(0, configLength)}...`;
59
+ return name;
60
+ };
61
+ const getXAxisOpt = (winChartProps)=>({
62
+ boundaryGap: true,
63
+ axisTick: {
64
+ alignWithLabel: true
65
+ },
66
+ data: getMainAxisLabels(winChartProps),
67
+ axisLabel: {
68
+ rotate: winChartProps.xAxisLabelRotate,
69
+ formatter: (name)=>handleMainAxisLabel(winChartProps, name)
70
+ }
71
+ });
72
+ const getGradientColor = (winChartProps, color)=>{
73
+ const gradientColor = new graphic.LinearGradient(0, 0, 0, 1, [
74
+ {
75
+ offset: 0,
76
+ color: rgba(color, 0.5)
77
+ },
78
+ {
79
+ offset: 1,
80
+ color: 'dark' === winChartProps.theme ? rgba('gray', 0.1) : '#fff'
81
+ }
82
+ ]);
83
+ return gradientColor;
84
+ };
85
+ const sortArray = (arr, order)=>{
86
+ if ('asc' === order) arr.sort((a, b)=>a.value - b.value);
87
+ else if ('desc' === order) arr.sort((a, b)=>b.value - a.value);
88
+ return arr;
89
+ };
90
+ const sortArrayByLabel = (arr, sortedLabels)=>{
91
+ arr.sort((a, b)=>{
92
+ const indexA = sortedLabels.indexOf(a.label);
93
+ const indexB = sortedLabels.indexOf(b.label);
94
+ return indexA - indexB;
95
+ });
96
+ return arr;
97
+ };
98
+ const handleSort = (winChartProps)=>{
99
+ const { data, extraData, sort } = winChartProps;
100
+ if (data && sort) {
101
+ const sortedData = sortArray([
102
+ ...data
103
+ ], sort);
104
+ const sortedLabels = arrDeduplication(sortedData.map((item)=>item.label));
105
+ const finalSortData = sortArrayByLabel(sortedData, sortedLabels);
106
+ const finalSortedExtraData = sortArrayByLabel([
107
+ ...extraData ?? []
108
+ ], sortedLabels);
109
+ return {
110
+ ...winChartProps,
111
+ data: finalSortData,
112
+ extraData: finalSortedExtraData
113
+ };
114
+ }
115
+ return winChartProps;
116
+ };
117
+ function debounce(func, delay) {
118
+ let timer = null;
119
+ return function(...args) {
120
+ clearTimeout(timer);
121
+ timer = setTimeout(()=>{
122
+ func.apply(globalThis, args);
123
+ }, delay);
124
+ };
125
+ }
126
+ const mergeSeriesOption = (option, seriesOption)=>{
127
+ if (isNonEmptyArray(option.series) && isNonEmptyArray(seriesOption)) seriesOption.forEach((config)=>{
128
+ option.series = option.series.map((item)=>({
129
+ ...item,
130
+ ...item.name === config.name && config
131
+ }));
132
+ });
133
+ return option;
134
+ };
135
+ const getLabelColor = (opt)=>'dark' === opt.theme ? 'rgba(255, 255, 255, 0.7)' : 'rgba(0, 0, 0, 0.7)';
136
+ function aggregateStackData(data) {
137
+ const result = data.reduce((acc, item)=>{
138
+ const { label, value } = item;
139
+ if (!acc[label]) acc[label] = 0;
140
+ if (value) acc[label] += Number(value);
141
+ return acc;
142
+ }, {});
143
+ const totals = Object.values(result).map((totalValue)=>parseFloat(totalValue.toFixed(2)));
144
+ return totals;
145
+ }
146
+ export { aggregateStackData, arrDeduplication, arraySum, checkEntityArr, dataDescOrder, debounce, getDataTypes, getExtraDataTypes, getGradientColor, getLabelColor, getMainAxisLabels, getSeriesDataByType, getSeriesLabelConfig, getXAxisOpt, handleMainAxisLabel, handleSort, handleToPercent, isNonEmptyArray, mergeSeriesOption, sortArray, sortArrayByLabel };