Skip to content

Commit 818c5e4

Browse files
committed
feat: add test unit and comment
1 parent 9aada8b commit 818c5e4

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { generateChart } from '../../src';
2+
3+
const MOCK_DATA_TABLE = [
4+
{ group: 'A', name: 'Category1', value: 10 },
5+
{ group: 'A', name: 'Category2', value: 15 },
6+
{ group: 'B', name: 'Category1', value: 20 },
7+
{ group: 'B', name: 'Category2', value: 25 }
8+
];
9+
10+
const layout = {
11+
type: 'grid',
12+
col: 3,
13+
row: 3,
14+
colWidth: [
15+
{
16+
index: 1,
17+
size: 120
18+
}
19+
],
20+
elements: [
21+
{
22+
modelId: 'title',
23+
col: 0,
24+
row: 0,
25+
colSpan: 3
26+
},
27+
{
28+
modelId: 'legend',
29+
col: 0,
30+
row: 1,
31+
colSpan: 3
32+
},
33+
{
34+
modelId: 'left',
35+
col: 0,
36+
row: 2
37+
},
38+
{
39+
modelId: 'right',
40+
col: 2,
41+
row: 2
42+
}
43+
]
44+
};
45+
46+
const region = [
47+
{
48+
id: 'left'
49+
},
50+
{
51+
id: 'right'
52+
}
53+
];
54+
55+
describe('generate comparative funnel chart', () => {
56+
it('should generate comparative funnel chart with dataTable', () => {
57+
const { spec } = generateChart('comparativeFunnel', {
58+
dataTable: MOCK_DATA_TABLE,
59+
cell: {
60+
x: 'name',
61+
y: 'value',
62+
category: 'group'
63+
},
64+
spec: {}
65+
});
66+
expect(spec.type).toBe('common');
67+
expect(spec.layout).toEqual(layout);
68+
expect(spec.region).toEqual(region);
69+
expect(spec.data).toEqual(
70+
Object.entries(
71+
MOCK_DATA_TABLE.reduce((acc, curr) => {
72+
if (!acc[curr.group]) {
73+
acc[curr.group] = [];
74+
}
75+
acc[curr.group].push(curr);
76+
return acc;
77+
}, {} as any)
78+
).map(([group, data]) => ({
79+
id: group,
80+
values: data
81+
}))
82+
);
83+
expect(spec.series).toEqual([
84+
{
85+
type: 'funnel',
86+
dataIndex: 0,
87+
regionIndex: 0,
88+
isTransform: true,
89+
gap: 2,
90+
maxSize: '60%',
91+
shape: 'rect',
92+
funnelAlign: 'right',
93+
categoryField: 'name',
94+
valueField: 'value',
95+
heightRatio: 1.5,
96+
funnel: {
97+
style: {
98+
fill: { field: 'group', scale: 'color' },
99+
cornerRadius: 4
100+
}
101+
},
102+
transform: {
103+
style: {
104+
fill: { field: 'group', scale: 'color' },
105+
fillOpacity: 0.1
106+
}
107+
},
108+
outerLabel: {
109+
visible: true,
110+
line: { visible: false },
111+
style: {
112+
fontSize: 24,
113+
fontWeight: 'bold',
114+
fill: 'black',
115+
limit: Infinity
116+
}
117+
},
118+
extensionMark: [
119+
{
120+
type: 'text',
121+
dataIndex: 0,
122+
style: {
123+
fontSize: 24,
124+
fill: 'grey',
125+
textAlign: 'center'
126+
}
127+
}
128+
]
129+
},
130+
{
131+
type: 'funnel',
132+
dataIndex: 1,
133+
regionIndex: 1,
134+
isTransform: true,
135+
gap: 2,
136+
maxSize: '60%',
137+
shape: 'rect',
138+
funnelAlign: 'left',
139+
categoryField: 'name',
140+
valueField: 'value',
141+
heightRatio: 1.5,
142+
funnel: {
143+
style: {
144+
fill: { field: 'group', scale: 'color' },
145+
cornerRadius: 4
146+
}
147+
},
148+
transform: {
149+
style: {
150+
fill: { field: 'group', scale: 'color' },
151+
fillOpacity: 0.1
152+
}
153+
},
154+
outerLabel: {
155+
visible: true,
156+
line: { visible: false },
157+
style: {
158+
fontSize: 24,
159+
fontWeight: 'bold',
160+
fill: 'black',
161+
limit: Infinity
162+
}
163+
}
164+
}
165+
]);
166+
});
167+
});

packages/vmind/src/atom/chartGenerator/rule/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export const getContextBySimpleVChartSpec = (simpleVChartSpec: SimpleVChartSpec)
194194
}
195195
if (chartType === 'heatmap') {
196196
cell.x = 'name';
197+
// 热图有两个维度数据,因此新增name1字段
197198
cell.y = 'name1';
198199
cell.size = 'value';
199200
}

0 commit comments

Comments
 (0)