@antv/gpt-vis 1.0.0 → 1.0.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.
- package/README.md +153 -34
- package/README.zh-CN.md +153 -34
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/util/animation.d.ts +2 -0
- package/dist/cjs/util/animation.js +38 -0
- package/dist/cjs/util/components.d.ts +15 -0
- package/dist/cjs/util/components.js +94 -0
- package/dist/cjs/util/crosshair-axis-labels.d.ts +15 -0
- package/dist/cjs/util/crosshair-axis-labels.js +401 -0
- package/dist/cjs/util/html.d.ts +1 -0
- package/dist/cjs/util/html.js +29 -0
- package/dist/cjs/util/index.d.ts +6 -0
- package/dist/cjs/util/index.js +33 -0
- package/dist/cjs/util/interaction.d.ts +14 -0
- package/dist/cjs/util/interaction.js +89 -0
- package/dist/cjs/util/theme.d.ts +18 -24
- package/dist/cjs/util/theme.js +303 -120
- package/dist/cjs/util/tokens.d.ts +31 -0
- package/dist/cjs/util/tokens.js +98 -0
- package/dist/cjs/vis/area/index.d.ts +2 -2
- package/dist/cjs/vis/area/index.js +76 -31
- package/dist/cjs/vis/bar/index.d.ts +2 -2
- package/dist/cjs/vis/bar/index.js +22 -19
- package/dist/cjs/vis/boxplot/index.js +1 -4
- package/dist/cjs/vis/column/index.d.ts +2 -2
- package/dist/cjs/vis/column/index.js +28 -18
- package/dist/cjs/vis/dual-axes/index.d.ts +2 -2
- package/dist/cjs/vis/dual-axes/index.js +107 -34
- package/dist/cjs/vis/funnel/index.d.ts +3 -2
- package/dist/cjs/vis/funnel/index.js +171 -94
- package/dist/cjs/vis/histogram/index.js +1 -4
- package/dist/cjs/vis/line/index.d.ts +2 -2
- package/dist/cjs/vis/line/index.js +71 -31
- package/dist/cjs/vis/liquid/index.d.ts +2 -2
- package/dist/cjs/vis/liquid/index.js +41 -16
- package/dist/cjs/vis/pie/index.d.ts +2 -2
- package/dist/cjs/vis/pie/index.js +26 -16
- package/dist/cjs/vis/radar/index.d.ts +2 -2
- package/dist/cjs/vis/radar/index.js +21 -29
- package/dist/cjs/vis/sankey/index.js +1 -4
- package/dist/cjs/vis/scatter/index.d.ts +2 -2
- package/dist/cjs/vis/scatter/index.js +40 -17
- package/dist/cjs/vis/table/index.js +13 -5
- package/dist/cjs/vis/treemap/index.js +1 -4
- package/dist/cjs/vis/venn/index.js +1 -4
- package/dist/cjs/vis/violin/index.js +1 -1
- package/dist/cjs/vis/waterfall/index.js +1 -1
- package/dist/cjs/vis/word-cloud/index.d.ts +3 -2
- package/dist/cjs/vis/word-cloud/index.js +125 -10
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/util/animation.d.ts +2 -0
- package/dist/esm/util/animation.js +17 -0
- package/dist/esm/util/components.d.ts +15 -0
- package/dist/esm/util/components.js +67 -0
- package/dist/esm/util/crosshair-axis-labels.d.ts +15 -0
- package/dist/esm/util/crosshair-axis-labels.js +431 -0
- package/dist/esm/util/html.d.ts +1 -0
- package/dist/esm/util/html.js +3 -0
- package/dist/esm/util/index.d.ts +6 -0
- package/dist/esm/util/index.js +6 -0
- package/dist/esm/util/interaction.d.ts +14 -0
- package/dist/esm/util/interaction.js +73 -0
- package/dist/esm/util/theme.d.ts +18 -24
- package/dist/esm/util/theme.js +302 -126
- package/dist/esm/util/tokens.d.ts +31 -0
- package/dist/esm/util/tokens.js +64 -0
- package/dist/esm/vis/area/index.d.ts +2 -2
- package/dist/esm/vis/area/index.js +91 -41
- package/dist/esm/vis/bar/index.d.ts +2 -2
- package/dist/esm/vis/bar/index.js +28 -29
- package/dist/esm/vis/boxplot/index.js +4 -5
- package/dist/esm/vis/column/index.d.ts +2 -2
- package/dist/esm/vis/column/index.js +36 -29
- package/dist/esm/vis/dual-axes/index.d.ts +2 -2
- package/dist/esm/vis/dual-axes/index.js +145 -42
- package/dist/esm/vis/funnel/index.d.ts +3 -2
- package/dist/esm/vis/funnel/index.js +159 -85
- package/dist/esm/vis/histogram/index.js +4 -5
- package/dist/esm/vis/line/index.d.ts +2 -2
- package/dist/esm/vis/line/index.js +80 -37
- package/dist/esm/vis/liquid/index.d.ts +2 -2
- package/dist/esm/vis/liquid/index.js +41 -14
- package/dist/esm/vis/pie/index.d.ts +2 -2
- package/dist/esm/vis/pie/index.js +36 -16
- package/dist/esm/vis/radar/index.d.ts +2 -2
- package/dist/esm/vis/radar/index.js +21 -34
- package/dist/esm/vis/sankey/index.js +4 -5
- package/dist/esm/vis/scatter/index.d.ts +2 -2
- package/dist/esm/vis/scatter/index.js +41 -25
- package/dist/esm/vis/table/index.js +9 -9
- package/dist/esm/vis/treemap/index.js +4 -5
- package/dist/esm/vis/venn/index.js +4 -5
- package/dist/esm/vis/violin/index.js +5 -13
- package/dist/esm/vis/waterfall/index.js +5 -7
- package/dist/esm/vis/word-cloud/index.d.ts +3 -2
- package/dist/esm/vis/word-cloud/index.js +158 -10
- package/dist/umd/index.min.js +1 -1
- package/package.json +18 -15
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ AI-native visualization library for the LLM era. Framework-agnostic, ready to us
|
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
26
|
<div align="center">
|
|
27
|
-
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*
|
|
27
|
+
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*yNtZT47dH1kAAAAAgBAAAAgAemJ7AQ/fmt.webp" width="100%" alt="GPT-Vis Hero Image" />
|
|
28
28
|
</div>
|
|
29
29
|
|
|
30
30
|
<br/>
|
|
@@ -57,19 +57,14 @@ const gptVis = new GPTVis({
|
|
|
57
57
|
height: 400,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
- time 2022
|
|
69
|
-
value 150
|
|
70
|
-
`;
|
|
71
|
-
|
|
72
|
-
gptVis.render(visSyntax);
|
|
60
|
+
gptVis.render({
|
|
61
|
+
type: 'line',
|
|
62
|
+
data: [
|
|
63
|
+
{ time: '2020', value: 100 },
|
|
64
|
+
{ time: '2021', value: 120 },
|
|
65
|
+
{ time: '2022', value: 150 },
|
|
66
|
+
],
|
|
67
|
+
});
|
|
73
68
|
```
|
|
74
69
|
|
|
75
70
|
### Streaming Rendering
|
|
@@ -94,9 +89,73 @@ function onToken(token) {
|
|
|
94
89
|
|
|
95
90
|
## 📚 Syntax Guide
|
|
96
91
|
|
|
97
|
-
`render()` supports two input formats:
|
|
92
|
+
`render()` supports two input formats: JSON objects (ideal for programmatic use) and DSL syntax (ideal for LLM streaming).
|
|
98
93
|
|
|
99
|
-
###
|
|
94
|
+
### Object Config
|
|
95
|
+
|
|
96
|
+
Pass JSON objects directly for programmatic chart creation:
|
|
97
|
+
|
|
98
|
+
**Line chart:**
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
gptVis.render({
|
|
102
|
+
type: 'line',
|
|
103
|
+
data: [
|
|
104
|
+
{ time: '2020', value: 100 },
|
|
105
|
+
{ time: '2021', value: 120 },
|
|
106
|
+
{ time: '2022', value: 150 },
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Pie chart:**
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
gptVis.render({
|
|
115
|
+
type: 'pie',
|
|
116
|
+
data: [
|
|
117
|
+
{ category: 'Android', value: 72 },
|
|
118
|
+
{ category: 'iOS', value: 28 },
|
|
119
|
+
],
|
|
120
|
+
innerRadius: 0.6,
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Themes:**
|
|
125
|
+
|
|
126
|
+
Three built-in themes, switchable via the `theme` property:
|
|
127
|
+
|
|
128
|
+
| Theme | Identifier | Background | Palette |
|
|
129
|
+
| --------------- | ---------- | ---------- | ----------------------------------------------------- |
|
|
130
|
+
| Default (Light) | `default` | `#FFF` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
131
|
+
| Dark | `dark` | `#000` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
132
|
+
| Academy | `academy` | `#FFF` | `#4e79a7` `#f28e2c` `#e15759` `#76b7b2` `#59a14f` ... |
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
gptVis.render({
|
|
136
|
+
type: 'line',
|
|
137
|
+
data: [
|
|
138
|
+
{ time: '2020', value: 100 },
|
|
139
|
+
{ time: '2021', value: 120 },
|
|
140
|
+
],
|
|
141
|
+
theme: 'dark',
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Custom Styles:**
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
gptVis.render({
|
|
149
|
+
type: 'line',
|
|
150
|
+
data: [
|
|
151
|
+
{ time: '2020', value: 100 },
|
|
152
|
+
{ time: '2021', value: 120 },
|
|
153
|
+
],
|
|
154
|
+
style: { lineWidth: 3, palette: ['#5B8FF9', '#5AD8A6'] },
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### DSL Syntax
|
|
100
159
|
|
|
101
160
|
Declarative markdown-like syntax that LLMs can generate without learning complex APIs:
|
|
102
161
|
|
|
@@ -121,14 +180,6 @@ innerRadius 0.6
|
|
|
121
180
|
|
|
122
181
|
**Themes:**
|
|
123
182
|
|
|
124
|
-
Three built-in themes, switchable via the `theme` property:
|
|
125
|
-
|
|
126
|
-
| Theme | Identifier | Background | Palette |
|
|
127
|
-
| --------------- | ---------- | ---------- | ----------------------------------------------------- |
|
|
128
|
-
| Default (Light) | `default` | `#FFF` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
129
|
-
| Dark | `dark` | `#000` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
130
|
-
| Academy | `academy` | `#FFF` | `#4e79a7` `#f28e2c` `#e15759` `#76b7b2` `#59a14f` ... |
|
|
131
|
-
|
|
132
183
|
```
|
|
133
184
|
vis line
|
|
134
185
|
data
|
|
@@ -179,18 +230,21 @@ data
|
|
|
179
230
|
- name Phase 2
|
|
180
231
|
```
|
|
181
232
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Also supports passing JSON objects directly, ideal for programmatic use:
|
|
233
|
+
**Render DSL syntax:**
|
|
185
234
|
|
|
186
235
|
```javascript
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
236
|
+
const visSyntax = `
|
|
237
|
+
vis line
|
|
238
|
+
data
|
|
239
|
+
- time 2020
|
|
240
|
+
value 100
|
|
241
|
+
- time 2021
|
|
242
|
+
value 120
|
|
243
|
+
- time 2022
|
|
244
|
+
value 150
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
gptVis.render(visSyntax);
|
|
194
248
|
```
|
|
195
249
|
|
|
196
250
|
## 📊 Chart Types
|
|
@@ -391,6 +445,71 @@ document.getElementById('content').innerHTML = marked.parse(markdown);
|
|
|
391
445
|
|
|
392
446
|
</details>
|
|
393
447
|
|
|
448
|
+
## 🧩 Shadcn/ui
|
|
449
|
+
|
|
450
|
+
Copy GPT-Vis React components directly into your project via shadcn CLI — full source control, fully customizable.
|
|
451
|
+
|
|
452
|
+
### Base Component
|
|
453
|
+
|
|
454
|
+
The universal `GPTVis` component accepts vis syntax strings or config objects for all 26 chart types:
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
npx shadcn@latest add @gpt-vis/gpt-vis
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
```tsx
|
|
461
|
+
import { GPTVis } from '@/components/ui/gpt-vis';
|
|
462
|
+
|
|
463
|
+
<GPTVis
|
|
464
|
+
content="vis line
|
|
465
|
+
data
|
|
466
|
+
- time 2020
|
|
467
|
+
value 100
|
|
468
|
+
- time 2021
|
|
469
|
+
value 120
|
|
470
|
+
- time 2022
|
|
471
|
+
value 150
|
|
472
|
+
title Sales Trend"
|
|
473
|
+
theme="academy"
|
|
474
|
+
/>;
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Typed Chart Components
|
|
478
|
+
|
|
479
|
+
Each chart type has its own component with a typed `config` prop — JSON only, chart-specific TypeScript validation:
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
npx shadcn@latest add @gpt-vis/line
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
```tsx
|
|
486
|
+
import { Line } from '@/components/ui/line';
|
|
487
|
+
|
|
488
|
+
<Line
|
|
489
|
+
config={{
|
|
490
|
+
data: [
|
|
491
|
+
{ time: '2020', value: 100 },
|
|
492
|
+
{ time: '2021', value: 120 },
|
|
493
|
+
{ time: '2022', value: 150 },
|
|
494
|
+
],
|
|
495
|
+
title: 'Sales Trend',
|
|
496
|
+
axisXTitle: 'Year',
|
|
497
|
+
}}
|
|
498
|
+
height={400}
|
|
499
|
+
/>;
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
All 26 chart types are available. Install any by name:
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
npx shadcn@latest add @gpt-vis/pie
|
|
506
|
+
npx shadcn@latest add @gpt-vis/bar
|
|
507
|
+
npx shadcn@latest add @gpt-vis/mindmap
|
|
508
|
+
# ...and more
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
Each typed component automatically bundles the base `GPTVis` component as a dependency. Props like `width`, `height`, `theme`, `wrapper`, `locale`, `className`, and `containerStyle` are the same across all components.
|
|
512
|
+
|
|
394
513
|
## 🤖 AI Ecosystem
|
|
395
514
|
|
|
396
515
|
GPT-Vis provides a complete AI integration solution:
|
package/README.zh-CN.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
26
|
<div align="center">
|
|
27
|
-
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*
|
|
27
|
+
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*yNtZT47dH1kAAAAAgBAAAAgAemJ7AQ/fmt.webp" width="100%" alt="GPT-Vis Hero Image" />
|
|
28
28
|
</div>
|
|
29
29
|
|
|
30
30
|
<br/>
|
|
@@ -57,19 +57,14 @@ const gptVis = new GPTVis({
|
|
|
57
57
|
height: 400,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
- time 2022
|
|
69
|
-
value 150
|
|
70
|
-
`;
|
|
71
|
-
|
|
72
|
-
gptVis.render(visSyntax);
|
|
60
|
+
gptVis.render({
|
|
61
|
+
type: 'line',
|
|
62
|
+
data: [
|
|
63
|
+
{ time: '2020', value: 100 },
|
|
64
|
+
{ time: '2021', value: 120 },
|
|
65
|
+
{ time: '2022', value: 150 },
|
|
66
|
+
],
|
|
67
|
+
});
|
|
73
68
|
```
|
|
74
69
|
|
|
75
70
|
### 流式渲染
|
|
@@ -94,9 +89,73 @@ function onToken(token) {
|
|
|
94
89
|
|
|
95
90
|
## 📚 语法指南
|
|
96
91
|
|
|
97
|
-
`render()`
|
|
92
|
+
`render()` 支持两种输入格式:对象配置(适合程序化调用)和 DSL 语法(适合 LLM 流式生成)。
|
|
98
93
|
|
|
99
|
-
###
|
|
94
|
+
### 对象配置
|
|
95
|
+
|
|
96
|
+
直接传入 JSON 对象,适合程序化图表创建:
|
|
97
|
+
|
|
98
|
+
**折线图:**
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
gptVis.render({
|
|
102
|
+
type: 'line',
|
|
103
|
+
data: [
|
|
104
|
+
{ time: '2020', value: 100 },
|
|
105
|
+
{ time: '2021', value: 120 },
|
|
106
|
+
{ time: '2022', value: 150 },
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**饼图:**
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
gptVis.render({
|
|
115
|
+
type: 'pie',
|
|
116
|
+
data: [
|
|
117
|
+
{ category: 'Android', value: 72 },
|
|
118
|
+
{ category: 'iOS', value: 28 },
|
|
119
|
+
],
|
|
120
|
+
innerRadius: 0.6,
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**主题:**
|
|
125
|
+
|
|
126
|
+
内置三套主题,通过 `theme` 属性切换:
|
|
127
|
+
|
|
128
|
+
| 主题 | 标识 | 背景色 | 色板 |
|
|
129
|
+
| ------------ | --------- | ------ | ----------------------------------------------------- |
|
|
130
|
+
| 默认(亮色) | `default` | `#FFF` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
131
|
+
| 暗色 | `dark` | `#000` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
132
|
+
| 学术 | `academy` | `#FFF` | `#4e79a7` `#f28e2c` `#e15759` `#76b7b2` `#59a14f` ... |
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
gptVis.render({
|
|
136
|
+
type: 'line',
|
|
137
|
+
data: [
|
|
138
|
+
{ time: '2020', value: 100 },
|
|
139
|
+
{ time: '2021', value: 120 },
|
|
140
|
+
],
|
|
141
|
+
theme: 'dark',
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**自定义样式:**
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
gptVis.render({
|
|
149
|
+
type: 'line',
|
|
150
|
+
data: [
|
|
151
|
+
{ time: '2020', value: 100 },
|
|
152
|
+
{ time: '2021', value: 120 },
|
|
153
|
+
],
|
|
154
|
+
style: { lineWidth: 3, palette: ['#5B8FF9', '#5AD8A6'] },
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### DSL 语法
|
|
100
159
|
|
|
101
160
|
类 Markdown 的声明式语法,LLM 无需学习复杂 API 即可生成:
|
|
102
161
|
|
|
@@ -121,14 +180,6 @@ innerRadius 0.6
|
|
|
121
180
|
|
|
122
181
|
**主题:**
|
|
123
182
|
|
|
124
|
-
内置三套主题,通过 `theme` 属性切换:
|
|
125
|
-
|
|
126
|
-
| 主题 | 标识 | 背景色 | 色板 |
|
|
127
|
-
| ------------ | --------- | ------ | ----------------------------------------------------- |
|
|
128
|
-
| 默认(亮色) | `default` | `#FFF` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
129
|
-
| 暗色 | `dark` | `#000` | `#1783FF` `#F08F56` `#D580FF` `#00C9C9` `#7863FF` ... |
|
|
130
|
-
| 学术 | `academy` | `#FFF` | `#4e79a7` `#f28e2c` `#e15759` `#76b7b2` `#59a14f` ... |
|
|
131
|
-
|
|
132
183
|
```
|
|
133
184
|
vis line
|
|
134
185
|
data
|
|
@@ -179,18 +230,21 @@ data
|
|
|
179
230
|
- name 第二阶段
|
|
180
231
|
```
|
|
181
232
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
也支持直接传入 JSON 对象,适合程序化调用:
|
|
233
|
+
**使用 DSL 语法渲染:**
|
|
185
234
|
|
|
186
235
|
```javascript
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
236
|
+
const visSyntax = `
|
|
237
|
+
vis line
|
|
238
|
+
data
|
|
239
|
+
- time 2020
|
|
240
|
+
value 100
|
|
241
|
+
- time 2021
|
|
242
|
+
value 120
|
|
243
|
+
- time 2022
|
|
244
|
+
value 150
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
gptVis.render(visSyntax);
|
|
194
248
|
```
|
|
195
249
|
|
|
196
250
|
## 📊 图表类型
|
|
@@ -391,6 +445,71 @@ document.getElementById('content').innerHTML = marked.parse(markdown);
|
|
|
391
445
|
|
|
392
446
|
</details>
|
|
393
447
|
|
|
448
|
+
## 🧩 Shadcn/ui
|
|
449
|
+
|
|
450
|
+
通过 shadcn CLI 将 GPT-Vis React 组件直接复制到你的项目中 — 完全源代码控制,高度可定制。
|
|
451
|
+
|
|
452
|
+
### 基础组件
|
|
453
|
+
|
|
454
|
+
通用的 `GPTVis` 组件,支持全部 26 种图表类型的 vis 语法字符串或 JSON 配置对象:
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
npx shadcn@latest add @gpt-vis/gpt-vis
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
```tsx
|
|
461
|
+
import { GPTVis } from '@/components/ui/gpt-vis';
|
|
462
|
+
|
|
463
|
+
<GPTVis
|
|
464
|
+
content="vis line
|
|
465
|
+
data
|
|
466
|
+
- time 2020
|
|
467
|
+
value 100
|
|
468
|
+
- time 2021
|
|
469
|
+
value 120
|
|
470
|
+
- time 2022
|
|
471
|
+
value 150
|
|
472
|
+
title 销售趋势"
|
|
473
|
+
theme="academy"
|
|
474
|
+
/>;
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### 类型化图表组件
|
|
478
|
+
|
|
479
|
+
每种图表类型都有独立的组件,提供类型安全的 `config` 属性 — 仅支持 JSON,带 TypeScript 类型校验:
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
npx shadcn@latest add @gpt-vis/line
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
```tsx
|
|
486
|
+
import { Line } from '@/components/ui/line';
|
|
487
|
+
|
|
488
|
+
<Line
|
|
489
|
+
config={{
|
|
490
|
+
data: [
|
|
491
|
+
{ time: '2020', value: 100 },
|
|
492
|
+
{ time: '2021', value: 120 },
|
|
493
|
+
{ time: '2022', value: 150 },
|
|
494
|
+
],
|
|
495
|
+
title: '销售趋势',
|
|
496
|
+
axisXTitle: '年份',
|
|
497
|
+
}}
|
|
498
|
+
height={400}
|
|
499
|
+
/>;
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
全部 26 种图表类型均可用,按名称安装即可:
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
npx shadcn@latest add @gpt-vis/pie
|
|
506
|
+
npx shadcn@latest add @gpt-vis/bar
|
|
507
|
+
npx shadcn@latest add @gpt-vis/mindmap
|
|
508
|
+
# ...等等
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
每个类型化组件自动将基础 `GPTVis` 组件作为依赖安装。`width`、`height`、`theme`、`wrapper`、`locale`、`className`、`containerStyle` 等属性在所有组件中保持一致。
|
|
512
|
+
|
|
394
513
|
## 🤖 AI 生态
|
|
395
514
|
|
|
396
515
|
GPT-Vis 提供完整的 AI 集成方案:
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* Common visualization options for all chart components.
|
|
3
3
|
* Defines the container and dimensions for rendering visualizations.
|
|
4
4
|
*/
|
|
5
|
+
export type VisualizationTheme = 'default' | 'light' | 'dark' | 'academy';
|
|
5
6
|
export interface VisualizationOptions {
|
|
6
7
|
container: string | HTMLElement;
|
|
7
8
|
width?: number;
|
|
8
9
|
height?: number;
|
|
9
|
-
theme?:
|
|
10
|
+
theme?: VisualizationTheme;
|
|
10
11
|
wrapper?: boolean;
|
|
11
12
|
locale?: string;
|
|
12
13
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/animation.ts
|
|
20
|
+
var animation_exports = {};
|
|
21
|
+
__export(animation_exports, {
|
|
22
|
+
getChartAnimation: () => getChartAnimation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(animation_exports);
|
|
25
|
+
var prefersReducedMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
26
|
+
var getChartAnimation = (hasRendered, enterType) => {
|
|
27
|
+
if (hasRendered || prefersReducedMotion())
|
|
28
|
+
return false;
|
|
29
|
+
return {
|
|
30
|
+
enter: enterType ? { type: enterType } : {},
|
|
31
|
+
update: { type: null },
|
|
32
|
+
exit: { type: null }
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
getChartAnimation
|
|
38
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ChartLocale = 'en-US' | 'zh-CN';
|
|
2
|
+
export type CartesianXAxisOptions = {
|
|
3
|
+
xLabels?: unknown[];
|
|
4
|
+
chartWidth?: number;
|
|
5
|
+
};
|
|
6
|
+
export type CartesianAxisOptions = CartesianXAxisOptions & {
|
|
7
|
+
axisXTitle?: string | false;
|
|
8
|
+
axisYTitle?: string | false;
|
|
9
|
+
};
|
|
10
|
+
export declare const resolveChartLocale: (locale?: string) => ChartLocale;
|
|
11
|
+
export declare const getCartesianLayout: ({ xLabels, chartWidth, }: CartesianXAxisOptions) => Record<string, number>;
|
|
12
|
+
export declare const getCartesianAxis: ({ axisXTitle, axisYTitle, xLabels, chartWidth, }: CartesianAxisOptions) => Record<'x' | 'y', Record<string, unknown>>;
|
|
13
|
+
export declare const getColorLegend: (visible: boolean) => false | {
|
|
14
|
+
color: Record<string, never>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/components.ts
|
|
20
|
+
var components_exports = {};
|
|
21
|
+
__export(components_exports, {
|
|
22
|
+
getCartesianAxis: () => getCartesianAxis,
|
|
23
|
+
getCartesianLayout: () => getCartesianLayout,
|
|
24
|
+
getColorLegend: () => getColorLegend,
|
|
25
|
+
resolveChartLocale: () => resolveChartLocale
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(components_exports);
|
|
28
|
+
var DEFAULT_CHART_WIDTH = 640;
|
|
29
|
+
var AXIS_HORIZONTAL_PADDING = 96;
|
|
30
|
+
var ANGLED_LABEL_MARGIN_RIGHT_MIN = 32;
|
|
31
|
+
var ANGLED_LABEL_MARGIN_RIGHT_MAX = 64;
|
|
32
|
+
var ANGLED_LABEL_EDGE_GAP = 8;
|
|
33
|
+
var estimateLabelWidth = (value) => Array.from(String(value ?? "")).reduce(
|
|
34
|
+
(width, character) => width + ((character.codePointAt(0) ?? 0) > 255 ? 12 : 7),
|
|
35
|
+
0
|
|
36
|
+
);
|
|
37
|
+
var shouldUseAngledXAxisLabels = (labels, chartWidth = DEFAULT_CHART_WIDTH) => {
|
|
38
|
+
if (!(labels == null ? void 0 : labels.length))
|
|
39
|
+
return false;
|
|
40
|
+
const uniqueLabels = Array.from(new Set(labels.map((label) => String(label ?? ""))));
|
|
41
|
+
if (uniqueLabels.length <= 1)
|
|
42
|
+
return false;
|
|
43
|
+
const availableWidth = Math.max(chartWidth - AXIS_HORIZONTAL_PADDING, 240);
|
|
44
|
+
const estimatedWidth = uniqueLabels.reduce(
|
|
45
|
+
(total, label) => total + Math.max(28, estimateLabelWidth(label) + 16),
|
|
46
|
+
0
|
|
47
|
+
);
|
|
48
|
+
return estimatedWidth > availableWidth;
|
|
49
|
+
};
|
|
50
|
+
var resolveChartLocale = (locale) => (locale == null ? void 0 : locale.toLowerCase().startsWith("zh")) ? "zh-CN" : "en-US";
|
|
51
|
+
var getCartesianLayout = ({
|
|
52
|
+
xLabels,
|
|
53
|
+
chartWidth
|
|
54
|
+
}) => {
|
|
55
|
+
if (!shouldUseAngledXAxisLabels(xLabels, chartWidth))
|
|
56
|
+
return {};
|
|
57
|
+
const tailLabel = xLabels == null ? void 0 : xLabels[xLabels.length - 1];
|
|
58
|
+
const labelWidth = estimateLabelWidth(tailLabel);
|
|
59
|
+
const projectedHalfWidth = (labelWidth + 12) * Math.SQRT1_2 / 2;
|
|
60
|
+
return {
|
|
61
|
+
marginRight: Math.min(
|
|
62
|
+
ANGLED_LABEL_MARGIN_RIGHT_MAX,
|
|
63
|
+
Math.max(
|
|
64
|
+
ANGLED_LABEL_MARGIN_RIGHT_MIN,
|
|
65
|
+
Math.ceil(projectedHalfWidth + ANGLED_LABEL_EDGE_GAP)
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
var getCartesianAxis = ({
|
|
71
|
+
axisXTitle,
|
|
72
|
+
axisYTitle,
|
|
73
|
+
xLabels,
|
|
74
|
+
chartWidth
|
|
75
|
+
}) => {
|
|
76
|
+
const useAngledXAxisLabels = shouldUseAngledXAxisLabels(xLabels, chartWidth);
|
|
77
|
+
return {
|
|
78
|
+
x: {
|
|
79
|
+
title: axisXTitle || false,
|
|
80
|
+
...useAngledXAxisLabels ? { labelTransform: "rotate(45)", labelAutoRotate: false } : {}
|
|
81
|
+
},
|
|
82
|
+
y: {
|
|
83
|
+
title: axisYTitle || false
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
var getColorLegend = (visible) => visible ? { color: {} } : false;
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
getCartesianAxis,
|
|
91
|
+
getCartesianLayout,
|
|
92
|
+
getColorLegend,
|
|
93
|
+
resolveChartLocale
|
|
94
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Chart } from '@antv/g2';
|
|
2
|
+
import type { VisualizationTheme } from '../types';
|
|
3
|
+
export type CrosshairAxisLabelsOptions = {
|
|
4
|
+
showXLabel?: boolean;
|
|
5
|
+
useStandaloneYLabel?: boolean;
|
|
6
|
+
yAxisPosition?: 'left' | 'right';
|
|
7
|
+
yField?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Bridges G2 tooltip crosshairs to axis value tags.
|
|
11
|
+
*
|
|
12
|
+
* G2 does not currently expose axis tags for tooltip crosshairs, so this adapter
|
|
13
|
+
* reads the rule geometry created by G2 5.4 and renders labels with LineCrosshair.
|
|
14
|
+
*/
|
|
15
|
+
export declare const bindCrosshairAxisLabels: (chart: Chart, theme: VisualizationTheme, { showXLabel, useStandaloneYLabel, yAxisPosition, yField, }?: CrosshairAxisLabelsOptions) => (() => void);
|