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,106 @@
1
+ import { COLOR_LIST } from "./const.js";
2
+ import { getDataTypes, getGradientColor, getMainAxisLabels, getSeriesDataByType, getSeriesLabelConfig, getXAxisOpt } from "./tool.js";
3
+ const getMiniAreaOpt = (winChartProps)=>{
4
+ const areaTypeList = getDataTypes(winChartProps);
5
+ const color = winChartProps.color;
6
+ return {
7
+ color,
8
+ grid: {
9
+ top: 4,
10
+ left: 0,
11
+ right: 0,
12
+ bottom: 0,
13
+ containLabel: true
14
+ },
15
+ tooltip: {
16
+ trigger: 'axis',
17
+ axisPointer: {
18
+ type: 'cross',
19
+ label: {
20
+ backgroundColor: '#999'
21
+ }
22
+ }
23
+ },
24
+ legend: {
25
+ show: false
26
+ },
27
+ xAxis: {
28
+ show: false,
29
+ boundaryGap: false,
30
+ data: getMainAxisLabels(winChartProps)
31
+ },
32
+ yAxis: {
33
+ show: false,
34
+ min: winChartProps.yStart?.at(0)
35
+ },
36
+ series: [
37
+ ...areaTypeList.map((type, index)=>{
38
+ const areaColor = color?.[index] ?? COLOR_LIST[index];
39
+ return {
40
+ name: type,
41
+ type: 'line',
42
+ smooth: true,
43
+ lineStyle: {
44
+ width: 2
45
+ },
46
+ showSymbol: false,
47
+ areaStyle: {
48
+ opacity: 0.8,
49
+ color: getGradientColor(winChartProps, areaColor)
50
+ },
51
+ emphasis: {
52
+ focus: 'series'
53
+ },
54
+ label: getSeriesLabelConfig(winChartProps),
55
+ data: getSeriesDataByType(winChartProps, type)
56
+ };
57
+ })
58
+ ]
59
+ };
60
+ };
61
+ const getAreaOpt = (winChartProps)=>{
62
+ const areaTypeList = getDataTypes(winChartProps);
63
+ return {
64
+ tooltip: {
65
+ trigger: 'axis',
66
+ axisPointer: {
67
+ type: 'cross',
68
+ label: {
69
+ backgroundColor: '#999'
70
+ }
71
+ }
72
+ },
73
+ legend: {
74
+ bottom: 0,
75
+ type: 'scroll'
76
+ },
77
+ xAxis: getXAxisOpt(winChartProps),
78
+ yAxis: {
79
+ min: winChartProps.yStart?.at(0)
80
+ },
81
+ series: [
82
+ ...areaTypeList.map((type, index)=>{
83
+ const areaColor = COLOR_LIST[index];
84
+ return {
85
+ name: type,
86
+ type: 'line',
87
+ smooth: true,
88
+ lineStyle: {
89
+ width: 2
90
+ },
91
+ areaStyle: {
92
+ opacity: 0.8,
93
+ color: getGradientColor(winChartProps, areaColor)
94
+ },
95
+ emphasis: {
96
+ focus: 'series'
97
+ },
98
+ showSymbol: winChartProps.showLabel,
99
+ label: getSeriesLabelConfig(winChartProps),
100
+ data: getSeriesDataByType(winChartProps, type)
101
+ };
102
+ })
103
+ ]
104
+ };
105
+ };
106
+ export { getAreaOpt, getMiniAreaOpt };
@@ -0,0 +1,134 @@
1
+ import { aggregateStackData, arraySum, getDataTypes, getMainAxisLabels, getSeriesDataByType, getSeriesLabelConfig, handleMainAxisLabel } from "./tool.js";
2
+ const getBarOpt = (winChartProps)=>({
3
+ tooltip: {
4
+ trigger: 'axis',
5
+ axisPointer: {
6
+ type: 'cross',
7
+ label: {
8
+ backgroundColor: '#999'
9
+ }
10
+ }
11
+ },
12
+ legend: {
13
+ bottom: 0,
14
+ type: 'scroll'
15
+ },
16
+ xAxis: {},
17
+ yAxis: {
18
+ data: getMainAxisLabels(winChartProps),
19
+ axisTick: {
20
+ alignWithLabel: true
21
+ },
22
+ axisPointer: {
23
+ type: 'shadow'
24
+ },
25
+ min: winChartProps.yStart?.[0],
26
+ axisLabel: {
27
+ rotate: winChartProps.xAxisLabelRotate,
28
+ formatter: (name)=>handleMainAxisLabel(winChartProps, name)
29
+ }
30
+ },
31
+ series: getDataTypes(winChartProps).map((type)=>({
32
+ name: type,
33
+ type: 'bar',
34
+ barGap: '30%',
35
+ barCategoryGap: '30%',
36
+ barMaxWidth: 8,
37
+ label: {
38
+ ...getSeriesLabelConfig(winChartProps),
39
+ position: 'right'
40
+ },
41
+ data: getSeriesDataByType(winChartProps, type).map((item)=>({
42
+ value: item,
43
+ itemStyle: {
44
+ borderRadius: [
45
+ 0,
46
+ 500,
47
+ 500,
48
+ 0
49
+ ]
50
+ }
51
+ }))
52
+ }))
53
+ });
54
+ const getStackBarOpt = (winChartProps)=>{
55
+ const barTypeList = getDataTypes(winChartProps);
56
+ return {
57
+ grid: {
58
+ ...winChartProps.showStackTotal && {
59
+ right: 32
60
+ }
61
+ },
62
+ tooltip: {
63
+ trigger: 'axis',
64
+ axisPointer: {
65
+ type: 'cross',
66
+ label: {
67
+ backgroundColor: '#999'
68
+ }
69
+ }
70
+ },
71
+ legend: {
72
+ bottom: 0,
73
+ type: 'scroll',
74
+ data: barTypeList
75
+ },
76
+ xAxis: {},
77
+ yAxis: {
78
+ data: getMainAxisLabels(winChartProps),
79
+ axisTick: {
80
+ alignWithLabel: true
81
+ },
82
+ axisPointer: {
83
+ type: 'shadow'
84
+ },
85
+ min: winChartProps.yStart?.[0],
86
+ axisLabel: {
87
+ rotate: winChartProps.xAxisLabelRotate,
88
+ formatter: (name)=>handleMainAxisLabel(winChartProps, name)
89
+ }
90
+ },
91
+ series: [
92
+ ...barTypeList.map((type)=>({
93
+ name: type,
94
+ type: 'bar',
95
+ stack: 'total',
96
+ barGap: '30%',
97
+ barCategoryGap: '30%',
98
+ barMaxWidth: 8,
99
+ label: {
100
+ ...getSeriesLabelConfig(winChartProps),
101
+ show: winChartProps.showLabel && !winChartProps.showStackTotal,
102
+ position: 'right'
103
+ },
104
+ data: getSeriesDataByType(winChartProps, type)
105
+ })),
106
+ {
107
+ name: '总和',
108
+ type: 'bar',
109
+ stack: 'abc',
110
+ barGap: '-100%',
111
+ barMaxWidth: 8,
112
+ itemStyle: {
113
+ normal: {
114
+ color: 'transparent'
115
+ }
116
+ },
117
+ tooltip: {
118
+ show: false
119
+ },
120
+ label: {
121
+ show: winChartProps.showStackTotal,
122
+ normal: {
123
+ show: true,
124
+ position: 'right',
125
+ color: '#000'
126
+ },
127
+ formatter: (params)=>String(Number(arraySum(winChartProps.data?.filter((item)=>item.label === params.name).map((item)=>item.value)).toFixed(2)))
128
+ },
129
+ data: aggregateStackData(winChartProps.data ?? [])
130
+ }
131
+ ]
132
+ };
133
+ };
134
+ export { getBarOpt, getStackBarOpt };
@@ -0,0 +1,44 @@
1
+ import { WinChartType } from "../types/index.js";
2
+ import { getAreaOpt, getMiniAreaOpt } from "./getAreaSpec.js";
3
+ import { getDualOpt, getStackDualOpt } from "./getDualSpec.js";
4
+ import { getPieCycleOpt, getPieOpt } from "./getPieSpec.js";
5
+ import { getLineOpt } from "./getLineSpec.js";
6
+ import { getColumnOpt, getColumnStackOpt } from "./getColumnSpec.js";
7
+ import { getFunnelOpt } from "./getFunnelSpec.js";
8
+ import { getBarOpt, getStackBarOpt } from "./getBarSpec.js";
9
+ import { handleSort } from "./tool.js";
10
+ import { getRadarOpt } from "./getRadarSpec.js";
11
+ const getEChartOptions = (originWinChartProps)=>{
12
+ const winChartProps = handleSort(originWinChartProps);
13
+ switch(winChartProps.chartType){
14
+ case WinChartType.MINI_AREA:
15
+ return getMiniAreaOpt(winChartProps);
16
+ case WinChartType.AREA:
17
+ return getAreaOpt(winChartProps);
18
+ case WinChartType.LINE:
19
+ return getLineOpt(winChartProps);
20
+ case WinChartType.COLUMN:
21
+ return getColumnOpt(winChartProps);
22
+ case WinChartType.STACK_COLUMN:
23
+ return getColumnStackOpt(winChartProps);
24
+ case WinChartType.BAR:
25
+ return getBarOpt(winChartProps);
26
+ case WinChartType.STACK_BAR:
27
+ return getStackBarOpt(winChartProps);
28
+ case WinChartType.FUNNEL:
29
+ return getFunnelOpt(winChartProps);
30
+ case WinChartType.DUAL_LINE_BAR:
31
+ return getDualOpt(winChartProps);
32
+ case WinChartType.STACK_DUAL_LINE_BAR:
33
+ return getStackDualOpt(winChartProps);
34
+ case WinChartType.PIE:
35
+ return getPieOpt(winChartProps);
36
+ case WinChartType.CYCLE:
37
+ return getPieCycleOpt(winChartProps);
38
+ case WinChartType.RADAR:
39
+ return getRadarOpt(winChartProps);
40
+ default:
41
+ return {};
42
+ }
43
+ };
44
+ export { getEChartOptions };
@@ -0,0 +1,90 @@
1
+ import { getDataTypes, getSeriesDataByType, getSeriesLabelConfig, getXAxisOpt } from "./tool.js";
2
+ const getColumnOpt = (winChartProps)=>{
3
+ const barTypeList = getDataTypes(winChartProps);
4
+ return {
5
+ tooltip: {
6
+ trigger: 'axis',
7
+ axisPointer: {
8
+ type: 'cross',
9
+ label: {
10
+ backgroundColor: '#999'
11
+ }
12
+ }
13
+ },
14
+ legend: {
15
+ bottom: 0,
16
+ type: 'scroll'
17
+ },
18
+ xAxis: {
19
+ ...getXAxisOpt(winChartProps),
20
+ axisPointer: {
21
+ type: 'shadow'
22
+ }
23
+ },
24
+ yAxis: {
25
+ min: winChartProps.yStart?.[0]
26
+ },
27
+ series: barTypeList.map((type)=>({
28
+ name: type,
29
+ type: 'bar',
30
+ barGap: '30%',
31
+ barCategoryGap: '30%',
32
+ barMaxWidth: 8,
33
+ label: getSeriesLabelConfig(winChartProps),
34
+ data: getSeriesDataByType(winChartProps, type).map((item)=>({
35
+ value: item,
36
+ itemStyle: {
37
+ borderRadius: item > 0 ? [
38
+ 500,
39
+ 500,
40
+ 0,
41
+ 0
42
+ ] : [
43
+ 0,
44
+ 0,
45
+ 500,
46
+ 500
47
+ ]
48
+ }
49
+ }))
50
+ }))
51
+ };
52
+ };
53
+ const getColumnStackOpt = (winChartProps)=>{
54
+ const barTypeList = getDataTypes(winChartProps);
55
+ return {
56
+ tooltip: {
57
+ trigger: 'axis',
58
+ axisPointer: {
59
+ type: 'cross',
60
+ label: {
61
+ backgroundColor: '#999'
62
+ }
63
+ }
64
+ },
65
+ legend: {
66
+ bottom: 0,
67
+ type: 'scroll'
68
+ },
69
+ xAxis: {
70
+ ...getXAxisOpt(winChartProps),
71
+ axisPointer: {
72
+ type: 'shadow'
73
+ }
74
+ },
75
+ yAxis: {
76
+ min: winChartProps.yStart?.[0]
77
+ },
78
+ series: barTypeList.map((name)=>({
79
+ name,
80
+ type: 'bar',
81
+ stack: 'total',
82
+ barGap: '30%',
83
+ barCategoryGap: '30%',
84
+ barMaxWidth: 8,
85
+ label: getSeriesLabelConfig(winChartProps),
86
+ data: getSeriesDataByType(winChartProps, name)
87
+ }))
88
+ };
89
+ };
90
+ export { getColumnOpt, getColumnStackOpt };
@@ -0,0 +1,134 @@
1
+ import { getDataTypes, getExtraDataTypes, getSeriesDataByType, getSeriesLabelConfig, getXAxisOpt } from "./tool.js";
2
+ const getDualOpt = (winChartProps)=>{
3
+ const barTypeList = getDataTypes(winChartProps);
4
+ const lineTypeList = getExtraDataTypes(winChartProps);
5
+ return {
6
+ tooltip: {
7
+ trigger: 'axis',
8
+ axisPointer: {
9
+ type: 'cross',
10
+ crossStyle: {
11
+ color: '#999'
12
+ },
13
+ label: {
14
+ backgroundColor: '#999'
15
+ }
16
+ }
17
+ },
18
+ legend: {
19
+ bottom: 0,
20
+ type: 'scroll'
21
+ },
22
+ xAxis: {
23
+ ...getXAxisOpt(winChartProps),
24
+ axisPointer: {
25
+ type: 'shadow'
26
+ }
27
+ },
28
+ yAxis: [
29
+ {
30
+ alignTicks: true,
31
+ min: winChartProps.yStart?.[0]
32
+ },
33
+ {
34
+ alignTicks: true,
35
+ min: winChartProps.yStart?.[1]
36
+ }
37
+ ],
38
+ series: [
39
+ ...barTypeList.map((type)=>({
40
+ name: type,
41
+ type: 'bar',
42
+ barGap: '30%',
43
+ barCategoryGap: '30%',
44
+ barMaxWidth: 8,
45
+ label: getSeriesLabelConfig(winChartProps),
46
+ data: getSeriesDataByType(winChartProps, type).map((item)=>({
47
+ value: item,
48
+ itemStyle: {
49
+ borderRadius: item > 0 ? [
50
+ 500,
51
+ 500,
52
+ 0,
53
+ 0
54
+ ] : [
55
+ 0,
56
+ 0,
57
+ 500,
58
+ 500
59
+ ]
60
+ }
61
+ }))
62
+ })),
63
+ ...lineTypeList.map((type)=>({
64
+ name: type,
65
+ type: 'line',
66
+ smooth: true,
67
+ yAxisIndex: 1,
68
+ showSymbol: false,
69
+ label: getSeriesLabelConfig(winChartProps),
70
+ data: getSeriesDataByType(winChartProps, type)
71
+ }))
72
+ ]
73
+ };
74
+ };
75
+ const getStackDualOpt = (winChartProps)=>{
76
+ const barTypeList = getDataTypes(winChartProps);
77
+ const lineTypeList = getExtraDataTypes(winChartProps);
78
+ return {
79
+ tooltip: {
80
+ trigger: 'axis',
81
+ axisPointer: {
82
+ type: 'cross',
83
+ crossStyle: {
84
+ color: '#999'
85
+ },
86
+ label: {
87
+ backgroundColor: '#999'
88
+ }
89
+ }
90
+ },
91
+ legend: {
92
+ bottom: 0,
93
+ type: 'scroll'
94
+ },
95
+ xAxis: {
96
+ ...getXAxisOpt(winChartProps),
97
+ axisPointer: {
98
+ type: 'shadow'
99
+ }
100
+ },
101
+ yAxis: [
102
+ {
103
+ alignTicks: true,
104
+ min: winChartProps.yStart?.[0]
105
+ },
106
+ {
107
+ alignTicks: true,
108
+ min: winChartProps.yStart?.[1]
109
+ }
110
+ ],
111
+ series: [
112
+ ...barTypeList.map((type)=>({
113
+ name: type,
114
+ type: 'bar',
115
+ stack: 'total',
116
+ barGap: '30%',
117
+ barCategoryGap: '30%',
118
+ barMaxWidth: 8,
119
+ label: getSeriesLabelConfig(winChartProps),
120
+ data: getSeriesDataByType(winChartProps, type)
121
+ })),
122
+ ...lineTypeList.map((type)=>({
123
+ name: type,
124
+ type: 'line',
125
+ smooth: true,
126
+ yAxisIndex: 1,
127
+ showSymbol: false,
128
+ label: getSeriesLabelConfig(winChartProps),
129
+ data: getSeriesDataByType(winChartProps, type)
130
+ }))
131
+ ]
132
+ };
133
+ };
134
+ export { getDualOpt, getStackDualOpt };
@@ -0,0 +1,55 @@
1
+ import { dataDescOrder, handleToPercent } from "./tool.js";
2
+ const getFunnelOpt = (winChartProps)=>{
3
+ const data = dataDescOrder(winChartProps.data)?.map((item)=>({
4
+ value: item.value ?? 0,
5
+ name: winChartProps.reserveValueWithLabelType ? item.label : item.type
6
+ })) ?? [];
7
+ const seriesConfig = {
8
+ type: 'funnel',
9
+ minSize: '20%',
10
+ left: 10,
11
+ top: 24,
12
+ width: '76%',
13
+ sort: 'descending',
14
+ data
15
+ };
16
+ return {
17
+ tooltip: {
18
+ trigger: 'item'
19
+ },
20
+ legend: {
21
+ bottom: 0,
22
+ type: 'scroll'
23
+ },
24
+ series: [
25
+ {
26
+ ...seriesConfig,
27
+ label: {
28
+ show: true,
29
+ position: 'outer',
30
+ formatter: '{c}'
31
+ }
32
+ },
33
+ {
34
+ ...seriesConfig,
35
+ emphasis: {
36
+ label: {
37
+ fontSize: 20
38
+ }
39
+ },
40
+ label: {
41
+ show: true,
42
+ position: 'inner',
43
+ color: '#fff',
44
+ formatter: (params)=>{
45
+ const currentIndex = params.dataIndex;
46
+ if (0 === currentIndex) return '100%';
47
+ const prevValue = data[currentIndex - 1].value;
48
+ return handleToPercent(params.value / prevValue);
49
+ }
50
+ }
51
+ }
52
+ ]
53
+ };
54
+ };
55
+ export { getFunnelOpt };
@@ -0,0 +1,38 @@
1
+ import { getDataTypes, getSeriesDataByType, getSeriesLabelConfig, getXAxisOpt } from "./tool.js";
2
+ const getLineOpt = (winChartProps)=>{
3
+ const typeList = getDataTypes(winChartProps);
4
+ return {
5
+ tooltip: {
6
+ trigger: 'axis',
7
+ axisPointer: {
8
+ type: 'cross',
9
+ label: {
10
+ backgroundColor: '#999'
11
+ }
12
+ }
13
+ },
14
+ legend: {
15
+ bottom: 0,
16
+ type: 'scroll'
17
+ },
18
+ xAxis: getXAxisOpt(winChartProps),
19
+ yAxis: {
20
+ min: winChartProps.yStart?.[0]
21
+ },
22
+ series: typeList.map((type)=>({
23
+ name: type,
24
+ type: 'line',
25
+ smooth: false,
26
+ lineStyle: {
27
+ width: 2
28
+ },
29
+ showSymbol: true,
30
+ emphasis: {
31
+ focus: 'series'
32
+ },
33
+ label: getSeriesLabelConfig(winChartProps),
34
+ data: getSeriesDataByType(winChartProps, type)
35
+ }))
36
+ };
37
+ };
38
+ export { getLineOpt };