Skip to content

Commit cb1d3fd

Browse files
committed
test: add test case of getChartSpecWithContext when chartType is circlePacking
1 parent f4b9f3a commit cb1d3fd

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { Dict } from '@visactor/vutils';
2+
import { getChartSpecWithContext } from '../../src/atom/chartGenerator/spec';
3+
import type { GenerateChartCellContext } from '../../src/atom/chartGenerator/type';
4+
import { ChartType } from '../../src/types';
5+
6+
const CHART_TYPE_LIST = [
7+
'Bar Chart',
8+
'Line Chart',
9+
'Area Chart',
10+
'Pie Chart',
11+
'Scatter Plot',
12+
'Word Cloud',
13+
'Rose Chart',
14+
'Radar Chart',
15+
'Sankey Chart',
16+
'Funnel Chart',
17+
'Dual Axis Chart',
18+
'Waterfall Chart',
19+
'Box Plot',
20+
'Linear Progress chart',
21+
'Circular Progress chart',
22+
'Liquid Chart',
23+
'Bubble Circle Packing',
24+
'Map Chart',
25+
'Range Column Chart',
26+
'Sunburst Chart',
27+
'Treemap Chart',
28+
'Gauge Chart',
29+
'Basic Heat Map',
30+
'Venn Chart',
31+
'Dynamic Bar Chart'
32+
];
33+
34+
const generateRandomValue = (min = 100, max = 2000) => Math.floor(Math.random() * (max - min + 1)) + min;
35+
36+
function generateDataStructure() {
37+
const createProducts = () => [
38+
{ name: 'Office Supplies', value: generateRandomValue() },
39+
{ name: 'Furniture', value: generateRandomValue() },
40+
{ name: 'Electronic equipment', value: generateRandomValue() }
41+
];
42+
43+
const createRegions = (count: number) =>
44+
Array.from({ length: count }, (_, i) => ({
45+
name: `Region${i + 1}`,
46+
children: createProducts()
47+
}));
48+
49+
const createCountries = (names: string[]) =>
50+
names.map(country => ({
51+
name: country,
52+
children: createRegions(6) // 每个国家6个地区
53+
}));
54+
55+
return [
56+
{
57+
name: 'root',
58+
children: createCountries(['Country A', 'Country B', 'Country C'])
59+
}
60+
];
61+
}
62+
const dataItem = generateDataStructure();
63+
//console.log("dataItem", JSON.stringify(dataItem, null, 2));
64+
65+
describe('getChartSpecWithContext', () => {
66+
it('should generate correct basic circle packing spec', () => {
67+
//console.log("data",data);
68+
const context = {
69+
chartTypeList: CHART_TYPE_LIST,
70+
transpose: false,
71+
command: 'Generate a BasicCircle Packing chart',
72+
cell: { x: 'name', size: 'value' },
73+
dataTable: dataItem,
74+
chartType: ChartType.BubbleCirclePacking.toUpperCase()
75+
};
76+
const { chartType, spec } = getChartSpecWithContext(context);
77+
//console.log("basic spec", JSON.stringify(spec, null, 2));
78+
expect(chartType).toBe(ChartType.BubbleCirclePacking);
79+
expect(spec.type).toBe('circlePacking');
80+
expect(spec.data.values).toEqual(dataItem);
81+
});
82+
83+
it('should generate correct bubble circle packing spec', () => {
84+
const buble_data = new Array(19).fill(0).map((_, i) => {
85+
return {
86+
name: `bubble-${i + 1}`,
87+
value: i + 1
88+
};
89+
});
90+
const context = {
91+
chartTypeList: CHART_TYPE_LIST,
92+
transpose: false,
93+
command: 'Generate a Bubble Circle Packing chart',
94+
cell: { x: 'name', size: 'value' },
95+
dataTable: buble_data,
96+
chartType: ChartType.BubbleCirclePacking.toUpperCase()
97+
};
98+
const { chartType, spec } = getChartSpecWithContext(context);
99+
//console.log("bubble spec", JSON.stringify(spec, null, 2));
100+
expect(chartType).toBe(ChartType.BubbleCirclePacking);
101+
expect(spec.type).toBe('circlePacking');
102+
expect(spec.data.values).toEqual(buble_data);
103+
});
104+
105+
it('should generate correct nulti-root circle packing spec', () => {
106+
const multi_root_data = dataItem[0].children;
107+
const context = {
108+
chartTypeList: CHART_TYPE_LIST,
109+
transpose: false,
110+
command: 'Generate a Multi-root Circle Packing chart',
111+
cell: { x: 'name', size: 'value' },
112+
dataTable: multi_root_data,
113+
chartType: ChartType.BubbleCirclePacking.toUpperCase()
114+
};
115+
const { chartType, spec } = getChartSpecWithContext(context);
116+
//console.log("multi-root spec", JSON.stringify(spec, null, 2));
117+
expect(chartType).toBe(ChartType.BubbleCirclePacking);
118+
expect(spec.type).toBe('circlePacking');
119+
expect(spec.data.values).toEqual(multi_root_data);
120+
});
121+
});

0 commit comments

Comments
 (0)