@antv/gpt-vis 1.0.0-beta.1 → 1.0.0-beta.2

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 (157) hide show
  1. package/README.md +6 -4
  2. package/README.zh-CN.md +6 -4
  3. package/dist/cjs/gpt-vis/index.d.ts +8 -1
  4. package/dist/cjs/gpt-vis/index.js +43 -20
  5. package/dist/cjs/index.d.ts +15 -2
  6. package/dist/cjs/index.js +22 -2
  7. package/dist/cjs/syntax/parser.d.ts +17 -2
  8. package/dist/cjs/syntax/parser.js +151 -38
  9. package/dist/cjs/util/container.d.ts +5 -0
  10. package/dist/cjs/util/container.js +43 -0
  11. package/dist/cjs/util/theme.d.ts +5 -0
  12. package/dist/cjs/util/theme.js +9 -2
  13. package/dist/cjs/vis/area/index.js +2 -1
  14. package/dist/cjs/vis/bar/index.js +5 -4
  15. package/dist/cjs/vis/boxplot/index.js +7 -2
  16. package/dist/cjs/vis/column/index.js +5 -4
  17. package/dist/cjs/vis/dual-axes/index.js +2 -1
  18. package/dist/cjs/vis/fishbone-diagram/index.d.ts +35 -0
  19. package/dist/cjs/vis/fishbone-diagram/index.js +183 -0
  20. package/dist/cjs/vis/flow-diagram/index.d.ts +27 -0
  21. package/dist/cjs/vis/flow-diagram/index.js +271 -0
  22. package/dist/cjs/vis/funnel/index.js +2 -1
  23. package/dist/cjs/vis/histogram/index.js +3 -7
  24. package/dist/cjs/vis/indented-tree/index.d.ts +40 -0
  25. package/dist/cjs/vis/indented-tree/index.js +375 -0
  26. package/dist/cjs/vis/line/index.js +2 -1
  27. package/dist/cjs/vis/liquid/index.js +2 -1
  28. package/dist/cjs/vis/mindmap/index.d.ts +32 -0
  29. package/dist/cjs/vis/mindmap/index.js +214 -0
  30. package/dist/cjs/vis/network-graph/index.d.ts +59 -0
  31. package/dist/cjs/vis/network-graph/index.js +166 -0
  32. package/dist/cjs/vis/organization-chart/index.d.ts +64 -0
  33. package/dist/cjs/vis/organization-chart/index.js +191 -0
  34. package/dist/cjs/vis/pie/index.js +3 -3
  35. package/dist/cjs/vis/radar/index.d.ts +1 -0
  36. package/dist/cjs/vis/radar/index.js +10 -9
  37. package/dist/cjs/vis/sankey/index.js +2 -1
  38. package/dist/cjs/vis/scatter/index.js +2 -1
  39. package/dist/cjs/vis/summary/index.js +17 -3
  40. package/dist/cjs/vis/table/index.d.ts +1 -0
  41. package/dist/cjs/vis/table/index.js +37 -1
  42. package/dist/cjs/vis/treemap/index.js +2 -1
  43. package/dist/cjs/vis/venn/index.d.ts +2 -1
  44. package/dist/cjs/vis/venn/index.js +18 -3
  45. package/dist/cjs/vis/violin/index.js +2 -1
  46. package/dist/cjs/vis/waterfall/index.d.ts +6 -9
  47. package/dist/cjs/vis/waterfall/index.js +28 -5
  48. package/dist/cjs/vis/word-cloud/index.js +2 -1
  49. package/dist/cjs/vis-wrapper/icons.js +2 -2
  50. package/dist/cjs/vis-wrapper/index.d.ts +1 -0
  51. package/dist/cjs/vis-wrapper/index.js +27 -16
  52. package/dist/cjs/vis-wrapper/styles.d.ts +1 -1
  53. package/dist/cjs/vis-wrapper/styles.js +8 -1
  54. package/dist/esm/gpt-vis/index.d.ts +8 -1
  55. package/dist/esm/gpt-vis/index.js +47 -26
  56. package/dist/esm/index.d.ts +15 -2
  57. package/dist/esm/index.js +7 -1
  58. package/dist/esm/syntax/parser.d.ts +17 -2
  59. package/dist/esm/syntax/parser.js +248 -90
  60. package/dist/esm/util/container.d.ts +5 -0
  61. package/dist/esm/util/container.js +20 -0
  62. package/dist/esm/util/theme.d.ts +5 -0
  63. package/dist/esm/util/theme.js +9 -0
  64. package/dist/esm/vis/area/index.js +3 -2
  65. package/dist/esm/vis/bar/index.js +7 -6
  66. package/dist/esm/vis/boxplot/index.js +17 -4
  67. package/dist/esm/vis/column/index.js +7 -6
  68. package/dist/esm/vis/dual-axes/index.js +3 -2
  69. package/dist/esm/vis/fishbone-diagram/index.d.ts +35 -0
  70. package/dist/esm/vis/fishbone-diagram/index.js +218 -0
  71. package/dist/esm/vis/flow-diagram/index.d.ts +27 -0
  72. package/dist/esm/vis/flow-diagram/index.js +342 -0
  73. package/dist/esm/vis/funnel/index.js +3 -2
  74. package/dist/esm/vis/histogram/index.js +6 -7
  75. package/dist/esm/vis/indented-tree/index.d.ts +40 -0
  76. package/dist/esm/vis/indented-tree/index.js +564 -0
  77. package/dist/esm/vis/line/index.js +3 -2
  78. package/dist/esm/vis/liquid/index.js +3 -2
  79. package/dist/esm/vis/mindmap/index.d.ts +32 -0
  80. package/dist/esm/vis/mindmap/index.js +315 -0
  81. package/dist/esm/vis/network-graph/index.d.ts +59 -0
  82. package/dist/esm/vis/network-graph/index.js +240 -0
  83. package/dist/esm/vis/organization-chart/index.d.ts +64 -0
  84. package/dist/esm/vis/organization-chart/index.js +269 -0
  85. package/dist/esm/vis/pie/index.js +4 -8
  86. package/dist/esm/vis/radar/index.d.ts +1 -0
  87. package/dist/esm/vis/radar/index.js +20 -4
  88. package/dist/esm/vis/sankey/index.js +3 -2
  89. package/dist/esm/vis/scatter/index.js +3 -2
  90. package/dist/esm/vis/summary/index.js +25 -4
  91. package/dist/esm/vis/table/index.d.ts +1 -0
  92. package/dist/esm/vis/table/index.js +9 -2
  93. package/dist/esm/vis/treemap/index.js +3 -2
  94. package/dist/esm/vis/venn/index.d.ts +2 -1
  95. package/dist/esm/vis/venn/index.js +29 -4
  96. package/dist/esm/vis/violin/index.js +3 -2
  97. package/dist/esm/vis/waterfall/index.d.ts +6 -9
  98. package/dist/esm/vis/waterfall/index.js +27 -9
  99. package/dist/esm/vis/word-cloud/index.js +3 -2
  100. package/dist/esm/vis-wrapper/icons.js +2 -2
  101. package/dist/esm/vis-wrapper/index.d.ts +1 -0
  102. package/dist/esm/vis-wrapper/index.js +15 -10
  103. package/dist/esm/vis-wrapper/styles.d.ts +1 -1
  104. package/dist/esm/vis-wrapper/styles.js +1 -1
  105. package/dist/umd/index.min.js +1 -1
  106. package/package.json +19 -19
  107. package/src/gpt-vis/index.ts +0 -283
  108. package/src/index.ts +0 -44
  109. package/src/readme.md +0 -37
  110. package/src/syntax/index.ts +0 -2
  111. package/src/syntax/parser.ts +0 -411
  112. package/src/types/index.ts +0 -29
  113. package/src/util/theme.ts +0 -167
  114. package/src/vis/area/README.md +0 -143
  115. package/src/vis/area/index.ts +0 -212
  116. package/src/vis/bar/README.md +0 -158
  117. package/src/vis/bar/index.ts +0 -186
  118. package/src/vis/boxplot/README.md +0 -168
  119. package/src/vis/boxplot/index.ts +0 -162
  120. package/src/vis/column/README.md +0 -158
  121. package/src/vis/column/index.ts +0 -185
  122. package/src/vis/dual-axes/README.md +0 -191
  123. package/src/vis/dual-axes/index.ts +0 -218
  124. package/src/vis/funnel/README.md +0 -143
  125. package/src/vis/funnel/index.ts +0 -238
  126. package/src/vis/histogram/README.md +0 -130
  127. package/src/vis/histogram/index.ts +0 -153
  128. package/src/vis/line/README.md +0 -138
  129. package/src/vis/line/index.ts +0 -159
  130. package/src/vis/liquid/README.md +0 -150
  131. package/src/vis/liquid/index.ts +0 -130
  132. package/src/vis/pie/README.md +0 -127
  133. package/src/vis/pie/index.ts +0 -163
  134. package/src/vis/radar/README.md +0 -184
  135. package/src/vis/radar/index.ts +0 -214
  136. package/src/vis/sankey/README.md +0 -144
  137. package/src/vis/sankey/index.ts +0 -144
  138. package/src/vis/scatter/README.md +0 -145
  139. package/src/vis/scatter/index.ts +0 -147
  140. package/src/vis/summary/README.md +0 -272
  141. package/src/vis/summary/index.ts +0 -91
  142. package/src/vis/table/README.md +0 -174
  143. package/src/vis/table/index.ts +0 -241
  144. package/src/vis/treemap/README.md +0 -199
  145. package/src/vis/treemap/index.ts +0 -167
  146. package/src/vis/venn/README.md +0 -153
  147. package/src/vis/venn/index.ts +0 -149
  148. package/src/vis/violin/README.md +0 -168
  149. package/src/vis/violin/index.ts +0 -216
  150. package/src/vis/waterfall/README.md +0 -178
  151. package/src/vis/waterfall/index.ts +0 -258
  152. package/src/vis/word-cloud/README.md +0 -137
  153. package/src/vis/word-cloud/index.ts +0 -137
  154. package/src/vis-wrapper/README.md +0 -159
  155. package/src/vis-wrapper/icons.ts +0 -35
  156. package/src/vis-wrapper/index.ts +0 -276
  157. package/src/vis-wrapper/styles.ts +0 -195
@@ -1,91 +0,0 @@
1
- import { Text } from '@antv/t8';
2
- import type { VisualizationOptions } from '../../types';
3
-
4
- /**
5
- * SummaryConfig is a T8 Syntax string for narrative text visualization.
6
- * Supports markdown-like syntax with special annotations for metrics.
7
- * @example
8
- * ```
9
- * # Sales Report
10
- * Total sales reached [¥1,234,567](metric_value, origin=1234567).
11
- * ```
12
- */
13
- export type SummaryConfig = string;
14
-
15
- /**
16
- * SummaryInstance represents a summary instance with render and destroy methods.
17
- */
18
- export interface SummaryInstance {
19
- render: (syntax: SummaryConfig) => void;
20
- destroy: () => void;
21
- }
22
-
23
- /**
24
- * Summary component using @antv/t8 for narrative text visualization.
25
- *
26
- * This component provides a way to render data summaries with rich text formatting
27
- * and inline data visualization using T8 syntax (markdown-like syntax).
28
- *
29
- * @example
30
- * ```ts
31
- * const summary = Summary({
32
- * container: '#container',
33
- * theme: 'light',
34
- * });
35
- *
36
- * summary.render(`
37
- * # Sales Report
38
- * Total sales reached [¥1,234,567](metric_value, origin=1234567).
39
- * This represents a [15%](delta_value, status=increase) increase compared to last quarter.
40
- * `);
41
- *
42
- * summary.destroy();
43
- * ```
44
- */
45
- export const Summary = (options: VisualizationOptions): SummaryInstance => {
46
- // T8 only supports 'light' and 'dark', so map 'academy' to 'light'
47
- let { theme = 'light' } = options;
48
- if (theme === 'academy' || theme === 'default') theme = 'light';
49
- const container =
50
- typeof options.container === 'string'
51
- ? document.querySelector(options.container)
52
- : options.container;
53
-
54
- if (!container) {
55
- throw new Error('Container not found');
56
- }
57
-
58
- let text: Text | null = null;
59
-
60
- /**
61
- * Render the summary with the given T8 syntax string.
62
- */
63
- const render = (syntax: SummaryConfig): void => {
64
- // Clean up previous instance if exists
65
- if (text) {
66
- text.unmount();
67
- }
68
-
69
- // Create T8 Text instance
70
- text = new Text(container as HTMLElement);
71
-
72
- // Set theme and render syntax
73
- text.theme(theme);
74
- text.render(syntax);
75
- };
76
-
77
- /**
78
- * Destroy the summary instance and clean up resources.
79
- */
80
- const destroy = (): void => {
81
- if (text) {
82
- text.unmount();
83
- text = null;
84
- }
85
- };
86
-
87
- return {
88
- render,
89
- destroy,
90
- };
91
- };
@@ -1,174 +0,0 @@
1
- # Table
2
-
3
- A table component for displaying structured data in rows and columns, built with pure JavaScript.
4
-
5
- ## Usage
6
-
7
- ```ts
8
- import { Table } from '@antv/gpt-vis/ai';
9
-
10
- const table = Table({
11
- container: '#container',
12
- width: 600,
13
- height: 400,
14
- });
15
-
16
- table.render({
17
- type: 'table',
18
- data: [
19
- {
20
- Indicator: '经度(°)',
21
- Mean: '104.15°',
22
- Std: '±0.64°',
23
- Range: '103.19-105.28',
24
- Q1Q3: '103.62-104.68°',
25
- },
26
- {
27
- Indicator: '纬度(°)',
28
- Mean: '31.60°',
29
- Std: '±0.48°',
30
- Range: '30.89-32.45°',
31
- Q1Q3: '31.21-32.00°',
32
- },
33
- { Indicator: '深度(km)', Mean: '11.82', Std: '±5.67', Range: '3.0-34.8', Q1Q3: '10.0-10.0' },
34
- { Indicator: '震级(mag)', Mean: '5.29', Std: '±0.49', Range: '5.0-7.9', Q1Q3: '5.0-5.4' },
35
- ],
36
- title: '一个文本标题',
37
- });
38
-
39
- table.destroy();
40
- ```
41
-
42
- ## Configuration
43
-
44
- ### Constructor Options (VisualizationOptions)
45
-
46
- | Property | Type | Default | Description |
47
- | --------- | --------------------- | ------- | ----------------------------- |
48
- | container | string \| HTMLElement | - | Container element or selector |
49
- | width | number | 640 | Chart width in pixels |
50
- | height | number | 480 | Chart height in pixels |
51
-
52
- ### Render Config (TableConfig)
53
-
54
- | Property | Type | Default | Description |
55
- | -------- | --------------------- | ------- | ---------------------- |
56
- | data | Record<string, any>[] | - | Table data array |
57
- | type | string | 'table' | Chart type identifier |
58
- | title | string | - | Table title (optional) |
59
-
60
- ### Data Structure
61
-
62
- The `data` property should be an array of objects where each object represents a row in the table. The keys of the objects will be used as column headers.
63
-
64
- ```ts
65
- type TableData = Record<string, any>[];
66
- ```
67
-
68
- ## Features
69
-
70
- - **Pure JavaScript**: No React or other framework dependencies
71
- - **Scoped CSS**: Dynamic CSS injection with automatic scoping to avoid style conflicts
72
- - **Responsive**: Automatically adapts to container size
73
- - **Hover Effects**: Interactive row highlighting on hover
74
- - **Clean Styling**: Modern, minimalist design with proper spacing and borders
75
-
76
- ## Examples
77
-
78
- ### Basic Table
79
-
80
- ```ts
81
- table.render({
82
- data: [
83
- { 类别: '火锅', '营收额占比(%)': 22 },
84
- { 类别: '自助餐', '营收额占比(%)': 12 },
85
- { 类别: '小吃快餐', '营收额占比(%)': 8 },
86
- { 类别: '西餐', '营收额占比(%)': 6 },
87
- { 类别: '其它', '营收额占比(%)': 44 },
88
- ],
89
- });
90
- ```
91
-
92
- ### Table with Title
93
-
94
- ```ts
95
- table.render({
96
- data: [
97
- { 类别: '火锅', '营收额占比(%)': 22 },
98
- { 类别: '自助餐', '营收额占比(%)': 12 },
99
- { 类别: '小吃快餐', '营收额占比(%)': 8 },
100
- { 类别: '西餐', '营收额占比(%)': 6 },
101
- { 类别: '其它', '营收额占比(%)': 44 },
102
- ],
103
- title: '餐饮业营收额数据表',
104
- });
105
- ```
106
-
107
- ### Population Distribution Table
108
-
109
- ```ts
110
- table.render({
111
- data: [
112
- { 人口类型: '城镇人口', '数量(万人)': 63.89 },
113
- { 人口类型: '乡村人口', '数量(万人)': 36.11 },
114
- ],
115
- title: '全国人口居住分布',
116
- });
117
- ```
118
-
119
- ### Industrial Structure Table
120
-
121
- ```ts
122
- table.render({
123
- data: [
124
- { 产业类型: '第一产业', '产值(亿元)': 7200.0 },
125
- { 产业类型: '第二产业', '产值(亿元)': 36600.0 },
126
- { 产业类型: '第三产业', '产值(亿元)': 41000.0 },
127
- ],
128
- });
129
- ```
130
-
131
- ### Seismic Data Table
132
-
133
- ```ts
134
- table.render({
135
- data: [
136
- {
137
- Indicator: '经度(°)',
138
- Mean: '104.15°',
139
- Std: '±0.64°',
140
- Range: '103.19-105.28',
141
- Q1Q3: '103.62-104.68°',
142
- },
143
- {
144
- Indicator: '纬度(°)',
145
- Mean: '31.60°',
146
- Std: '±0.48°',
147
- Range: '30.89-32.45°',
148
- Q1Q3: '31.21-32.00°',
149
- },
150
- { Indicator: '深度(km)', Mean: '11.82', Std: '±5.67', Range: '3.0-34.8', Q1Q3: '10.0-10.0' },
151
- { Indicator: '震级(mag)', Mean: '5.29', Std: '±0.49', Range: '5.0-7.9', Q1Q3: '5.0-5.4' },
152
- ],
153
- title: '地震数据统计表',
154
- });
155
- ```
156
-
157
- ## Methods
158
-
159
- - `render(config: TableConfig): void` - Render or update the table
160
- - `destroy(): void` - Destroy the table instance and clean up resources (including injected styles)
161
-
162
- ## Use Cases
163
-
164
- - Displaying structured data like reports, lists, and detail tables
165
- - Comparing multiple data items with several attributes
166
- - Presenting statistical data in a clear, organized format
167
- - When data needs to be searchable, sortable, or filterable
168
- - Financial statements, scorecards, product lists, etc.
169
-
170
- ## When Not to Use
171
-
172
- - When data has hierarchical or network relationships (use tree or graph visualizations instead)
173
- - When you need to emphasize data distribution, trends, or proportions (use charts like bar, line, or pie instead)
174
- - When the dataset is extremely large with many fields (consider pagination or grouping)
@@ -1,241 +0,0 @@
1
- import { measureText } from 'measury';
2
-
3
- import type { VisualizationOptions } from '../../types';
4
-
5
- /**
6
- * TableConfig defines the configuration for rendering the table.
7
- */
8
- export interface TableConfig {
9
- type?: 'table';
10
- data: Record<string, any>[];
11
- title?: string;
12
- }
13
-
14
- /**
15
- * TableInstance represents a table instance with render and destroy methods.
16
- */
17
- export interface TableInstance {
18
- render: (config: TableConfig) => void;
19
- destroy: () => void;
20
- }
21
-
22
- const SCOPE_ID = '__gpt-vis-table__';
23
- const FONT_FAMILY =
24
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
25
- const CELL_PADDING = 16; // 8px * 2
26
- const MIN_WIDTH_MULTIPLIER = 1.1;
27
-
28
- // CSS styles for the table component
29
- const TABLE_STYLES = `
30
- .${SCOPE_ID} {
31
- font-family: ${FONT_FAMILY};
32
- overflow: auto;
33
- height: 100%;
34
- }
35
-
36
- .${SCOPE_ID} .table-title {
37
- font-size: 16px;
38
- font-weight: 500;
39
- margin-bottom: 12px;
40
- color: #1d2129;
41
- }
42
-
43
- .${SCOPE_ID} table {
44
- border-collapse: separate;
45
- border-spacing: 0;
46
- background: #fff;
47
- border-radius: 8px;
48
- overflow: hidden;
49
- }
50
-
51
- .${SCOPE_ID} th,
52
- .${SCOPE_ID} td {
53
- border-bottom: 1px solid #f0f0f0;
54
- padding: 8px;
55
- text-align: left;
56
- font-size: 14px;
57
- color: #333;
58
- white-space: nowrap;
59
- }
60
-
61
- .${SCOPE_ID} th {
62
- background: #f5f5f5;
63
- font-weight: 600;
64
- color: #000000e0;
65
- position: relative;
66
- }
67
-
68
- .${SCOPE_ID} th:not(:last-child)::after {
69
- content: '';
70
- position: absolute;
71
- top: 25%;
72
- right: 0;
73
- width: 1px;
74
- height: 50%;
75
- background: #e0e0e0;
76
- }
77
-
78
- .${SCOPE_ID} tr {
79
- transition: background 0.2s;
80
- }
81
-
82
- .${SCOPE_ID} tbody tr:hover {
83
- background: #f5f5f5;
84
- cursor: pointer;
85
- }
86
- `;
87
-
88
- /**
89
- * Calculate the minimum width needed for a table based on its data.
90
- * This is a pure function that measures text width and returns the calculated min-width.
91
- *
92
- * @param data - Table data array
93
- * @param columns - Column names array
94
- * @returns Calculated minimum width in pixels
95
- */
96
- export const calculateTableMinWidth = (data: Record<string, any>[], columns: string[]): number => {
97
- let maxRowWidth = 0;
98
-
99
- // Measure header row
100
- const headerWidth = columns.reduce((total, col) => {
101
- const metrics = measureText(String(col), {
102
- fontFamily: FONT_FAMILY,
103
- fontSize: 14,
104
- fontWeight: '600',
105
- });
106
- return total + metrics.width + CELL_PADDING;
107
- }, 0);
108
- maxRowWidth = Math.max(maxRowWidth, headerWidth);
109
-
110
- // Measure each data row
111
- data.forEach((row) => {
112
- const rowText = columns.map((col) => String(row[col] != null ? row[col] : '')).join('');
113
- const metrics = measureText(rowText, {
114
- fontFamily: FONT_FAMILY,
115
- fontSize: 14,
116
- });
117
- const rowWidth = metrics.width + columns.length * CELL_PADDING;
118
- maxRowWidth = Math.max(maxRowWidth, rowWidth);
119
- });
120
-
121
- // Return min-width with 110% multiplier for optimal spacing
122
- return maxRowWidth * MIN_WIDTH_MULTIPLIER;
123
- };
124
-
125
- // Inject CSS into the document head if not already present
126
- const injectStyles = (): void => {
127
- if (document.querySelector(`style[data-scope="${SCOPE_ID}"]`)) {
128
- return;
129
- }
130
- const styleElement = document.createElement('style');
131
- styleElement.setAttribute('data-scope', SCOPE_ID);
132
- styleElement.textContent = TABLE_STYLES;
133
- document.head.appendChild(styleElement);
134
- };
135
-
136
- /**
137
- * Table component using pure JavaScript.
138
- *
139
- * @example
140
- * ```ts
141
- * const table = Table({
142
- * container: '#container',
143
- * width: 600,
144
- * height: 400,
145
- * });
146
- *
147
- * table.render({
148
- * type: 'table',
149
- * data: [
150
- * { "Indicator": "经度(°)", "Mean": "104.15°", "Std": "±0.64°" },
151
- * { "Indicator": "纬度(°)", "Mean": "31.60°", "Std": "±0.48°" },
152
- * ],
153
- * title: '一个文本标题',
154
- * });
155
- *
156
- * table.destroy();
157
- * ```
158
- */
159
- export const Table = (options: VisualizationOptions): TableInstance => {
160
- const container =
161
- typeof options.container === 'string'
162
- ? document.querySelector(options.container)
163
- : options.container;
164
-
165
- if (!container) {
166
- throw new Error('Container not found');
167
- }
168
-
169
- let tableWrapper: HTMLDivElement | null = null;
170
-
171
- /**
172
- * Render the table with the given configuration.
173
- */
174
- const render = (config: TableConfig): void => {
175
- const { data = [], title } = config;
176
-
177
- // Inject styles if not already present
178
- injectStyles();
179
-
180
- // Clean up previous render
181
- if (tableWrapper) {
182
- tableWrapper.remove();
183
- }
184
-
185
- // Create wrapper element
186
- tableWrapper = document.createElement('div');
187
- tableWrapper.className = SCOPE_ID;
188
-
189
- // Handle empty data case
190
- if (data.length === 0) {
191
- tableWrapper.innerHTML = `
192
- ${title ? `<div class="table-title">${title}</div>` : ''}
193
- <div style="padding: 20px; text-align: center; color: #999;">No data available</div>
194
- `;
195
- container.appendChild(tableWrapper);
196
- return;
197
- }
198
-
199
- // Get columns from the first data item
200
- const columns = Object.keys(data[0]);
201
-
202
- // Calculate the minimum width needed for the table using pure function
203
- let minWidth = calculateTableMinWidth(data, columns);
204
- // Ensure a minimum width for columns
205
- minWidth = Math.max(minWidth, columns.length * 100);
206
-
207
- // Build table HTML using template strings
208
- const headerHTML = columns.map((col) => `<th>${col}</th>`).join('');
209
- const bodyHTML = data
210
- .map(
211
- (row) =>
212
- `<tr>${columns.map((col) => `<td>${row[col] != null ? row[col] : ''}</td>`).join('')}</tr>`,
213
- )
214
- .join('');
215
-
216
- tableWrapper.innerHTML = `
217
- ${title ? `<div class="table-title">${title}</div>` : ''}
218
- <table style="min-width: ${minWidth}px;">
219
- <thead><tr>${headerHTML}</tr></thead>
220
- <tbody>${bodyHTML}</tbody>
221
- </table>
222
- `;
223
-
224
- container.appendChild(tableWrapper);
225
- };
226
-
227
- /**
228
- * Destroy the table instance and clean up resources.
229
- */
230
- const destroy = (): void => {
231
- if (tableWrapper) {
232
- tableWrapper.remove();
233
- tableWrapper = null;
234
- }
235
- };
236
-
237
- return {
238
- render,
239
- destroy,
240
- };
241
- };
@@ -1,199 +0,0 @@
1
- # Treemap
2
-
3
- A treemap chart component for visualizing hierarchical data structures, built with G2 5.0.
4
-
5
- ## Usage
6
-
7
- ```ts
8
- import { Treemap } from '@antv/gpt-vis/ai';
9
-
10
- const treemap = Treemap({
11
- container: '#container',
12
- width: 600,
13
- height: 400,
14
- });
15
-
16
- treemap.render({
17
- data: [
18
- {
19
- name: 'A',
20
- value: 100,
21
- children: [
22
- { name: 'A1', value: 40 },
23
- { name: 'A2', value: 30 },
24
- { name: 'A3', value: 30 },
25
- ],
26
- },
27
- {
28
- name: 'B',
29
- value: 80,
30
- children: [
31
- { name: 'B1', value: 50 },
32
- { name: 'B2', value: 30 },
33
- ],
34
- },
35
- ],
36
- });
37
-
38
- treemap.destroy();
39
- ```
40
-
41
- ## Configuration
42
-
43
- ### Constructor Options (TreemapOptions)
44
-
45
- | Property | Type | Default | Description |
46
- | --------- | --------------------- | ------- | ----------------------------- |
47
- | container | string \| HTMLElement | - | Container element or selector |
48
- | width | number | 640 | Chart width in pixels |
49
- | height | number | 480 | Chart height in pixels |
50
-
51
- ### Render Config (TreemapConfig)
52
-
53
- | Property | Type | Default | Description |
54
- | -------- | ------ | --------- | ------------------------- |
55
- | data | Array | - | Hierarchical data array |
56
- | theme | string | 'default' | Color theme |
57
- | title | string | - | Chart title |
58
- | style | object | - | Chart style configuration |
59
-
60
- ### Data Structure
61
-
62
- ```ts
63
- type TreemapDataItem = {
64
- name: string; // Category name
65
- value: number; // Numeric value
66
- children?: TreemapDataItem[]; // Optional nested children
67
- };
68
- ```
69
-
70
- ### Style Options
71
-
72
- ```ts
73
- style?: {
74
- backgroundColor?: string; // Background color
75
- palette?: string[]; // Color palette
76
- }
77
- ```
78
-
79
- ## Examples
80
-
81
- ### Basic Example
82
-
83
- ```ts
84
- treemap.render({
85
- data: [
86
- {
87
- name: '产品A',
88
- value: 500,
89
- children: [
90
- { name: '子产品A1', value: 200 },
91
- { name: '子产品A2', value: 300 },
92
- ],
93
- },
94
- { name: '产品B', value: 400 },
95
- ],
96
- });
97
- ```
98
-
99
- ### With Theme
100
-
101
- ```ts
102
- treemap.render({
103
- data: [
104
- {
105
- name: 'A',
106
- value: 100,
107
- children: [
108
- { name: 'A1', value: 40 },
109
- { name: 'A2', value: 30 },
110
- { name: 'A3', value: 30 },
111
- ],
112
- },
113
- ],
114
- theme: 'academy',
115
- });
116
- ```
117
-
118
- ### With Title
119
-
120
- ```ts
121
- treemap.render({
122
- data: [
123
- {
124
- name: '苹果',
125
- value: 800,
126
- children: [
127
- { name: '红富士', value: 400 },
128
- { name: '黄元帅', value: 400 },
129
- ],
130
- },
131
- { name: '橙子', value: 600 },
132
- { name: '香蕉', value: 500 },
133
- ],
134
- title: '水果销售量',
135
- });
136
- ```
137
-
138
- ### With Custom Styles
139
-
140
- ```ts
141
- treemap.render({
142
- data: [
143
- { name: 'A', value: 100 },
144
- { name: 'B', value: 80 },
145
- { name: 'C', value: 60 },
146
- ],
147
- style: {
148
- palette: ['#FF6B6B', '#4ECDC4', '#45B7D1'],
149
- },
150
- });
151
- ```
152
-
153
- ### Dark Theme
154
-
155
- ```ts
156
- treemap.render({
157
- data: [
158
- {
159
- name: 'A',
160
- value: 100,
161
- children: [
162
- { name: 'A1', value: 40 },
163
- { name: 'A2', value: 30 },
164
- { name: 'A3', value: 30 },
165
- ],
166
- },
167
- ],
168
- theme: 'dark',
169
- });
170
- ```
171
-
172
- ### Multiple Levels
173
-
174
- ```ts
175
- treemap.render({
176
- data: [
177
- {
178
- name: '部门A',
179
- value: 200,
180
- children: [
181
- {
182
- name: '组A1',
183
- value: 100,
184
- children: [
185
- { name: '成员1', value: 50 },
186
- { name: '成员2', value: 50 },
187
- ],
188
- },
189
- { name: '组A2', value: 100 },
190
- ],
191
- },
192
- ],
193
- });
194
- ```
195
-
196
- ## Methods
197
-
198
- - `render(config: TreemapConfig): void` - Render or update the chart
199
- - `destroy(): void` - Destroy the chart instance and clean up resources