@agions/taroviz 1.1.1 → 1.2.1
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/README.md +324 -53
- package/dist/cjs/index.js +1 -0
- package/dist/esm/index.js +82979 -0
- package/package.json +160 -30
- package/src/__tests__/integration.test.tsx +168 -0
- package/src/adapters/__tests__/index.test.ts +91 -0
- package/src/adapters/h5/__tests__/index.test.ts +156 -0
- package/src/adapters/h5/index.ts +301 -0
- package/src/adapters/harmony/index.ts +274 -0
- package/src/adapters/index.ts +166 -0
- package/src/adapters/swan/index.ts +274 -0
- package/src/adapters/tt/index.ts +274 -0
- package/src/adapters/types.ts +162 -0
- package/src/adapters/weapp/index.ts +237 -0
- package/src/charts/bar/__tests__/index.test.tsx +113 -0
- package/src/charts/bar/index.tsx +18 -0
- package/src/charts/common/BaseChartWrapper.tsx +136 -0
- package/src/charts/funnel/index.tsx +18 -0
- package/src/charts/gauge/index.tsx +18 -0
- package/src/charts/heatmap/index.tsx +18 -0
- package/src/charts/index.ts +21 -0
- package/src/charts/line/__tests__/index.test.tsx +107 -0
- package/src/charts/line/index.tsx +18 -0
- package/src/charts/pie/__tests__/index.test.tsx +112 -0
- package/src/charts/pie/index.tsx +19 -0
- package/src/charts/radar/index.tsx +18 -0
- package/src/charts/scatter/index.tsx +18 -0
- package/src/charts/types.ts +619 -0
- package/src/charts/utils.ts +56 -0
- package/src/core/__tests__/platform.test.ts +48 -0
- package/src/core/animation/AnimationManager.ts +391 -0
- package/src/core/animation/index.ts +20 -0
- package/src/core/animation/types.ts +248 -0
- package/src/core/components/BaseChart.tsx +1313 -0
- package/src/core/components/ErrorBoundary.tsx +458 -0
- package/src/core/echarts.ts +58 -0
- package/src/core/index.ts +22 -0
- package/src/core/types/chart.ts +66 -0
- package/src/core/types/common.ts +224 -0
- package/src/core/types/index.ts +281 -0
- package/src/core/types/platform.ts +325 -0
- package/src/core/utils/__tests__/common.test.ts +52 -0
- package/src/core/utils/__tests__/environment.test.ts +94 -0
- package/src/core/utils/__tests__/i18n.test.ts +247 -0
- package/src/core/utils/__tests__/index.test.ts +219 -0
- package/src/core/utils/__tests__/uuid.test.ts +78 -0
- package/src/core/utils/chartInstances.ts +69 -0
- package/src/core/utils/codeGenerator/CodeGenerator.ts +655 -0
- package/src/core/utils/codeGenerator/index.ts +13 -0
- package/src/core/utils/codeGenerator/types.ts +198 -0
- package/src/core/utils/common.ts +58 -0
- package/src/core/utils/configGenerator/ConfigGenerator.ts +583 -0
- package/src/core/utils/configGenerator/index.ts +13 -0
- package/src/core/utils/configGenerator/types.ts +445 -0
- package/src/core/utils/debug/DebugPanel.tsx +637 -0
- package/src/core/utils/debug/debugger.ts +322 -0
- package/src/core/utils/debug/index.ts +21 -0
- package/src/core/utils/debug/types.ts +142 -0
- package/src/core/utils/i18n.ts +452 -0
- package/src/core/utils/index.ts +162 -0
- package/src/core/utils/performance/PerformanceAnalyzer.ts +586 -0
- package/src/core/utils/performance/index.ts +13 -0
- package/src/core/utils/performance/types.ts +180 -0
- package/src/core/utils/uuid.ts +30 -0
- package/src/editor/ThemeEditor.tsx +449 -0
- package/src/editor/index.ts +10 -0
- package/src/hooks/__tests__/index.test.tsx +333 -0
- package/src/hooks/index.ts +594 -0
- package/src/index.ts +75 -0
- package/src/main.tsx +247 -0
- package/src/react-dom.d.ts +7 -0
- package/src/themes/__tests__/index.test.ts +91 -0
- package/src/themes/index.ts +860 -0
- package/dist/389.index.esm.js +0 -1
- package/dist/389.index.js +0 -1
- package/dist/633.index.esm.js +0 -1
- package/dist/633.index.js +0 -1
- package/dist/967.index.esm.js +0 -1
- package/dist/967.index.js +0 -1
- package/dist/index.esm.js +0 -1
- package/dist/index.js +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaroViz 图表组件集合
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// 导出基础图表组件
|
|
6
|
+
export { default as LineChart } from './line';
|
|
7
|
+
export { default as BarChart } from './bar';
|
|
8
|
+
export { default as PieChart } from './pie';
|
|
9
|
+
export { default as ScatterChart } from './scatter';
|
|
10
|
+
export { default as RadarChart } from './radar';
|
|
11
|
+
export { default as HeatmapChart } from './heatmap';
|
|
12
|
+
export { default as GaugeChart } from './gauge';
|
|
13
|
+
export { default as FunnelChart } from './funnel';
|
|
14
|
+
|
|
15
|
+
// 导出类型定义
|
|
16
|
+
export * from './types';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 版本信息
|
|
20
|
+
*/
|
|
21
|
+
export const version = '1.1.1';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import LineChart from '../index';
|
|
5
|
+
|
|
6
|
+
// Mock ECharts and adapters
|
|
7
|
+
jest.mock('echarts/core', () => ({
|
|
8
|
+
use: jest.fn(),
|
|
9
|
+
init: jest.fn(() => ({
|
|
10
|
+
setOption: jest.fn(),
|
|
11
|
+
showLoading: jest.fn(),
|
|
12
|
+
hideLoading: jest.fn(),
|
|
13
|
+
on: jest.fn(),
|
|
14
|
+
off: jest.fn(),
|
|
15
|
+
dispose: jest.fn(),
|
|
16
|
+
resize: jest.fn(),
|
|
17
|
+
})),
|
|
18
|
+
getInstanceByDom: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
// Mock specific ECharts chart imports
|
|
22
|
+
jest.mock('echarts/charts', () => ({
|
|
23
|
+
LineChart: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock('echarts/components', () => ({
|
|
27
|
+
GridComponent: jest.fn(),
|
|
28
|
+
TooltipComponent: jest.fn(),
|
|
29
|
+
TitleComponent: jest.fn(),
|
|
30
|
+
LegendComponent: jest.fn(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock('../../common/BaseChartWrapper', () => ({
|
|
34
|
+
__esModule: true,
|
|
35
|
+
default: (props: any) => (
|
|
36
|
+
<div
|
|
37
|
+
data-testid="base-chart-wrapper"
|
|
38
|
+
className={`taroviz-${props.chartType} ${props.className || ''}`}
|
|
39
|
+
style={{ width: props.width, height: props.height }}
|
|
40
|
+
>
|
|
41
|
+
<div data-testid="chart-option">{JSON.stringify(props.option)}</div>
|
|
42
|
+
</div>
|
|
43
|
+
),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
describe('LineChart Component', () => {
|
|
47
|
+
const mockOption = {
|
|
48
|
+
xAxis: {
|
|
49
|
+
type: 'category' as const,
|
|
50
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
51
|
+
},
|
|
52
|
+
yAxis: {
|
|
53
|
+
type: 'value' as const,
|
|
54
|
+
},
|
|
55
|
+
series: [
|
|
56
|
+
{
|
|
57
|
+
data: [150, 230, 224, 218, 135, 147, 260],
|
|
58
|
+
type: 'line' as const,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
it('should render correctly with default props', () => {
|
|
64
|
+
const { getByTestId } = render(<LineChart option={mockOption} />);
|
|
65
|
+
|
|
66
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
67
|
+
expect(chartWrapper).toBeInTheDocument();
|
|
68
|
+
expect(chartWrapper).toHaveClass('taroviz-line-chart');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should pass the correct option to BaseChartWrapper', () => {
|
|
72
|
+
const { getByTestId } = render(<LineChart option={mockOption} />);
|
|
73
|
+
|
|
74
|
+
const chartOption = getByTestId('chart-option');
|
|
75
|
+
expect(JSON.parse(chartOption.textContent || '')).toEqual(mockOption);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should render with custom width and height', () => {
|
|
79
|
+
const customWidth = '500px';
|
|
80
|
+
const customHeight = '400px';
|
|
81
|
+
|
|
82
|
+
const { getByTestId } = render(
|
|
83
|
+
<LineChart option={mockOption} width={customWidth} height={customHeight} />
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
87
|
+
expect(chartWrapper).toHaveStyle(`width: ${customWidth}`);
|
|
88
|
+
expect(chartWrapper).toHaveStyle(`height: ${customHeight}`);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should render with custom className', () => {
|
|
92
|
+
const customClass = 'custom-line-chart';
|
|
93
|
+
|
|
94
|
+
const { getByTestId } = render(<LineChart option={mockOption} className={customClass} />);
|
|
95
|
+
|
|
96
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
97
|
+
expect(chartWrapper).toHaveClass(customClass);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should render with loading state', () => {
|
|
101
|
+
const { getByTestId } = render(<LineChart option={mockOption} loading={true} />);
|
|
102
|
+
|
|
103
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
104
|
+
expect(chartWrapper).toBeInTheDocument();
|
|
105
|
+
// The loading state is handled by BaseChartWrapper, which we've mocked
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 折线图组件
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import BaseChartWrapper from '../common/BaseChartWrapper';
|
|
7
|
+
import { LineChartProps } from '../types';
|
|
8
|
+
|
|
9
|
+
import '@/core/echarts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 折线图组件
|
|
13
|
+
*/
|
|
14
|
+
const LineChart: React.FC<LineChartProps> = (props) => (
|
|
15
|
+
<BaseChartWrapper {...props} chartType="line-chart" />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default LineChart;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import PieChart from '../index';
|
|
5
|
+
|
|
6
|
+
// Mock ECharts and adapters
|
|
7
|
+
jest.mock('echarts/core', () => ({
|
|
8
|
+
use: jest.fn(),
|
|
9
|
+
init: jest.fn(() => ({
|
|
10
|
+
setOption: jest.fn(),
|
|
11
|
+
showLoading: jest.fn(),
|
|
12
|
+
hideLoading: jest.fn(),
|
|
13
|
+
on: jest.fn(),
|
|
14
|
+
off: jest.fn(),
|
|
15
|
+
dispose: jest.fn(),
|
|
16
|
+
resize: jest.fn(),
|
|
17
|
+
})),
|
|
18
|
+
getInstanceByDom: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
// Mock specific ECharts chart imports
|
|
22
|
+
jest.mock('echarts/charts', () => ({
|
|
23
|
+
PieChart: jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock('echarts/components', () => ({
|
|
27
|
+
GridComponent: jest.fn(),
|
|
28
|
+
TooltipComponent: jest.fn(),
|
|
29
|
+
TitleComponent: jest.fn(),
|
|
30
|
+
LegendComponent: jest.fn(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock('../../common/BaseChartWrapper', () => ({
|
|
34
|
+
__esModule: true,
|
|
35
|
+
default: (props: any) => (
|
|
36
|
+
<div
|
|
37
|
+
data-testid="base-chart-wrapper"
|
|
38
|
+
className={`taroviz-${props.chartType} ${props.className || ''}`}
|
|
39
|
+
style={{ width: props.width, height: props.height }}
|
|
40
|
+
>
|
|
41
|
+
<div data-testid="chart-option">{JSON.stringify(props.option)}</div>
|
|
42
|
+
</div>
|
|
43
|
+
),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
describe('PieChart Component', () => {
|
|
47
|
+
const mockOption = {
|
|
48
|
+
series: [
|
|
49
|
+
{
|
|
50
|
+
type: 'pie' as const,
|
|
51
|
+
data: [
|
|
52
|
+
{ value: 1048, name: 'Search Engine' },
|
|
53
|
+
{ value: 735, name: 'Direct' },
|
|
54
|
+
{ value: 580, name: 'Email' },
|
|
55
|
+
{ value: 484, name: 'Union Ads' },
|
|
56
|
+
{ value: 300, name: 'Video Ads' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
it('should render correctly with default props', () => {
|
|
63
|
+
const { getByTestId } = render(<PieChart option={mockOption} />);
|
|
64
|
+
|
|
65
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
66
|
+
expect(chartWrapper).toBeInTheDocument();
|
|
67
|
+
expect(chartWrapper).toHaveClass('taroviz-pie-chart');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should pass the correct option to BaseChartWrapper', () => {
|
|
71
|
+
const { getByTestId } = render(<PieChart option={mockOption} />);
|
|
72
|
+
|
|
73
|
+
const chartOption = getByTestId('chart-option');
|
|
74
|
+
expect(JSON.parse(chartOption.textContent || '')).toEqual(mockOption);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should render with custom width and height', () => {
|
|
78
|
+
const customWidth = '400px';
|
|
79
|
+
const customHeight = '400px';
|
|
80
|
+
|
|
81
|
+
const { getByTestId } = render(
|
|
82
|
+
<PieChart option={mockOption} width={customWidth} height={customHeight} />
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
86
|
+
expect(chartWrapper).toHaveStyle(`width: ${customWidth}`);
|
|
87
|
+
expect(chartWrapper).toHaveStyle(`height: ${customHeight}`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should render with custom className', () => {
|
|
91
|
+
const customClass = 'custom-pie-chart';
|
|
92
|
+
|
|
93
|
+
const { getByTestId } = render(<PieChart option={mockOption} className={customClass} />);
|
|
94
|
+
|
|
95
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
96
|
+
expect(chartWrapper).toHaveClass(customClass);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should render with loading state', () => {
|
|
100
|
+
const { getByTestId } = render(<PieChart option={mockOption} loading={true} />);
|
|
101
|
+
|
|
102
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
103
|
+
expect(chartWrapper).toBeInTheDocument();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should render with theme', () => {
|
|
107
|
+
const { getByTestId } = render(<PieChart option={mockOption} theme="dark" />);
|
|
108
|
+
|
|
109
|
+
const chartWrapper = getByTestId('base-chart-wrapper');
|
|
110
|
+
expect(chartWrapper).toBeInTheDocument();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 饼图组件
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import BaseChartWrapper from '../common/BaseChartWrapper';
|
|
7
|
+
import { BaseChartProps } from '../types';
|
|
8
|
+
|
|
9
|
+
// 导入统一注册的 echarts
|
|
10
|
+
import '@/core/echarts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 饼图组件
|
|
14
|
+
*/
|
|
15
|
+
const PieChart: React.FC<BaseChartProps> = (props) => (
|
|
16
|
+
<BaseChartWrapper {...props} chartType="pie-chart" />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export default PieChart;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 雷达图组件
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import BaseChartWrapper from '../common/BaseChartWrapper';
|
|
7
|
+
import { RadarChartProps } from '../types';
|
|
8
|
+
|
|
9
|
+
import '@/core/echarts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 雷达图组件
|
|
13
|
+
*/
|
|
14
|
+
const RadarChart: React.FC<RadarChartProps> = (props) => (
|
|
15
|
+
<BaseChartWrapper {...props} chartType="radar-chart" />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default RadarChart;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 散点图组件
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import BaseChartWrapper from '../common/BaseChartWrapper';
|
|
7
|
+
import { ScatterChartProps } from '../types';
|
|
8
|
+
|
|
9
|
+
import '@/core/echarts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 散点图组件
|
|
13
|
+
*/
|
|
14
|
+
const ScatterChart: React.FC<ScatterChartProps> = (props) => (
|
|
15
|
+
<BaseChartWrapper {...props} chartType="scatter-chart" />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default ScatterChart;
|