@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.
Files changed (81) hide show
  1. package/README.md +324 -53
  2. package/dist/cjs/index.js +1 -0
  3. package/dist/esm/index.js +82979 -0
  4. package/package.json +160 -30
  5. package/src/__tests__/integration.test.tsx +168 -0
  6. package/src/adapters/__tests__/index.test.ts +91 -0
  7. package/src/adapters/h5/__tests__/index.test.ts +156 -0
  8. package/src/adapters/h5/index.ts +301 -0
  9. package/src/adapters/harmony/index.ts +274 -0
  10. package/src/adapters/index.ts +166 -0
  11. package/src/adapters/swan/index.ts +274 -0
  12. package/src/adapters/tt/index.ts +274 -0
  13. package/src/adapters/types.ts +162 -0
  14. package/src/adapters/weapp/index.ts +237 -0
  15. package/src/charts/bar/__tests__/index.test.tsx +113 -0
  16. package/src/charts/bar/index.tsx +18 -0
  17. package/src/charts/common/BaseChartWrapper.tsx +136 -0
  18. package/src/charts/funnel/index.tsx +18 -0
  19. package/src/charts/gauge/index.tsx +18 -0
  20. package/src/charts/heatmap/index.tsx +18 -0
  21. package/src/charts/index.ts +21 -0
  22. package/src/charts/line/__tests__/index.test.tsx +107 -0
  23. package/src/charts/line/index.tsx +18 -0
  24. package/src/charts/pie/__tests__/index.test.tsx +112 -0
  25. package/src/charts/pie/index.tsx +19 -0
  26. package/src/charts/radar/index.tsx +18 -0
  27. package/src/charts/scatter/index.tsx +18 -0
  28. package/src/charts/types.ts +619 -0
  29. package/src/charts/utils.ts +56 -0
  30. package/src/core/__tests__/platform.test.ts +48 -0
  31. package/src/core/animation/AnimationManager.ts +391 -0
  32. package/src/core/animation/index.ts +20 -0
  33. package/src/core/animation/types.ts +248 -0
  34. package/src/core/components/BaseChart.tsx +1313 -0
  35. package/src/core/components/ErrorBoundary.tsx +458 -0
  36. package/src/core/echarts.ts +58 -0
  37. package/src/core/index.ts +22 -0
  38. package/src/core/types/chart.ts +66 -0
  39. package/src/core/types/common.ts +224 -0
  40. package/src/core/types/index.ts +281 -0
  41. package/src/core/types/platform.ts +325 -0
  42. package/src/core/utils/__tests__/common.test.ts +52 -0
  43. package/src/core/utils/__tests__/environment.test.ts +94 -0
  44. package/src/core/utils/__tests__/i18n.test.ts +247 -0
  45. package/src/core/utils/__tests__/index.test.ts +219 -0
  46. package/src/core/utils/__tests__/uuid.test.ts +78 -0
  47. package/src/core/utils/chartInstances.ts +69 -0
  48. package/src/core/utils/codeGenerator/CodeGenerator.ts +655 -0
  49. package/src/core/utils/codeGenerator/index.ts +13 -0
  50. package/src/core/utils/codeGenerator/types.ts +198 -0
  51. package/src/core/utils/common.ts +58 -0
  52. package/src/core/utils/configGenerator/ConfigGenerator.ts +583 -0
  53. package/src/core/utils/configGenerator/index.ts +13 -0
  54. package/src/core/utils/configGenerator/types.ts +445 -0
  55. package/src/core/utils/debug/DebugPanel.tsx +637 -0
  56. package/src/core/utils/debug/debugger.ts +322 -0
  57. package/src/core/utils/debug/index.ts +21 -0
  58. package/src/core/utils/debug/types.ts +142 -0
  59. package/src/core/utils/i18n.ts +452 -0
  60. package/src/core/utils/index.ts +162 -0
  61. package/src/core/utils/performance/PerformanceAnalyzer.ts +586 -0
  62. package/src/core/utils/performance/index.ts +13 -0
  63. package/src/core/utils/performance/types.ts +180 -0
  64. package/src/core/utils/uuid.ts +30 -0
  65. package/src/editor/ThemeEditor.tsx +449 -0
  66. package/src/editor/index.ts +10 -0
  67. package/src/hooks/__tests__/index.test.tsx +333 -0
  68. package/src/hooks/index.ts +594 -0
  69. package/src/index.ts +75 -0
  70. package/src/main.tsx +247 -0
  71. package/src/react-dom.d.ts +7 -0
  72. package/src/themes/__tests__/index.test.ts +91 -0
  73. package/src/themes/index.ts +860 -0
  74. package/dist/389.index.esm.js +0 -1
  75. package/dist/389.index.js +0 -1
  76. package/dist/633.index.esm.js +0 -1
  77. package/dist/633.index.js +0 -1
  78. package/dist/967.index.esm.js +0 -1
  79. package/dist/967.index.js +0 -1
  80. package/dist/index.esm.js +0 -1
  81. package/dist/index.js +0 -1
package/src/main.tsx ADDED
@@ -0,0 +1,247 @@
1
+ import React, { useState } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+
4
+ import type { ChartOptions, EChartsType } from './core/types';
5
+
6
+ import { BaseChart, LineChart, BarChart, PieChart } from './index';
7
+
8
+ // Type assertion helper
9
+ const asChartOptions = <T extends Record<string, any>>(options: T): ChartOptions => {
10
+ return options as ChartOptions;
11
+ };
12
+
13
+ // Example data for various chart types
14
+ const lineOption = {
15
+ title: {
16
+ text: 'Line Chart Example',
17
+ left: 'center',
18
+ },
19
+ tooltip: {
20
+ trigger: 'axis',
21
+ },
22
+ legend: {
23
+ data: ['Series 1', 'Series 2'],
24
+ bottom: 10,
25
+ },
26
+ xAxis: {
27
+ type: 'category',
28
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
29
+ },
30
+ yAxis: {
31
+ type: 'value',
32
+ },
33
+ series: [
34
+ {
35
+ name: 'Series 1',
36
+ data: [120, 200, 150, 80, 70, 110, 130],
37
+ type: 'line',
38
+ smooth: true,
39
+ },
40
+ {
41
+ name: 'Series 2',
42
+ data: [90, 150, 120, 100, 80, 130, 150],
43
+ type: 'line',
44
+ smooth: true,
45
+ },
46
+ ],
47
+ };
48
+
49
+ const barOption = {
50
+ title: {
51
+ text: 'Bar Chart Example',
52
+ left: 'center',
53
+ },
54
+ tooltip: {
55
+ trigger: 'axis',
56
+ },
57
+ legend: {
58
+ data: ['Series A', 'Series B'],
59
+ bottom: 10,
60
+ },
61
+ xAxis: {
62
+ type: 'category',
63
+ data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
64
+ },
65
+ yAxis: {
66
+ type: 'value',
67
+ },
68
+ series: [
69
+ {
70
+ name: 'Series A',
71
+ data: [200, 300, 400, 350, 500, 450],
72
+ type: 'bar',
73
+ itemStyle: {
74
+ color: '#5470c6',
75
+ },
76
+ },
77
+ {
78
+ name: 'Series B',
79
+ data: [150, 250, 350, 300, 450, 400],
80
+ type: 'bar',
81
+ itemStyle: {
82
+ color: '#91cc75',
83
+ },
84
+ },
85
+ ],
86
+ };
87
+
88
+ const pieOption = {
89
+ title: {
90
+ text: 'Pie Chart Example',
91
+ left: 'center',
92
+ },
93
+ tooltip: {
94
+ trigger: 'item',
95
+ },
96
+ legend: {
97
+ orient: 'vertical',
98
+ left: 'left',
99
+ },
100
+ series: [
101
+ {
102
+ name: 'Pie Data',
103
+ type: 'pie',
104
+ radius: '60%',
105
+ center: ['50%', '50%'],
106
+ data: [
107
+ { value: 350, name: 'Category A' },
108
+ { value: 250, name: 'Category B' },
109
+ { value: 200, name: 'Category C' },
110
+ { value: 150, name: 'Category D' },
111
+ { value: 50, name: 'Category E' },
112
+ ],
113
+ emphasis: {
114
+ itemStyle: {
115
+ shadowBlur: 10,
116
+ shadowOffsetX: 0,
117
+ shadowColor: 'rgba(0, 0, 0, 0.5)',
118
+ },
119
+ },
120
+ },
121
+ ],
122
+ };
123
+
124
+ const TestApp = () => {
125
+ const [darkMode, setDarkMode] = useState(false);
126
+ const [loading, setLoading] = useState(false);
127
+ const [currentChart, setCurrentChart] = useState('line');
128
+
129
+ // Toggle loading state
130
+ const toggleLoading = () => {
131
+ setLoading(!loading);
132
+ };
133
+
134
+ // Toggle dark mode
135
+ const toggleDarkMode = () => {
136
+ setDarkMode(!darkMode);
137
+ };
138
+
139
+ // Update chart data randomly
140
+ const updateData = () => {
141
+ // This would normally update the chart options state
142
+ console.log('Updating chart data...');
143
+ };
144
+
145
+ return (
146
+ <div>
147
+ {/* Controls Section */}
148
+ <div className="controls">
149
+ <h3>Chart Controls</h3>
150
+ <div>
151
+ <button onClick={() => setCurrentChart('line')}>Line Chart</button>
152
+ <button onClick={() => setCurrentChart('bar')}>Bar Chart</button>
153
+ <button onClick={() => setCurrentChart('pie')}>Pie Chart</button>
154
+ <button onClick={updateData}>Update Data</button>
155
+ <button onClick={toggleLoading}>{loading ? 'Hide Loading' : 'Show Loading'}</button>
156
+ <button onClick={toggleDarkMode}>{darkMode ? 'Light Mode' : 'Dark Mode'}</button>
157
+ </div>
158
+ </div>
159
+
160
+ {/* Theme Switcher */}
161
+ <div className="theme-switcher">
162
+ <label htmlFor="theme">Current Theme:</label>
163
+ <select
164
+ id="theme"
165
+ value={darkMode ? 'dark' : 'light'}
166
+ onChange={(e) => setDarkMode(e.target.value === 'dark')}
167
+ >
168
+ <option value="light">Light</option>
169
+ <option value="dark">Dark</option>
170
+ </select>
171
+ </div>
172
+
173
+ {/* Chart Sections */}
174
+ <h2>BaseChart Component</h2>
175
+ <div className="chart-container">
176
+ <div className="chart-title">BaseChart with {currentChart} data</div>
177
+ <BaseChart
178
+ option={asChartOptions(
179
+ currentChart === 'line' ? lineOption : currentChart === 'bar' ? barOption : pieOption
180
+ )}
181
+ width="100%"
182
+ height="400px"
183
+ theme={darkMode ? 'dark' : 'default'}
184
+ loading={loading}
185
+ onReady={(chart: EChartsType) => {
186
+ console.log('BaseChart is ready:', chart);
187
+ }}
188
+ />
189
+ </div>
190
+
191
+ <h2>Specialized Chart Components</h2>
192
+
193
+ {/* LineChart Example */}
194
+ <div className="chart-container">
195
+ <div className="chart-title">LineChart Component</div>
196
+ <LineChart
197
+ option={asChartOptions(lineOption)}
198
+ width="100%"
199
+ height="300px"
200
+ theme={darkMode ? 'dark' : 'default'}
201
+ />
202
+ </div>
203
+
204
+ {/* BarChart Example */}
205
+ <div className="chart-container">
206
+ <div className="chart-title">BarChart Component</div>
207
+ <BarChart
208
+ option={asChartOptions(barOption)}
209
+ width="100%"
210
+ height="300px"
211
+ theme={darkMode ? 'dark' : 'default'}
212
+ />
213
+ </div>
214
+
215
+ {/* PieChart Example */}
216
+ <div className="chart-container">
217
+ <div className="chart-title">PieChart Component</div>
218
+ <PieChart
219
+ option={asChartOptions(pieOption)}
220
+ width="100%"
221
+ height="300px"
222
+ theme={darkMode ? 'dark' : 'default'}
223
+ />
224
+ </div>
225
+
226
+ <h2>Responsive Charts</h2>
227
+ <div className="chart-container">
228
+ <div className="chart-title">Responsive BaseChart (50% width)</div>
229
+ <BaseChart
230
+ option={asChartOptions(lineOption)}
231
+ width="50%"
232
+ height="300px"
233
+ theme={darkMode ? 'dark' : 'default'}
234
+ />
235
+ </div>
236
+ </div>
237
+ );
238
+ };
239
+
240
+ // Render the test application
241
+ const container = document.getElementById('root') as HTMLElement;
242
+ const root = createRoot(container);
243
+ root.render(
244
+ <React.StrictMode>
245
+ <TestApp />
246
+ </React.StrictMode>
247
+ );
@@ -0,0 +1,7 @@
1
+ declare module 'react-dom' {
2
+ export function render(
3
+ element: React.ReactElement<any, string | React.JSXElementConstructor<any>>,
4
+ container: Element | null,
5
+ callback?: () => void
6
+ ): React.ReactInstance;
7
+ }
@@ -0,0 +1,91 @@
1
+ import { getTheme, registerTheme, defaultTheme, darkTheme } from '../index';
2
+
3
+ describe('Theme System', () => {
4
+ describe('getTheme', () => {
5
+ it('should return defaultTheme when no options are provided', () => {
6
+ const result = getTheme();
7
+ expect(result).toEqual(defaultTheme);
8
+ });
9
+
10
+ it('should return darkTheme when darkMode is true', () => {
11
+ const result = getTheme({ darkMode: true });
12
+ expect(result.darkMode).toBe(true);
13
+ expect(result.theme).toBe('dark');
14
+ expect(result.backgroundColor).toBe('#0f1117');
15
+ });
16
+
17
+ it('should merge custom options with defaultTheme', () => {
18
+ const customColors = ['#ff0000', '#00ff00', '#0000ff'];
19
+ const result = getTheme({ colors: customColors, textColor: '#666' });
20
+
21
+ expect(result).toEqual({
22
+ ...defaultTheme,
23
+ colors: customColors,
24
+ textColor: '#666',
25
+ });
26
+ });
27
+
28
+ it('should merge custom options with darkTheme when darkMode is true', () => {
29
+ const customFont = 'Arial, sans-serif';
30
+ const result = getTheme({ darkMode: true, fontFamily: customFont });
31
+
32
+ expect(result).toEqual({
33
+ ...darkTheme,
34
+ fontFamily: customFont,
35
+ });
36
+ });
37
+
38
+ it('should accept custom theme object', () => {
39
+ const customTheme = { backgroundColor: '#f0f0f0', textColor: '#333' };
40
+ const result = getTheme({ theme: customTheme });
41
+
42
+ expect(result.theme).toEqual(customTheme);
43
+ });
44
+
45
+ it('should accept builtin theme name as string', () => {
46
+ const result = getTheme({ theme: 'vintage' });
47
+
48
+ expect(result.theme).toBe('vintage');
49
+ });
50
+ });
51
+
52
+ describe('registerTheme', () => {
53
+ it('should log when registering a theme', () => {
54
+ // Mock console.log
55
+ const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
56
+
57
+ registerTheme('custom-theme', { backgroundColor: '#123' });
58
+
59
+ expect(consoleSpy).toHaveBeenCalledWith('Registering theme: custom-theme');
60
+
61
+ // Restore console.log
62
+ consoleSpy.mockRestore();
63
+ });
64
+ });
65
+
66
+ describe('defaultTheme', () => {
67
+ it('should have correct default values', () => {
68
+ expect(defaultTheme).toHaveProperty('theme', 'default');
69
+ expect(defaultTheme).toHaveProperty('darkMode', false);
70
+ expect(defaultTheme).toHaveProperty('colors');
71
+ expect(Array.isArray(defaultTheme.colors)).toBe(true);
72
+ expect(defaultTheme.colors).toHaveLength(9);
73
+ expect(defaultTheme).toHaveProperty('backgroundColor', 'transparent');
74
+ expect(defaultTheme).toHaveProperty('textColor', '#333');
75
+ expect(defaultTheme).toHaveProperty('fontFamily');
76
+ });
77
+ });
78
+
79
+ describe('darkTheme', () => {
80
+ it('should have correct dark mode values', () => {
81
+ expect(darkTheme).toHaveProperty('theme', 'dark');
82
+ expect(darkTheme).toHaveProperty('darkMode', true);
83
+ expect(darkTheme).toHaveProperty('colors');
84
+ expect(Array.isArray(darkTheme.colors)).toBe(true);
85
+ expect(darkTheme.colors).toHaveLength(9);
86
+ expect(darkTheme).toHaveProperty('backgroundColor', '#0f1117');
87
+ expect(darkTheme).toHaveProperty('textColor', '#e1e1e1');
88
+ expect(darkTheme).toHaveProperty('fontFamily');
89
+ });
90
+ });
91
+ });