Skip to content

Commit 6a12f04

Browse files
committed
feat: fix test unit
1 parent 818c5e4 commit 6a12f04

File tree

3 files changed

+99
-85
lines changed

3 files changed

+99
-85
lines changed

packages/generate-vchart/__tests__/transformers/comparativeFunnel.test.ts

Lines changed: 82 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -80,88 +80,92 @@ describe('generate comparative funnel chart', () => {
8080
values: data
8181
}))
8282
);
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,
83+
const serialize = (obj: any) => JSON.parse(JSON.stringify(obj));
84+
expect(serialize(spec.series)).toEqual(
85+
serialize([
86+
{
87+
type: 'funnel',
88+
dataIndex: 0,
89+
regionIndex: 0,
90+
isTransform: true,
91+
gap: 2,
92+
maxSize: '60%',
93+
shape: 'rect',
94+
funnelAlign: 'right',
95+
categoryField: 'name',
96+
valueField: 'value',
97+
heightRatio: 1.5,
98+
funnel: {
99+
style: {
100+
fill: { field: 'group', scale: 'color' },
101+
cornerRadius: 4
102+
}
103+
},
104+
transform: {
105+
style: {
106+
fill: { field: 'group', scale: 'color' },
107+
fillOpacity: 0.1
108+
}
109+
},
110+
outerLabel: {
111+
visible: true,
112+
line: { visible: false },
122113
style: {
123114
fontSize: 24,
124-
fill: 'grey',
125-
textAlign: 'center'
115+
fontWeight: 'bold',
116+
fill: 'black',
117+
limit: Infinity
126118
}
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-
}
119+
},
120+
extensionMark: [
121+
{
122+
type: 'text',
123+
dataIndex: 0,
124+
style: {
125+
fontSize: 24,
126+
fill: 'grey',
127+
textAlign: 'center'
128+
}
129+
}
130+
]
153131
},
154-
outerLabel: {
155-
visible: true,
156-
line: { visible: false },
157-
style: {
158-
fontSize: 24,
159-
fontWeight: 'bold',
160-
fill: 'black',
161-
limit: Infinity
162-
}
132+
{
133+
type: 'funnel',
134+
dataIndex: 1,
135+
regionIndex: 1,
136+
isTransform: true,
137+
gap: 2,
138+
maxSize: '60%',
139+
shape: 'rect',
140+
funnelAlign: 'left',
141+
categoryField: 'name',
142+
valueField: 'value',
143+
heightRatio: 1.5,
144+
funnel: {
145+
style: {
146+
fill: { field: 'group', scale: 'color' },
147+
cornerRadius: 4
148+
}
149+
},
150+
transform: {
151+
style: {
152+
fill: { field: 'group', scale: 'color' },
153+
fillOpacity: 0.1
154+
}
155+
},
156+
outerLabel: {
157+
visible: true,
158+
line: { visible: false },
159+
style: {
160+
fontSize: 24,
161+
fontWeight: 'bold',
162+
fill: 'black',
163+
limit: Infinity
164+
}
165+
},
166+
extensionMark: []
163167
}
164-
}
165-
]);
168+
])
169+
);
166170
});
167171
});

packages/generate-vchart/__tests__/transformers/heatmap.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ describe('generateChart', () => {
4848
grid: {
4949
visible: false
5050
},
51+
label: {
52+
style: {
53+
angle: 90
54+
}
55+
},
5156
domainLine: {
5257
visible: false
5358
}
@@ -261,6 +266,11 @@ describe('generateChart', () => {
261266
grid: {
262267
visible: false
263268
},
269+
label: {
270+
style: {
271+
angle: 90
272+
}
273+
},
264274
domainLine: {
265275
visible: false
266276
},

packages/generate-vchart/src/transformers/comparativeFunnel.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { array } from '@visactor/vutils';
2-
import { GenerateChartInput } from '../types';
2+
import { DataItem, GenerateChartInput } from '../types';
33
import { data, discreteLegend, formatXFields } from './common';
44

55
const title = (context: GenerateChartInput) => {
@@ -31,8 +31,8 @@ const layout = (context: GenerateChartInput) => {
3131
};
3232

3333
const comparativeFunnelSeries = (context: GenerateChartInput) => {
34-
const { spec, dataTable, series, cell } = context;
35-
const generateSeries = (index, align: 'left' | 'right') => {
34+
const { spec, cell } = context;
35+
const generateSeries = (index: number, align: 'left' | 'right') => {
3636
return {
3737
type: 'funnel',
3838
dataIndex: index,
@@ -60,7 +60,7 @@ const comparativeFunnelSeries = (context: GenerateChartInput) => {
6060
outerLabel: {
6161
visible: true,
6262
line: { visible: false },
63-
formatMethod: (label, datum) => datum[array(cell.y)[0]],
63+
formatMethod: (data: any, datum: DataItem) => datum[array(cell.y)[0]],
6464
style: {
6565
fontSize: 24,
6666
fontWeight: 'bold',
@@ -74,15 +74,15 @@ const comparativeFunnelSeries = (context: GenerateChartInput) => {
7474
type: 'text',
7575
dataIndex: 0,
7676
style: {
77-
text: data => data[array(cell.x)[0]],
77+
text: (data: any) => data[array(cell.x)[0]],
7878
fontSize: 24,
7979
fill: 'grey',
8080
textAlign: 'center',
81-
x: (data, ctx) => {
81+
x: (data: any, ctx: any) => {
8282
const { vchart } = ctx;
8383
return vchart.getCurrentSize().width / 2 - 10;
8484
},
85-
y: (data, ctx) => {
85+
y: (data: DataItem, ctx: any) => {
8686
const { getPoints } = ctx;
8787
const [tl, tr, br, bl] = getPoints(data);
8888
return (tl.y + bl.y) / 2;

0 commit comments

Comments
 (0)