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
|
@@ -28,22 +28,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
getDualOpt: ()=>getDualOpt
|
|
29
29
|
});
|
|
30
30
|
const external_tool_cjs_namespaceObject = require("./tool.cjs");
|
|
31
|
+
const external_const_cjs_namespaceObject = require("./const.cjs");
|
|
31
32
|
const getDualOpt = (winChartProps)=>{
|
|
32
33
|
const barTypeList = (0, external_tool_cjs_namespaceObject.getDataTypes)(winChartProps);
|
|
33
34
|
const lineTypeList = (0, external_tool_cjs_namespaceObject.getExtraDataTypes)(winChartProps);
|
|
34
35
|
return {
|
|
35
|
-
tooltip:
|
|
36
|
-
trigger: 'axis',
|
|
37
|
-
axisPointer: {
|
|
38
|
-
type: 'cross',
|
|
39
|
-
crossStyle: {
|
|
40
|
-
color: '#999'
|
|
41
|
-
},
|
|
42
|
-
label: {
|
|
43
|
-
backgroundColor: '#999'
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
36
|
+
tooltip: external_const_cjs_namespaceObject.COMMON_TOOLTIP_OPT,
|
|
47
37
|
legend: {
|
|
48
38
|
bottom: 0,
|
|
49
39
|
type: 'scroll'
|
|
@@ -105,18 +95,7 @@ const getStackDualOpt = (winChartProps)=>{
|
|
|
105
95
|
const barTypeList = (0, external_tool_cjs_namespaceObject.getDataTypes)(winChartProps);
|
|
106
96
|
const lineTypeList = (0, external_tool_cjs_namespaceObject.getExtraDataTypes)(winChartProps);
|
|
107
97
|
return {
|
|
108
|
-
tooltip:
|
|
109
|
-
trigger: 'axis',
|
|
110
|
-
axisPointer: {
|
|
111
|
-
type: 'cross',
|
|
112
|
-
crossStyle: {
|
|
113
|
-
color: '#999'
|
|
114
|
-
},
|
|
115
|
-
label: {
|
|
116
|
-
backgroundColor: '#999'
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
98
|
+
tooltip: external_const_cjs_namespaceObject.COMMON_TOOLTIP_OPT,
|
|
120
99
|
legend: {
|
|
121
100
|
bottom: 0,
|
|
122
101
|
type: 'scroll'
|
|
@@ -27,6 +27,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
getFunnelOpt: ()=>getFunnelOpt
|
|
28
28
|
});
|
|
29
29
|
const external_tool_cjs_namespaceObject = require("./tool.cjs");
|
|
30
|
+
const external_const_cjs_namespaceObject = require("./const.cjs");
|
|
30
31
|
const getFunnelOpt = (winChartProps)=>{
|
|
31
32
|
const data = (0, external_tool_cjs_namespaceObject.dataDescOrder)(winChartProps.data)?.map((item)=>({
|
|
32
33
|
value: item.value ?? 0,
|
|
@@ -42,9 +43,7 @@ const getFunnelOpt = (winChartProps)=>{
|
|
|
42
43
|
data
|
|
43
44
|
};
|
|
44
45
|
return {
|
|
45
|
-
tooltip:
|
|
46
|
-
trigger: 'item'
|
|
47
|
-
},
|
|
46
|
+
tooltip: external_const_cjs_namespaceObject.ITEM_TOOLTIP_OPT,
|
|
48
47
|
legend: {
|
|
49
48
|
bottom: 0,
|
|
50
49
|
type: 'scroll'
|
|
@@ -27,18 +27,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
getLineOpt: ()=>getLineOpt
|
|
28
28
|
});
|
|
29
29
|
const external_tool_cjs_namespaceObject = require("./tool.cjs");
|
|
30
|
+
const external_const_cjs_namespaceObject = require("./const.cjs");
|
|
30
31
|
const getLineOpt = (winChartProps)=>{
|
|
31
32
|
const typeList = (0, external_tool_cjs_namespaceObject.getDataTypes)(winChartProps);
|
|
32
33
|
return {
|
|
33
|
-
tooltip:
|
|
34
|
-
trigger: 'axis',
|
|
35
|
-
axisPointer: {
|
|
36
|
-
type: 'cross',
|
|
37
|
-
label: {
|
|
38
|
-
backgroundColor: '#999'
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
34
|
+
tooltip: external_const_cjs_namespaceObject.COMMON_TOOLTIP_OPT,
|
|
42
35
|
legend: {
|
|
43
36
|
bottom: 0,
|
|
44
37
|
type: 'scroll'
|
|
@@ -28,12 +28,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
getPieOpt: ()=>getPieOpt
|
|
29
29
|
});
|
|
30
30
|
const external_tool_cjs_namespaceObject = require("./tool.cjs");
|
|
31
|
+
const external_const_cjs_namespaceObject = require("./const.cjs");
|
|
31
32
|
const getPieOpt = (winChartProps)=>{
|
|
32
33
|
const total = (0, external_tool_cjs_namespaceObject.arraySum)(winChartProps.data?.map((item)=>item.value));
|
|
33
34
|
return {
|
|
34
|
-
tooltip:
|
|
35
|
-
trigger: 'item'
|
|
36
|
-
},
|
|
35
|
+
tooltip: external_const_cjs_namespaceObject.ITEM_TOOLTIP_OPT,
|
|
37
36
|
legend: {
|
|
38
37
|
bottom: 0,
|
|
39
38
|
type: 'scroll'
|
|
@@ -68,9 +67,7 @@ const getPieOpt = (winChartProps)=>{
|
|
|
68
67
|
const getPieCycleOpt = (winChartProps)=>{
|
|
69
68
|
const total = (0, external_tool_cjs_namespaceObject.arraySum)(winChartProps.data?.map((item)=>item.value));
|
|
70
69
|
return {
|
|
71
|
-
tooltip:
|
|
72
|
-
trigger: 'item'
|
|
73
|
-
},
|
|
70
|
+
tooltip: external_const_cjs_namespaceObject.ITEM_TOOLTIP_OPT,
|
|
74
71
|
legend: {
|
|
75
72
|
bottom: 0,
|
|
76
73
|
type: 'scroll'
|
|
@@ -32,9 +32,7 @@ const external_tool_cjs_namespaceObject = require("./tool.cjs");
|
|
|
32
32
|
const getRadarOpt = (winChartProps)=>{
|
|
33
33
|
const typeList = (0, external_tool_cjs_namespaceObject.arrDeduplication)(winChartProps.data?.map((item)=>winChartProps.reserveValueWithLabelType ? item.label : item.type));
|
|
34
34
|
return {
|
|
35
|
-
tooltip:
|
|
36
|
-
trigger: 'item'
|
|
37
|
-
},
|
|
35
|
+
tooltip: external_const_cjs_namespaceObject.ITEM_TOOLTIP_OPT,
|
|
38
36
|
legend: {
|
|
39
37
|
bottom: 0,
|
|
40
38
|
type: 'scroll'
|
package/dist/cjs/utils/tool.cjs
CHANGED
|
@@ -181,15 +181,18 @@ const mergeSeriesOption = (option, seriesOption)=>{
|
|
|
181
181
|
return option;
|
|
182
182
|
};
|
|
183
183
|
const getLabelColor = (opt)=>'dark' === opt.theme ? 'rgba(255, 255, 255, 0.7)' : 'rgba(0, 0, 0, 0.7)';
|
|
184
|
-
function aggregateStackData(data) {
|
|
184
|
+
function aggregateStackData(data, labels) {
|
|
185
185
|
const result = data.reduce((acc, item)=>{
|
|
186
186
|
const { label, value } = item;
|
|
187
|
-
if (
|
|
187
|
+
if (void 0 === acc[label]) acc[label] = 0;
|
|
188
188
|
if (value) acc[label] += Number(value);
|
|
189
189
|
return acc;
|
|
190
190
|
}, {});
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
if (labels && labels.length > 0) return labels.map((label)=>{
|
|
192
|
+
const val = result[label] || 0;
|
|
193
|
+
return parseFloat(val.toFixed(2));
|
|
194
|
+
});
|
|
195
|
+
return Object.values(result).map((totalValue)=>parseFloat(totalValue.toFixed(2)));
|
|
193
196
|
}
|
|
194
197
|
exports.aggregateStackData = __webpack_exports__.aggregateStackData;
|
|
195
198
|
exports.arrDeduplication = __webpack_exports__.arrDeduplication;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, it } from "vitest";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { WinChart } from "../WinChart.js";
|
|
5
|
+
import { WinChartType } from "../../types/index.js";
|
|
6
|
+
const mockData = [
|
|
7
|
+
{
|
|
8
|
+
label: 'Mon',
|
|
9
|
+
value: 120,
|
|
10
|
+
type: 'Series A'
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: 'Tue',
|
|
14
|
+
value: 200,
|
|
15
|
+
type: 'Series A'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
label: 'Wed',
|
|
19
|
+
value: 150,
|
|
20
|
+
type: 'Series A'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: 'Thu',
|
|
24
|
+
value: 80,
|
|
25
|
+
type: 'Series A'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Fri',
|
|
29
|
+
value: 70,
|
|
30
|
+
type: 'Series A'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'Mon',
|
|
34
|
+
value: 130,
|
|
35
|
+
type: 'Series B'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Tue',
|
|
39
|
+
value: 180,
|
|
40
|
+
type: 'Series B'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'Wed',
|
|
44
|
+
value: 160,
|
|
45
|
+
type: 'Series B'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: 'Thu',
|
|
49
|
+
value: 90,
|
|
50
|
+
type: 'Series B'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Fri',
|
|
54
|
+
value: 60,
|
|
55
|
+
type: 'Series B'
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
describe('Playground', ()=>{
|
|
59
|
+
it('Development View', async ()=>{
|
|
60
|
+
render(/*#__PURE__*/ jsxs("div", {
|
|
61
|
+
style: {
|
|
62
|
+
height: '500px',
|
|
63
|
+
width: '800px',
|
|
64
|
+
border: '1px solid #ccc',
|
|
65
|
+
padding: '20px'
|
|
66
|
+
},
|
|
67
|
+
children: [
|
|
68
|
+
/*#__PURE__*/ jsx("h2", {
|
|
69
|
+
children: "WinChart Playground"
|
|
70
|
+
}),
|
|
71
|
+
/*#__PURE__*/ jsx(WinChart, {
|
|
72
|
+
chartType: WinChartType.LINE,
|
|
73
|
+
data: mockData,
|
|
74
|
+
extraOption: {
|
|
75
|
+
title: {
|
|
76
|
+
text: 'Development Chart'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
}));
|
|
82
|
+
await new Promise(()=>{});
|
|
83
|
+
}, 100000000);
|
|
84
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { WinChart } from "../WinChart.js";
|
|
5
|
+
import { WinChartType } from "../../types/index.js";
|
|
6
|
+
const mockData = [
|
|
7
|
+
{
|
|
8
|
+
label: 'Mon',
|
|
9
|
+
value: 12000,
|
|
10
|
+
type: 'Series A'
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: 'Tue',
|
|
14
|
+
value: 200,
|
|
15
|
+
type: 'Series A'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
label: 'Wed',
|
|
19
|
+
value: 150,
|
|
20
|
+
type: 'Series A'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: 'Thu',
|
|
24
|
+
value: 80,
|
|
25
|
+
type: 'Series A'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Fri',
|
|
29
|
+
value: 70,
|
|
30
|
+
type: 'Series A'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'Mon',
|
|
34
|
+
value: 130,
|
|
35
|
+
type: 'Series B'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Tue',
|
|
39
|
+
value: 180,
|
|
40
|
+
type: 'Series B'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'Wed',
|
|
44
|
+
value: 160,
|
|
45
|
+
type: 'Series B'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: 'Thu',
|
|
49
|
+
value: 90,
|
|
50
|
+
type: 'Series B'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Fri',
|
|
54
|
+
value: 60,
|
|
55
|
+
type: 'Series B'
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
describe('WinChart', ()=>{
|
|
59
|
+
it('renders without crashing', ()=>{
|
|
60
|
+
render(/*#__PURE__*/ jsx("div", {
|
|
61
|
+
style: {
|
|
62
|
+
height: '400px',
|
|
63
|
+
width: '600px'
|
|
64
|
+
},
|
|
65
|
+
children: /*#__PURE__*/ jsx(WinChart, {
|
|
66
|
+
chartType: WinChartType.LINE,
|
|
67
|
+
data: mockData
|
|
68
|
+
})
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
it('renders with title', ()=>{
|
|
72
|
+
const title = 'Test Chart';
|
|
73
|
+
render(/*#__PURE__*/ jsx("div", {
|
|
74
|
+
style: {
|
|
75
|
+
height: '400px',
|
|
76
|
+
width: '600px'
|
|
77
|
+
},
|
|
78
|
+
children: /*#__PURE__*/ jsx(WinChart, {
|
|
79
|
+
chartType: WinChartType.LINE,
|
|
80
|
+
data: mockData,
|
|
81
|
+
extraOption: {
|
|
82
|
+
title: {
|
|
83
|
+
text: title
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
style: {
|
|
87
|
+
height: 200
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
it('renders canvas element', async ()=>{
|
|
93
|
+
const { container } = render(/*#__PURE__*/ jsx("div", {
|
|
94
|
+
style: {
|
|
95
|
+
height: '400px',
|
|
96
|
+
width: '600px'
|
|
97
|
+
},
|
|
98
|
+
children: /*#__PURE__*/ jsx(WinChart, {
|
|
99
|
+
chartType: WinChartType.LINE,
|
|
100
|
+
data: mockData
|
|
101
|
+
})
|
|
102
|
+
}));
|
|
103
|
+
const canvas = container.querySelector('canvas');
|
|
104
|
+
expect(canvas).toBeTruthy();
|
|
105
|
+
});
|
|
106
|
+
});
|