@antv/gpt-vis 1.0.0-beta.1 → 1.0.0
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 +223 -47
- package/README.zh-CN.md +227 -51
- package/dist/cjs/gpt-vis/index.d.ts +8 -1
- package/dist/cjs/gpt-vis/index.js +43 -20
- package/dist/cjs/index.d.ts +15 -2
- package/dist/cjs/index.js +22 -2
- package/dist/cjs/syntax/parser.d.ts +17 -2
- package/dist/cjs/syntax/parser.js +151 -38
- package/dist/cjs/util/container.d.ts +5 -0
- package/dist/cjs/util/container.js +43 -0
- package/dist/cjs/util/theme.d.ts +5 -0
- package/dist/cjs/util/theme.js +9 -2
- package/dist/cjs/vis/area/index.js +2 -1
- package/dist/cjs/vis/bar/index.js +5 -4
- package/dist/cjs/vis/boxplot/index.js +7 -2
- package/dist/cjs/vis/column/index.js +5 -4
- package/dist/cjs/vis/dual-axes/index.js +3 -3
- package/dist/cjs/vis/fishbone-diagram/index.d.ts +35 -0
- package/dist/cjs/vis/fishbone-diagram/index.js +191 -0
- package/dist/cjs/vis/flow-diagram/index.d.ts +27 -0
- package/dist/cjs/vis/flow-diagram/index.js +287 -0
- package/dist/cjs/vis/funnel/index.js +2 -1
- package/dist/cjs/vis/histogram/index.js +3 -7
- package/dist/cjs/vis/indented-tree/index.d.ts +40 -0
- package/dist/cjs/vis/indented-tree/index.js +385 -0
- package/dist/cjs/vis/line/index.js +2 -1
- package/dist/cjs/vis/liquid/index.js +2 -1
- package/dist/cjs/vis/mindmap/index.d.ts +32 -0
- package/dist/cjs/vis/mindmap/index.js +222 -0
- package/dist/cjs/vis/network-graph/index.d.ts +59 -0
- package/dist/cjs/vis/network-graph/index.js +175 -0
- package/dist/cjs/vis/organization-chart/index.d.ts +64 -0
- package/dist/cjs/vis/organization-chart/index.js +200 -0
- package/dist/cjs/vis/pie/index.js +3 -3
- package/dist/cjs/vis/radar/index.d.ts +1 -0
- package/dist/cjs/vis/radar/index.js +10 -9
- package/dist/cjs/vis/sankey/index.js +2 -1
- package/dist/cjs/vis/scatter/index.d.ts +2 -0
- package/dist/cjs/vis/scatter/index.js +9 -4
- package/dist/cjs/vis/summary/index.js +17 -3
- package/dist/cjs/vis/table/index.d.ts +1 -0
- package/dist/cjs/vis/table/index.js +37 -1
- package/dist/cjs/vis/treemap/index.js +2 -1
- package/dist/cjs/vis/venn/index.d.ts +2 -1
- package/dist/cjs/vis/venn/index.js +18 -3
- package/dist/cjs/vis/violin/index.js +2 -1
- package/dist/cjs/vis/waterfall/index.d.ts +6 -9
- package/dist/cjs/vis/waterfall/index.js +29 -6
- package/dist/cjs/vis/word-cloud/index.js +2 -1
- package/dist/cjs/vis-wrapper/icons.js +2 -2
- package/dist/cjs/vis-wrapper/index.d.ts +1 -0
- package/dist/cjs/vis-wrapper/index.js +27 -16
- package/dist/cjs/vis-wrapper/styles.d.ts +1 -1
- package/dist/cjs/vis-wrapper/styles.js +8 -1
- package/dist/esm/gpt-vis/index.d.ts +8 -1
- package/dist/esm/gpt-vis/index.js +47 -26
- package/dist/esm/index.d.ts +15 -2
- package/dist/esm/index.js +7 -1
- package/dist/esm/syntax/parser.d.ts +17 -2
- package/dist/esm/syntax/parser.js +248 -90
- package/dist/esm/util/container.d.ts +5 -0
- package/dist/esm/util/container.js +20 -0
- package/dist/esm/util/theme.d.ts +5 -0
- package/dist/esm/util/theme.js +9 -0
- package/dist/esm/vis/area/index.js +3 -2
- package/dist/esm/vis/bar/index.js +7 -6
- package/dist/esm/vis/boxplot/index.js +17 -4
- package/dist/esm/vis/column/index.js +7 -6
- package/dist/esm/vis/dual-axes/index.js +13 -5
- package/dist/esm/vis/fishbone-diagram/index.d.ts +35 -0
- package/dist/esm/vis/fishbone-diagram/index.js +219 -0
- package/dist/esm/vis/flow-diagram/index.d.ts +27 -0
- package/dist/esm/vis/flow-diagram/index.js +349 -0
- package/dist/esm/vis/funnel/index.js +3 -2
- package/dist/esm/vis/histogram/index.js +6 -7
- package/dist/esm/vis/indented-tree/index.d.ts +40 -0
- package/dist/esm/vis/indented-tree/index.js +569 -0
- package/dist/esm/vis/line/index.js +3 -2
- package/dist/esm/vis/liquid/index.js +3 -2
- package/dist/esm/vis/mindmap/index.d.ts +32 -0
- package/dist/esm/vis/mindmap/index.js +316 -0
- package/dist/esm/vis/network-graph/index.d.ts +59 -0
- package/dist/esm/vis/network-graph/index.js +242 -0
- package/dist/esm/vis/organization-chart/index.d.ts +64 -0
- package/dist/esm/vis/organization-chart/index.js +271 -0
- package/dist/esm/vis/pie/index.js +4 -8
- package/dist/esm/vis/radar/index.d.ts +1 -0
- package/dist/esm/vis/radar/index.js +20 -4
- package/dist/esm/vis/sankey/index.js +3 -2
- package/dist/esm/vis/scatter/index.d.ts +2 -0
- package/dist/esm/vis/scatter/index.js +15 -4
- package/dist/esm/vis/summary/index.js +25 -4
- package/dist/esm/vis/table/index.d.ts +1 -0
- package/dist/esm/vis/table/index.js +9 -2
- package/dist/esm/vis/treemap/index.js +3 -2
- package/dist/esm/vis/venn/index.d.ts +2 -1
- package/dist/esm/vis/venn/index.js +29 -4
- package/dist/esm/vis/violin/index.js +3 -2
- package/dist/esm/vis/waterfall/index.d.ts +6 -9
- package/dist/esm/vis/waterfall/index.js +33 -13
- package/dist/esm/vis/word-cloud/index.js +3 -2
- package/dist/esm/vis-wrapper/icons.js +2 -2
- package/dist/esm/vis-wrapper/index.d.ts +1 -0
- package/dist/esm/vis-wrapper/index.js +15 -10
- package/dist/esm/vis-wrapper/styles.d.ts +1 -1
- package/dist/esm/vis-wrapper/styles.js +1 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +17 -21
- package/src/gpt-vis/index.ts +0 -283
- package/src/index.ts +0 -44
- package/src/readme.md +0 -37
- package/src/syntax/index.ts +0 -2
- package/src/syntax/parser.ts +0 -411
- package/src/types/index.ts +0 -29
- package/src/util/theme.ts +0 -167
- package/src/vis/area/README.md +0 -143
- package/src/vis/area/index.ts +0 -212
- package/src/vis/bar/README.md +0 -158
- package/src/vis/bar/index.ts +0 -186
- package/src/vis/boxplot/README.md +0 -168
- package/src/vis/boxplot/index.ts +0 -162
- package/src/vis/column/README.md +0 -158
- package/src/vis/column/index.ts +0 -185
- package/src/vis/dual-axes/README.md +0 -191
- package/src/vis/dual-axes/index.ts +0 -218
- package/src/vis/funnel/README.md +0 -143
- package/src/vis/funnel/index.ts +0 -238
- package/src/vis/histogram/README.md +0 -130
- package/src/vis/histogram/index.ts +0 -153
- package/src/vis/line/README.md +0 -138
- package/src/vis/line/index.ts +0 -159
- package/src/vis/liquid/README.md +0 -150
- package/src/vis/liquid/index.ts +0 -130
- package/src/vis/pie/README.md +0 -127
- package/src/vis/pie/index.ts +0 -163
- package/src/vis/radar/README.md +0 -184
- package/src/vis/radar/index.ts +0 -214
- package/src/vis/sankey/README.md +0 -144
- package/src/vis/sankey/index.ts +0 -144
- package/src/vis/scatter/README.md +0 -145
- package/src/vis/scatter/index.ts +0 -147
- package/src/vis/summary/README.md +0 -272
- package/src/vis/summary/index.ts +0 -91
- package/src/vis/table/README.md +0 -174
- package/src/vis/table/index.ts +0 -241
- package/src/vis/treemap/README.md +0 -199
- package/src/vis/treemap/index.ts +0 -167
- package/src/vis/venn/README.md +0 -153
- package/src/vis/venn/index.ts +0 -149
- package/src/vis/violin/README.md +0 -168
- package/src/vis/violin/index.ts +0 -216
- package/src/vis/waterfall/README.md +0 -178
- package/src/vis/waterfall/index.ts +0 -258
- package/src/vis/word-cloud/README.md +0 -137
- package/src/vis/word-cloud/index.ts +0 -137
- package/src/vis-wrapper/README.md +0 -159
- package/src/vis-wrapper/icons.ts +0 -35
- package/src/vis-wrapper/index.ts +0 -276
- package/src/vis-wrapper/styles.ts +0 -195
package/README.zh-CN.md
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
<img src="https://gw.alipayobjects.com/zos/antfincdn/R8sN%24GNdh6/language.svg" width="18"> [English](./README.md) | 简体中文
|
|
2
2
|
|
|
3
|
-
<
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="https://github.com/eosphoros-ai/GPT-Vis/assets/17919400/c8804ffb-d3d6-45d3-846f-cf217681ab05" height="70" />
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">GPT-Vis</h1>
|
|
4
8
|
|
|
5
9
|
<div align="center">
|
|
6
|
-
<img src="https://github.com/eosphoros-ai/GPT-Vis/assets/17919400/c8804ffb-d3d6-45d3-846f-cf217681ab05" height="70">
|
|
7
10
|
|
|
8
|
-
面向 LLM 时代的 AI
|
|
11
|
+
面向 LLM 时代的 AI 原生可视化库,框架无关,开箱即用。
|
|
9
12
|
|
|
10
13
|
[](https://www.npmjs.com/package/@antv/gpt-vis)
|
|
11
14
|
[](https://www.npmjs.com/package/@antv/gpt-vis)
|
|
12
15
|
[](./LICENSE)
|
|
13
16
|
|
|
14
17
|
<p align="center">
|
|
15
|
-
<a href="https://gpt-vis.antv.vision" target="_blank">📖 文档</a>
|
|
16
|
-
<a href="/
|
|
17
|
-
<a href="/
|
|
18
|
-
<a href="
|
|
19
|
-
<a href="https://github.com/antvis/mcp-server-chart" target="_blank">🔌 MCP 服务器</a>
|
|
18
|
+
<a href="https://gpt-vis.antv.vision" target="_blank">📖 文档</a> ·
|
|
19
|
+
<a href="https://gpt-vis.antv.vision/examples" target="_blank">🎨 图表示例</a> ·
|
|
20
|
+
<a href="https://github.com/antvis/mcp-server-chart" target="_blank">🔌 MCP 服务</a> ·
|
|
21
|
+
<a href="/skills/chart-visualization" target="_blank">🧩 图表技能</a>
|
|
20
22
|
</p>
|
|
21
23
|
|
|
22
24
|
</div>
|
|
23
25
|
|
|
24
26
|
<div align="center">
|
|
25
|
-
<
|
|
27
|
+
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*k21VQY6NgAwAAAAAWAAAAAgAemJ7AQ/fmt.avif" width="100%" />
|
|
26
28
|
</div>
|
|
27
29
|
|
|
28
30
|
<br/>
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
## ✨ 特性
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
- **📊 20+ 图表类型**: 统计图表、关系图表和高级可视化图表
|
|
39
|
-
- **🧠 智能默认值**: 自动数据检测、智能配色方案、自适应布局
|
|
34
|
+
- 🚀 **框架无关** — 原生 JavaScript、React、Vue、Angular,任何框架均可使用
|
|
35
|
+
- ✍️ **类 Markdown 语法** — LLM 可以直接生成的简洁语法,易学易用
|
|
36
|
+
- 🌊 **流式渲染** — 原生支持 AI 模型流式输出,边生成边渲染
|
|
37
|
+
- 🛡️ **高容错** — 优雅处理不完整、格式异常的数据,适配 AI 生成内容的不确定性
|
|
38
|
+
- 📊 **26 种图表** — 统计图表、关系图表、文本可视化,覆盖主流场景
|
|
39
|
+
- 🎨 **主题系统** — 内置亮色、暗色、学术三套主题,支持自定义配色
|
|
40
40
|
|
|
41
41
|
## 🚀 快速开始
|
|
42
42
|
|
|
@@ -52,12 +52,12 @@ npm install @antv/gpt-vis
|
|
|
52
52
|
import { GPTVis } from '@antv/gpt-vis';
|
|
53
53
|
|
|
54
54
|
const gptVis = new GPTVis({
|
|
55
|
-
container: '
|
|
55
|
+
container: 'container',
|
|
56
56
|
width: 600,
|
|
57
57
|
height: 400,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
//
|
|
60
|
+
// 类 Markdown 的可视化语法
|
|
61
61
|
const visSyntax = `
|
|
62
62
|
vis line
|
|
63
63
|
data
|
|
@@ -72,12 +72,16 @@ data
|
|
|
72
72
|
gptVis.render(visSyntax);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
###
|
|
75
|
+
### 流式渲染
|
|
76
|
+
|
|
77
|
+
AI 模型边生成、图表边渲染,无需等待完整响应:
|
|
78
|
+
|
|
79
|
+
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*_xY7Q6QyuZ4AAAAAWeAAAAgAemJ7AQ/original" width="100%" />
|
|
76
80
|
|
|
77
81
|
```javascript
|
|
78
82
|
import { GPTVis, isVisSyntax } from '@antv/gpt-vis';
|
|
79
83
|
|
|
80
|
-
const gptVis = new GPTVis({ container: '
|
|
84
|
+
const gptVis = new GPTVis({ container: 'container', width: 600, height: 400 });
|
|
81
85
|
let buffer = '';
|
|
82
86
|
|
|
83
87
|
function onToken(token) {
|
|
@@ -90,18 +94,20 @@ function onToken(token) {
|
|
|
90
94
|
|
|
91
95
|
## 📚 语法指南
|
|
92
96
|
|
|
93
|
-
|
|
97
|
+
`render()` 支持两种输入格式:vis 语法(适合 LLM 流式生成)和 JSON 对象(适合程序化调用)。
|
|
98
|
+
|
|
99
|
+
### Vis 语法
|
|
100
|
+
|
|
101
|
+
类 Markdown 的声明式语法,LLM 无需学习复杂 API 即可生成:
|
|
94
102
|
|
|
95
103
|
```
|
|
96
104
|
vis [图表类型]
|
|
97
105
|
[属性] [值]
|
|
98
106
|
data
|
|
99
|
-
- [
|
|
107
|
+
- [字段] [值]
|
|
100
108
|
```
|
|
101
109
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
**简单图表:**
|
|
110
|
+
**饼图:**
|
|
105
111
|
|
|
106
112
|
```
|
|
107
113
|
vis pie
|
|
@@ -113,7 +119,29 @@ data
|
|
|
113
119
|
innerRadius 0.6
|
|
114
120
|
```
|
|
115
121
|
|
|
116
|
-
|
|
122
|
+
**主题:**
|
|
123
|
+
|
|
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
|
+
```
|
|
133
|
+
vis line
|
|
134
|
+
data
|
|
135
|
+
- time 2020
|
|
136
|
+
value 100
|
|
137
|
+
- time 2021
|
|
138
|
+
value 120
|
|
139
|
+
theme dark
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**自定义样式:**
|
|
143
|
+
|
|
144
|
+
通过 `style` 设置线宽、自定义配色等:
|
|
117
145
|
|
|
118
146
|
```
|
|
119
147
|
vis line
|
|
@@ -124,20 +152,94 @@ data
|
|
|
124
152
|
value 120
|
|
125
153
|
style
|
|
126
154
|
lineWidth 3
|
|
127
|
-
palette
|
|
155
|
+
palette
|
|
156
|
+
- #5B8FF9
|
|
157
|
+
- #5AD8A6
|
|
128
158
|
```
|
|
129
159
|
|
|
130
|
-
|
|
160
|
+
**包含空格的值用引号包裹:**
|
|
131
161
|
|
|
132
162
|
```
|
|
133
|
-
vis
|
|
163
|
+
vis pie
|
|
134
164
|
data
|
|
135
|
-
-
|
|
165
|
+
- category "Q1 销售额"
|
|
166
|
+
value 30
|
|
167
|
+
- category "Q2 销售额"
|
|
168
|
+
value 25
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**层级数据:**
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
vis mindmap
|
|
175
|
+
data
|
|
176
|
+
- name 项目规划
|
|
136
177
|
children
|
|
137
|
-
- name
|
|
138
|
-
- name
|
|
178
|
+
- name 第一阶段
|
|
179
|
+
- name 第二阶段
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### JSON 对象
|
|
183
|
+
|
|
184
|
+
也支持直接传入 JSON 对象,适合程序化调用:
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
gptVis.render({
|
|
188
|
+
type: 'pie',
|
|
189
|
+
data: [
|
|
190
|
+
{ category: 'Android', value: 72 },
|
|
191
|
+
{ category: 'iOS', value: 28 },
|
|
192
|
+
],
|
|
193
|
+
});
|
|
139
194
|
```
|
|
140
195
|
|
|
196
|
+
## 📊 图表类型
|
|
197
|
+
|
|
198
|
+
支持 26 种图表,覆盖统计分析、关系网络、文本可视化三大类。
|
|
199
|
+
|
|
200
|
+
### 统计图表(18 种)
|
|
201
|
+
|
|
202
|
+
| 图表 | 类型标识 |
|
|
203
|
+
| -------- | ------------ |
|
|
204
|
+
| 折线图 | `line` |
|
|
205
|
+
| 面积图 | `area` |
|
|
206
|
+
| 柱状图 | `column` |
|
|
207
|
+
| 条形图 | `bar` |
|
|
208
|
+
| 饼图 | `pie` |
|
|
209
|
+
| 散点图 | `scatter` |
|
|
210
|
+
| 雷达图 | `radar` |
|
|
211
|
+
| 漏斗图 | `funnel` |
|
|
212
|
+
| 瀑布图 | `waterfall` |
|
|
213
|
+
| 双轴图 | `dual-axes` |
|
|
214
|
+
| 直方图 | `histogram` |
|
|
215
|
+
| 箱线图 | `boxplot` |
|
|
216
|
+
| 小提琴图 | `violin` |
|
|
217
|
+
| 韦恩图 | `venn` |
|
|
218
|
+
| 桑基图 | `sankey` |
|
|
219
|
+
| 树图 | `treemap` |
|
|
220
|
+
| 词云 | `word-cloud` |
|
|
221
|
+
| 水波图 | `liquid` |
|
|
222
|
+
|
|
223
|
+
### 关系图表(6 种)
|
|
224
|
+
|
|
225
|
+
| 图表 | 类型标识 |
|
|
226
|
+
| ---------- | -------------------- |
|
|
227
|
+
| 流程图 | `flow-diagram` |
|
|
228
|
+
| 网络图 | `network-graph` |
|
|
229
|
+
| 思维导图 | `mindmap` |
|
|
230
|
+
| 缩进树 | `indented-tree` |
|
|
231
|
+
| 组织架构图 | `organization-chart` |
|
|
232
|
+
| 鱼骨图 | `fishbone-diagram` |
|
|
233
|
+
|
|
234
|
+
### 文本可视化(2 种)
|
|
235
|
+
|
|
236
|
+
| 图表 | 类型标识 |
|
|
237
|
+
| -------- | --------- |
|
|
238
|
+
| 表格 | `table` |
|
|
239
|
+
| 文本摘要 | `summary` |
|
|
240
|
+
|
|
241
|
+
查看全部示例 → [图表示例](https://gpt-vis.antv.vision/examples)
|
|
242
|
+
|
|
141
243
|
## 🔧 框架集成
|
|
142
244
|
|
|
143
245
|
<details>
|
|
@@ -146,7 +248,7 @@ data
|
|
|
146
248
|
```javascript
|
|
147
249
|
import { GPTVis } from '@antv/gpt-vis';
|
|
148
250
|
|
|
149
|
-
const gptVis = new GPTVis({ container: '
|
|
251
|
+
const gptVis = new GPTVis({ container: 'chart', width: 600, height: 400 });
|
|
150
252
|
gptVis.render(visSyntaxString);
|
|
151
253
|
```
|
|
152
254
|
|
|
@@ -189,25 +291,22 @@ function ChartComponent({ visSyntax }) {
|
|
|
189
291
|
</template>
|
|
190
292
|
|
|
191
293
|
<script setup>
|
|
192
|
-
import { ref,
|
|
294
|
+
import { ref, watch, onUnmounted } from 'vue';
|
|
193
295
|
import { GPTVis } from '@antv/gpt-vis';
|
|
194
296
|
|
|
195
297
|
const props = defineProps(['visSyntax']);
|
|
196
298
|
const chartRef = ref(null);
|
|
197
299
|
let gptVis = null;
|
|
198
300
|
|
|
199
|
-
onMounted(() => {
|
|
200
|
-
gptVis = new GPTVis({ container: chartRef.value, width: 600, height: 400 });
|
|
201
|
-
gptVis.render(props.visSyntax);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
301
|
watch(
|
|
205
302
|
() => props.visSyntax,
|
|
206
|
-
(
|
|
207
|
-
if (gptVis) {
|
|
208
|
-
gptVis.
|
|
303
|
+
(syntax) => {
|
|
304
|
+
if (!gptVis) {
|
|
305
|
+
gptVis = new GPTVis({ container: chartRef.value, width: 600, height: 400 });
|
|
209
306
|
}
|
|
307
|
+
gptVis.render(syntax);
|
|
210
308
|
},
|
|
309
|
+
{ immediate: true },
|
|
211
310
|
);
|
|
212
311
|
|
|
213
312
|
onUnmounted(() => gptVis?.destroy());
|
|
@@ -216,18 +315,95 @@ onUnmounted(() => gptVis?.destroy());
|
|
|
216
315
|
|
|
217
316
|
</details>
|
|
218
317
|
|
|
219
|
-
|
|
318
|
+
<details>
|
|
319
|
+
<summary><strong>Markdown 渲染器(marked)</strong></summary>
|
|
220
320
|
|
|
221
|
-
GPT-Vis
|
|
321
|
+
GPT-Vis 的 vis 语法天然兼容 Markdown code fence,可以与任何 Markdown 渲染器集成。以下示例使用 `marked` + `marked-highlight`,普通代码块走语法高亮,`vis` 代码块自动渲染为交互式图表。
|
|
222
322
|
|
|
223
|
-
|
|
323
|
+
**安装依赖:**
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
npm install @antv/gpt-vis marked marked-highlight highlight.js
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**完整示例:**
|
|
330
|
+
|
|
331
|
+
```javascript
|
|
332
|
+
import { Marked } from 'marked';
|
|
333
|
+
import { markedHighlight } from 'marked-highlight';
|
|
334
|
+
import hljs from 'highlight.js';
|
|
335
|
+
import { GPTVis } from '@antv/gpt-vis';
|
|
336
|
+
|
|
337
|
+
class GPTVisElement extends HTMLElement {
|
|
338
|
+
connectedCallback() {
|
|
339
|
+
const syntax = decodeURIComponent(this.dataset.syntax);
|
|
340
|
+
this._instance = new GPTVis({ container: this });
|
|
341
|
+
this._instance.render(syntax);
|
|
342
|
+
}
|
|
343
|
+
disconnectedCallback() {
|
|
344
|
+
this._instance?.destroy();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (!customElements.get('gpt-vis')) {
|
|
348
|
+
customElements.define('gpt-vis', GPTVisElement);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const marked = new Marked(
|
|
352
|
+
markedHighlight({
|
|
353
|
+
langPrefix: 'hljs language-',
|
|
354
|
+
highlight(code, lang) {
|
|
355
|
+
if (lang?.startsWith('vis')) return code;
|
|
356
|
+
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
|
357
|
+
return hljs.highlight(code, { language }).value;
|
|
358
|
+
},
|
|
359
|
+
}),
|
|
360
|
+
{
|
|
361
|
+
renderer: {
|
|
362
|
+
code({ text, lang }) {
|
|
363
|
+
if (lang?.startsWith('vis')) {
|
|
364
|
+
const syntax = encodeURIComponent(lang + '\n' + text);
|
|
365
|
+
return `<gpt-vis data-syntax="${syntax}" style="min-height:300px"></gpt-vis>`;
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
const markdown = `# My Report
|
|
374
|
+
|
|
375
|
+
\`\`\`vis bar
|
|
376
|
+
data
|
|
377
|
+
- category Python
|
|
378
|
+
value 28.1
|
|
379
|
+
- category JavaScript
|
|
380
|
+
value 18.5
|
|
381
|
+
- category Java
|
|
382
|
+
value 15.6
|
|
383
|
+
- category "C/C++"
|
|
384
|
+
value 12.3
|
|
385
|
+
title 2024 Programming Language Popularity
|
|
386
|
+
\`\`\`
|
|
387
|
+
`;
|
|
224
388
|
|
|
225
|
-
|
|
389
|
+
document.getElementById('content').innerHTML = marked.parse(markdown);
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
</details>
|
|
393
|
+
|
|
394
|
+
## 🤖 AI 生态
|
|
395
|
+
|
|
396
|
+
GPT-Vis 提供完整的 AI 集成方案:
|
|
397
|
+
|
|
398
|
+
- **[MCP 服务](https://github.com/antvis/mcp-server-chart)** — 通过 Model Context Protocol 让 AI 模型直接调用可视化能力
|
|
399
|
+
- **[图表技能](https://github.com/antvis/GPT-Vis/tree/main/skills/chart-visualization)** — 为 AI 助手提供图表推荐与生成能力,支持语法模式和代码模式两种输出
|
|
400
|
+
|
|
401
|
+
## 🤝 贡献
|
|
226
402
|
|
|
227
|
-
|
|
403
|
+
> **AI 生成代码策略**:本项目仅合并 AI 生成的代码。
|
|
228
404
|
|
|
229
|
-
1. 提交 Issue
|
|
230
|
-
2. 标记 @copilot
|
|
405
|
+
1. 提交 Issue 描述问题或需求
|
|
406
|
+
2. 标记 @copilot 生成实现方案
|
|
231
407
|
3. 提交包含 AI 生成代码的 PR
|
|
232
408
|
|
|
233
409
|
## 📄 开源协议
|
|
@@ -4,10 +4,16 @@ import type { BarConfig } from '../vis/bar';
|
|
|
4
4
|
import type { BoxplotConfig } from '../vis/boxplot';
|
|
5
5
|
import type { ColumnConfig } from '../vis/column';
|
|
6
6
|
import type { DualAxesConfig } from '../vis/dual-axes';
|
|
7
|
+
import type { FishboneDiagramConfig } from '../vis/fishbone-diagram';
|
|
8
|
+
import type { FlowDiagramConfig } from '../vis/flow-diagram';
|
|
7
9
|
import type { FunnelConfig } from '../vis/funnel';
|
|
8
10
|
import type { HistogramConfig } from '../vis/histogram';
|
|
11
|
+
import type { IndentedTreeConfig } from '../vis/indented-tree';
|
|
9
12
|
import type { LineConfig } from '../vis/line';
|
|
10
13
|
import type { LiquidConfig } from '../vis/liquid';
|
|
14
|
+
import type { MindmapConfig } from '../vis/mindmap';
|
|
15
|
+
import type { NetworkGraphConfig } from '../vis/network-graph';
|
|
16
|
+
import type { OrganizationChartConfig } from '../vis/organization-chart';
|
|
11
17
|
import type { PieConfig } from '../vis/pie';
|
|
12
18
|
import type { RadarConfig } from '../vis/radar';
|
|
13
19
|
import type { SankeyConfig } from '../vis/sankey';
|
|
@@ -22,7 +28,7 @@ import type { WordCloudConfig } from '../vis/word-cloud';
|
|
|
22
28
|
/**
|
|
23
29
|
* Union type for all supported chart configurations
|
|
24
30
|
*/
|
|
25
|
-
export type GPTVisConfig = AreaConfig | BarConfig | BoxplotConfig | ColumnConfig | DualAxesConfig | FunnelConfig | HistogramConfig | LineConfig | LiquidConfig | PieConfig | RadarConfig | SankeyConfig | ScatterConfig | SummaryConfig | TableConfig | TreemapConfig | VennConfig | ViolinConfig | WaterfallConfig | WordCloudConfig;
|
|
31
|
+
export type GPTVisConfig = AreaConfig | BarConfig | BoxplotConfig | ColumnConfig | DualAxesConfig | FlowDiagramConfig | FunnelConfig | HistogramConfig | IndentedTreeConfig | LineConfig | LiquidConfig | MindmapConfig | NetworkGraphConfig | OrganizationChartConfig | PieConfig | RadarConfig | SankeyConfig | ScatterConfig | SummaryConfig | TableConfig | TreemapConfig | VennConfig | ViolinConfig | WaterfallConfig | WordCloudConfig | FishboneDiagramConfig;
|
|
26
32
|
/**
|
|
27
33
|
* GPTVis is the unified API for all chart types.
|
|
28
34
|
* It provides a simple interface to render different types of visualizations.
|
|
@@ -66,6 +72,7 @@ export type GPTVisConfig = AreaConfig | BarConfig | BoxplotConfig | ColumnConfig
|
|
|
66
72
|
export declare class GPTVis {
|
|
67
73
|
private options;
|
|
68
74
|
private currentChart;
|
|
75
|
+
private currentChartType;
|
|
69
76
|
private wrapperInstance;
|
|
70
77
|
/**
|
|
71
78
|
* Chart type registry mapping type strings to factory functions
|
|
@@ -23,16 +23,23 @@ __export(gpt_vis_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(gpt_vis_exports);
|
|
25
25
|
var import_parser = require("../syntax/parser");
|
|
26
|
+
var import_container = require("../util/container");
|
|
26
27
|
var import_vis_wrapper = require("../vis-wrapper");
|
|
27
28
|
var import_area = require("../vis/area");
|
|
28
29
|
var import_bar = require("../vis/bar");
|
|
29
30
|
var import_boxplot = require("../vis/boxplot");
|
|
30
31
|
var import_column = require("../vis/column");
|
|
31
32
|
var import_dual_axes = require("../vis/dual-axes");
|
|
33
|
+
var import_fishbone_diagram = require("../vis/fishbone-diagram");
|
|
34
|
+
var import_flow_diagram = require("../vis/flow-diagram");
|
|
32
35
|
var import_funnel = require("../vis/funnel");
|
|
33
36
|
var import_histogram = require("../vis/histogram");
|
|
37
|
+
var import_indented_tree = require("../vis/indented-tree");
|
|
34
38
|
var import_line = require("../vis/line");
|
|
35
39
|
var import_liquid = require("../vis/liquid");
|
|
40
|
+
var import_mindmap = require("../vis/mindmap");
|
|
41
|
+
var import_network_graph = require("../vis/network-graph");
|
|
42
|
+
var import_organization_chart = require("../vis/organization-chart");
|
|
36
43
|
var import_pie = require("../vis/pie");
|
|
37
44
|
var import_radar = require("../vis/radar");
|
|
38
45
|
var import_sankey = require("../vis/sankey");
|
|
@@ -51,8 +58,12 @@ var _GPTVis = class {
|
|
|
51
58
|
*/
|
|
52
59
|
constructor(options) {
|
|
53
60
|
this.currentChart = null;
|
|
61
|
+
this.currentChartType = "";
|
|
54
62
|
this.wrapperInstance = null;
|
|
55
|
-
this.options =
|
|
63
|
+
this.options = {
|
|
64
|
+
...options,
|
|
65
|
+
container: (0, import_container.resolveContainer)(options.container)
|
|
66
|
+
};
|
|
56
67
|
}
|
|
57
68
|
/**
|
|
58
69
|
* Render a chart based on the provided configuration or syntax string.
|
|
@@ -101,28 +112,33 @@ var _GPTVis = class {
|
|
|
101
112
|
const availableTypes = Object.keys(_GPTVis.chartRegistry).join(", ");
|
|
102
113
|
throw new Error(`Unsupported chart type: "${type}". Available types: ${availableTypes}`);
|
|
103
114
|
}
|
|
104
|
-
if (this.currentChart) {
|
|
105
|
-
this.currentChart.destroy();
|
|
106
|
-
}
|
|
107
|
-
if (this.wrapperInstance) {
|
|
108
|
-
this.wrapperInstance.destroy();
|
|
109
|
-
this.wrapperInstance = null;
|
|
110
|
-
}
|
|
111
115
|
let chartContainer = this.options.container;
|
|
112
116
|
if (this.options.wrapper) {
|
|
113
|
-
this.wrapperInstance
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
if (!this.wrapperInstance) {
|
|
118
|
+
this.wrapperInstance = (0, import_vis_wrapper.createVisWrapper)(this.options.container, {
|
|
119
|
+
chartType: type,
|
|
120
|
+
syntax: config,
|
|
121
|
+
locale: this.options.locale || "en-US"
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
this.wrapperInstance.update(config);
|
|
125
|
+
}
|
|
118
126
|
chartContainer = this.wrapperInstance.chartContainer;
|
|
119
127
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
if (this.currentChart && this.currentChartType === type) {
|
|
129
|
+
this.currentChart.render(chartConfig);
|
|
130
|
+
} else {
|
|
131
|
+
if (this.currentChart) {
|
|
132
|
+
this.currentChart.destroy();
|
|
133
|
+
}
|
|
134
|
+
const chartOptions = {
|
|
135
|
+
...this.options,
|
|
136
|
+
container: chartContainer
|
|
137
|
+
};
|
|
138
|
+
this.currentChart = chartFactory(chartOptions);
|
|
139
|
+
this.currentChartType = type;
|
|
140
|
+
this.currentChart.render(chartConfig);
|
|
141
|
+
}
|
|
126
142
|
if (this.wrapperInstance) {
|
|
127
143
|
this.wrapperInstance.setChartRef(this.currentChart);
|
|
128
144
|
}
|
|
@@ -134,6 +150,7 @@ var _GPTVis = class {
|
|
|
134
150
|
if (this.currentChart) {
|
|
135
151
|
this.currentChart.destroy();
|
|
136
152
|
this.currentChart = null;
|
|
153
|
+
this.currentChartType = "";
|
|
137
154
|
}
|
|
138
155
|
if (this.wrapperInstance) {
|
|
139
156
|
this.wrapperInstance.destroy();
|
|
@@ -151,10 +168,15 @@ GPTVis.chartRegistry = {
|
|
|
151
168
|
boxplot: import_boxplot.Boxplot,
|
|
152
169
|
column: import_column.Column,
|
|
153
170
|
"dual-axes": import_dual_axes.DualAxes,
|
|
171
|
+
"flow-diagram": import_flow_diagram.FlowDiagram,
|
|
154
172
|
funnel: import_funnel.Funnel,
|
|
155
173
|
histogram: import_histogram.Histogram,
|
|
174
|
+
"indented-tree": import_indented_tree.IndentedTree,
|
|
156
175
|
line: import_line.Line,
|
|
157
176
|
liquid: import_liquid.Liquid,
|
|
177
|
+
mindmap: import_mindmap.Mindmap,
|
|
178
|
+
"network-graph": import_network_graph.NetworkGraph,
|
|
179
|
+
"organization-chart": import_organization_chart.OrganizationChart,
|
|
158
180
|
pie: import_pie.Pie,
|
|
159
181
|
radar: import_radar.Radar,
|
|
160
182
|
sankey: import_sankey.Sankey,
|
|
@@ -165,7 +187,8 @@ GPTVis.chartRegistry = {
|
|
|
165
187
|
venn: import_venn.Venn,
|
|
166
188
|
violin: import_violin.Violin,
|
|
167
189
|
waterfall: import_waterfall.Waterfall,
|
|
168
|
-
"word-cloud": import_word_cloud.WordCloud
|
|
190
|
+
"word-cloud": import_word_cloud.WordCloud,
|
|
191
|
+
"fishbone-diagram": import_fishbone_diagram.FishboneDiagram
|
|
169
192
|
};
|
|
170
193
|
// Annotate the CommonJS export names for ESM import in node:
|
|
171
194
|
0 && (module.exports = {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { GPTVis } from './gpt-vis';
|
|
2
2
|
export type { GPTVisConfig } from './gpt-vis';
|
|
3
|
-
export { isVisSyntax } from './syntax';
|
|
3
|
+
export { isVisSyntax, parse } from './syntax';
|
|
4
|
+
export type { ParsedConfig } from './syntax';
|
|
4
5
|
export type { VisualizationOptions } from './types';
|
|
5
6
|
export { Area } from './vis/area';
|
|
6
7
|
export type { AreaConfig, AreaDataItem } from './vis/area';
|
|
@@ -12,14 +13,26 @@ export { Column } from './vis/column';
|
|
|
12
13
|
export type { ColumnConfig, ColumnDataItem } from './vis/column';
|
|
13
14
|
export { DualAxes } from './vis/dual-axes';
|
|
14
15
|
export type { DualAxesConfig, DualAxesSeriesItem } from './vis/dual-axes';
|
|
16
|
+
export { FishboneDiagram } from './vis/fishbone-diagram';
|
|
17
|
+
export type { FishboneDiagramConfig, FishboneDiagramInstance, FishboneNode, } from './vis/fishbone-diagram';
|
|
18
|
+
export { FlowDiagram } from './vis/flow-diagram';
|
|
19
|
+
export type { FlowDiagramConfig } from './vis/flow-diagram';
|
|
15
20
|
export { Funnel } from './vis/funnel';
|
|
16
21
|
export type { FunnelConfig, FunnelDataItem } from './vis/funnel';
|
|
17
22
|
export { Histogram } from './vis/histogram';
|
|
18
23
|
export type { HistogramConfig } from './vis/histogram';
|
|
24
|
+
export { IndentedTree } from './vis/indented-tree';
|
|
25
|
+
export type { IndentedTreeConfig, IndentedTreeData, IndentedTreeInstance, } from './vis/indented-tree';
|
|
19
26
|
export { Line } from './vis/line';
|
|
20
27
|
export type { LineConfig, LineDataItem } from './vis/line';
|
|
21
28
|
export { Liquid } from './vis/liquid';
|
|
22
29
|
export type { LiquidConfig } from './vis/liquid';
|
|
30
|
+
export { Mindmap } from './vis/mindmap';
|
|
31
|
+
export type { MindMapProps, MindmapConfig, MindmapData } from './vis/mindmap';
|
|
32
|
+
export { NetworkGraph } from './vis/network-graph';
|
|
33
|
+
export type { NetworkGraphConfig, NetworkGraphData, NetworkGraphEdge, NetworkGraphNode, } from './vis/network-graph';
|
|
34
|
+
export { OrganizationChart } from './vis/organization-chart';
|
|
35
|
+
export type { OrganizationChartConfig, OrganizationChartData } from './vis/organization-chart';
|
|
23
36
|
export { Pie } from './vis/pie';
|
|
24
37
|
export type { PieConfig } from './vis/pie';
|
|
25
38
|
export { Radar } from './vis/radar';
|
|
@@ -39,6 +52,6 @@ export type { VennConfig, VennDataItem } from './vis/venn';
|
|
|
39
52
|
export { Violin } from './vis/violin';
|
|
40
53
|
export type { ViolinConfig, ViolinDataItem } from './vis/violin';
|
|
41
54
|
export { Waterfall } from './vis/waterfall';
|
|
42
|
-
export type { WaterfallConfig, WaterfallDataItem
|
|
55
|
+
export type { WaterfallConfig, WaterfallDataItem } from './vis/waterfall';
|
|
43
56
|
export { WordCloud } from './vis/word-cloud';
|
|
44
57
|
export type { WordCloudConfig, WordCloudDataItem } from './vis/word-cloud';
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,11 +24,17 @@ __export(src_exports, {
|
|
|
24
24
|
Boxplot: () => import_boxplot.Boxplot,
|
|
25
25
|
Column: () => import_column.Column,
|
|
26
26
|
DualAxes: () => import_dual_axes.DualAxes,
|
|
27
|
+
FishboneDiagram: () => import_fishbone_diagram.FishboneDiagram,
|
|
28
|
+
FlowDiagram: () => import_flow_diagram.FlowDiagram,
|
|
27
29
|
Funnel: () => import_funnel.Funnel,
|
|
28
30
|
GPTVis: () => import_gpt_vis.GPTVis,
|
|
29
31
|
Histogram: () => import_histogram.Histogram,
|
|
32
|
+
IndentedTree: () => import_indented_tree.IndentedTree,
|
|
30
33
|
Line: () => import_line.Line,
|
|
31
34
|
Liquid: () => import_liquid.Liquid,
|
|
35
|
+
Mindmap: () => import_mindmap.Mindmap,
|
|
36
|
+
NetworkGraph: () => import_network_graph.NetworkGraph,
|
|
37
|
+
OrganizationChart: () => import_organization_chart.OrganizationChart,
|
|
32
38
|
Pie: () => import_pie.Pie,
|
|
33
39
|
Radar: () => import_radar.Radar,
|
|
34
40
|
Sankey: () => import_sankey.Sankey,
|
|
@@ -40,7 +46,8 @@ __export(src_exports, {
|
|
|
40
46
|
Violin: () => import_violin.Violin,
|
|
41
47
|
Waterfall: () => import_waterfall.Waterfall,
|
|
42
48
|
WordCloud: () => import_word_cloud.WordCloud,
|
|
43
|
-
isVisSyntax: () => import_syntax.isVisSyntax
|
|
49
|
+
isVisSyntax: () => import_syntax.isVisSyntax,
|
|
50
|
+
parse: () => import_syntax.parse
|
|
44
51
|
});
|
|
45
52
|
module.exports = __toCommonJS(src_exports);
|
|
46
53
|
var import_gpt_vis = require("./gpt-vis");
|
|
@@ -50,10 +57,16 @@ var import_bar = require("./vis/bar");
|
|
|
50
57
|
var import_boxplot = require("./vis/boxplot");
|
|
51
58
|
var import_column = require("./vis/column");
|
|
52
59
|
var import_dual_axes = require("./vis/dual-axes");
|
|
60
|
+
var import_fishbone_diagram = require("./vis/fishbone-diagram");
|
|
61
|
+
var import_flow_diagram = require("./vis/flow-diagram");
|
|
53
62
|
var import_funnel = require("./vis/funnel");
|
|
54
63
|
var import_histogram = require("./vis/histogram");
|
|
64
|
+
var import_indented_tree = require("./vis/indented-tree");
|
|
55
65
|
var import_line = require("./vis/line");
|
|
56
66
|
var import_liquid = require("./vis/liquid");
|
|
67
|
+
var import_mindmap = require("./vis/mindmap");
|
|
68
|
+
var import_network_graph = require("./vis/network-graph");
|
|
69
|
+
var import_organization_chart = require("./vis/organization-chart");
|
|
57
70
|
var import_pie = require("./vis/pie");
|
|
58
71
|
var import_radar = require("./vis/radar");
|
|
59
72
|
var import_sankey = require("./vis/sankey");
|
|
@@ -72,11 +85,17 @@ var import_word_cloud = require("./vis/word-cloud");
|
|
|
72
85
|
Boxplot,
|
|
73
86
|
Column,
|
|
74
87
|
DualAxes,
|
|
88
|
+
FishboneDiagram,
|
|
89
|
+
FlowDiagram,
|
|
75
90
|
Funnel,
|
|
76
91
|
GPTVis,
|
|
77
92
|
Histogram,
|
|
93
|
+
IndentedTree,
|
|
78
94
|
Line,
|
|
79
95
|
Liquid,
|
|
96
|
+
Mindmap,
|
|
97
|
+
NetworkGraph,
|
|
98
|
+
OrganizationChart,
|
|
80
99
|
Pie,
|
|
81
100
|
Radar,
|
|
82
101
|
Sankey,
|
|
@@ -88,5 +107,6 @@ var import_word_cloud = require("./vis/word-cloud");
|
|
|
88
107
|
Violin,
|
|
89
108
|
Waterfall,
|
|
90
109
|
WordCloud,
|
|
91
|
-
isVisSyntax
|
|
110
|
+
isVisSyntax,
|
|
111
|
+
parse
|
|
92
112
|
});
|