@antv/gpt-vis 1.0.0-beta.2 → 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 CHANGED
@@ -1,42 +1,42 @@
1
1
  <img src="https://gw.alipayobjects.com/zos/antfincdn/R8sN%24GNdh6/language.svg" width="18"> English | [简体中文](./README.zh-CN.md)
2
2
 
3
- <h1 align="center">GPT-Vis, Visualization for AI Friendly!</h1>
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
- AI-Native Visualization Components for the LLM Era. Framework-agnostic visualization library designed for AI-powered applications.
11
+ AI-native visualization library for the LLM era. Framework-agnostic, ready to use.
9
12
 
10
13
  [![npm version](https://img.shields.io/npm/v/@antv/gpt-vis.svg)](https://www.npmjs.com/package/@antv/gpt-vis)
11
14
  [![npm downloads](https://img.shields.io/npm/dm/@antv/gpt-vis.svg)](https://www.npmjs.com/package/@antv/gpt-vis)
12
15
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
13
16
 
14
17
  <p align="center">
15
- <a href="https://gpt-vis.antv.vision" target="_blank">📖 Documentation</a>
16
- <a href="/skills/chart-visualization" target="_blank">🤖 Chart Skill</a>
17
- <a href="/knowledges" target="_blank">🧠 Knowledge Base</a>
18
- <a href="https://www.tbox.cn/share/202504APmv6c00373739?platform=WebService" target="_blank">🎮 Try Demo</a>
19
- <a href="https://github.com/antvis/mcp-server-chart" target="_blank">🔌 MCP Server</a>
18
+ <a href="https://gpt-vis.antv.vision" target="_blank">📖 Documentation</a> ·
19
+ <a href="https://gpt-vis.antv.vision/examples" target="_blank">🎨 Examples</a> ·
20
+ <a href="https://github.com/antvis/mcp-server-chart" target="_blank">🔌 MCP Server</a> ·
21
+ <a href="/skills/chart-visualization" target="_blank">🧩 Chart Skill</a>
20
22
  </p>
21
23
 
22
24
  </div>
23
25
 
24
26
  <div align="center">
25
- <video src="https://github.com/user-attachments/assets/24b0d820-ebf8-4351-bc5b-4fa607a76e17" />
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
- > **📢 Version 1.0 Preview**: Reimagined architecture optimized for AI. Stable release expected **March 21, 2026**.
31
-
32
32
  ## ✨ Features
33
33
 
34
- - **🚀 Framework Agnostic**: Works with vanilla JavaScript, React, Vue, Angular, or any framework
35
- - **✍️ Natural Syntax**: Simple, markdown-like syntax that LLMs can generate effortlessly
36
- - **🌊 Streaming Support**: Built-in support for streaming output from AI models
37
- - **🛡️ Fault Tolerant**: Gracefully handles incomplete or malformed data
38
- - **📊 20+ Chart Types**: Statistical, relationship, and advanced visualization charts
39
- - **🧠 Intelligent Defaults**: Automatic data detection, smart color schemes, adaptive layouts
34
+ - 🚀 **Framework Agnostic** Works with vanilla JavaScript, React, Vue, Angular, or any framework
35
+ - ✍️ **Markdown-like Syntax** Simple syntax that LLMs can generate directly, easy to learn and use
36
+ - 🌊 **Streaming Rendering** Native support for AI model streaming output, renders as it generates
37
+ - 🛡️ **Fault Tolerant** Gracefully handles incomplete or malformed data, adapts to the uncertainty of AI-generated content
38
+ - 📊 **26 Chart Types** Statistical charts, relationship graphs, and text visualizations covering mainstream scenarios
39
+ - 🎨 **Theme System** Built-in light, dark, and academy themes with customizable color palettes
40
40
 
41
41
  ## 🚀 Quick Start
42
42
 
@@ -57,7 +57,7 @@ const gptVis = new GPTVis({
57
57
  height: 400,
58
58
  });
59
59
 
60
- // Render with markdown-like syntax
60
+ // Markdown-like visualization syntax
61
61
  const visSyntax = `
62
62
  vis line
63
63
  data
@@ -72,7 +72,11 @@ data
72
72
  gptVis.render(visSyntax);
73
73
  ```
74
74
 
75
- ### Streaming Support
75
+ ### Streaming Rendering
76
+
77
+ Charts render as the AI model generates, no need to wait for the full response:
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';
@@ -90,18 +94,20 @@ function onToken(token) {
90
94
 
91
95
  ## 📚 Syntax Guide
92
96
 
93
- ### Basic Structure
97
+ `render()` supports two input formats: vis syntax (ideal for LLM streaming) and JSON objects (ideal for programmatic use).
98
+
99
+ ### Vis Syntax
100
+
101
+ Declarative markdown-like syntax that LLMs can generate without learning complex APIs:
94
102
 
95
103
  ```
96
104
  vis [chart-type]
97
105
  [property] [value]
98
106
  data
99
- - [key] [value]
107
+ - [field] [value]
100
108
  ```
101
109
 
102
- ### Examples
103
-
104
- **Simple chart:**
110
+ **Pie chart:**
105
111
 
106
112
  ```
107
113
  vis pie
@@ -113,7 +119,29 @@ data
113
119
  innerRadius 0.6
114
120
  ```
115
121
 
116
- **With style:**
122
+ **Themes:**
123
+
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
+ ```
133
+ vis line
134
+ data
135
+ - time 2020
136
+ value 100
137
+ - time 2021
138
+ value 120
139
+ theme dark
140
+ ```
141
+
142
+ **Custom Styles:**
143
+
144
+ Use `style` to set line width, custom palettes, and more:
117
145
 
118
146
  ```
119
147
  vis line
@@ -129,17 +157,89 @@ style
129
157
  - #5AD8A6
130
158
  ```
131
159
 
160
+ **Quoted string values (for values with spaces):**
161
+
162
+ ```
163
+ vis pie
164
+ data
165
+ - category "Q1 Sales"
166
+ value 30
167
+ - category "Q2 Sales"
168
+ value 25
169
+ ```
170
+
132
171
  **Hierarchical data:**
133
172
 
134
173
  ```
135
- vis mind-map
174
+ vis mindmap
136
175
  data
137
- - name Project
176
+ - name Project Plan
138
177
  children
139
178
  - name Phase 1
140
179
  - name Phase 2
141
180
  ```
142
181
 
182
+ ### JSON Objects
183
+
184
+ Also supports passing JSON objects directly, ideal for programmatic use:
185
+
186
+ ```javascript
187
+ gptVis.render({
188
+ type: 'pie',
189
+ data: [
190
+ { category: 'Android', value: 72 },
191
+ { category: 'iOS', value: 28 },
192
+ ],
193
+ });
194
+ ```
195
+
196
+ ## 📊 Chart Types
197
+
198
+ 26 chart types covering statistical analysis, relationship networks, and text visualization.
199
+
200
+ ### Statistical Charts (18)
201
+
202
+ | Chart | Type Identifier |
203
+ | ---------- | --------------- |
204
+ | Line | `line` |
205
+ | Area | `area` |
206
+ | Column | `column` |
207
+ | Bar | `bar` |
208
+ | Pie | `pie` |
209
+ | Scatter | `scatter` |
210
+ | Radar | `radar` |
211
+ | Funnel | `funnel` |
212
+ | Waterfall | `waterfall` |
213
+ | Dual Axes | `dual-axes` |
214
+ | Histogram | `histogram` |
215
+ | Boxplot | `boxplot` |
216
+ | Violin | `violin` |
217
+ | Venn | `venn` |
218
+ | Sankey | `sankey` |
219
+ | Treemap | `treemap` |
220
+ | Word Cloud | `word-cloud` |
221
+ | Liquid | `liquid` |
222
+
223
+ ### Relationship Charts (6)
224
+
225
+ | Chart | Type Identifier |
226
+ | ------------------ | -------------------- |
227
+ | Flow Diagram | `flow-diagram` |
228
+ | Network Graph | `network-graph` |
229
+ | Mindmap | `mindmap` |
230
+ | Indented Tree | `indented-tree` |
231
+ | Organization Chart | `organization-chart` |
232
+ | Fishbone Diagram | `fishbone-diagram` |
233
+
234
+ ### Text Visualization (2)
235
+
236
+ | Chart | Type Identifier |
237
+ | ------- | --------------- |
238
+ | Table | `table` |
239
+ | Summary | `summary` |
240
+
241
+ Explore all examples → [Examples Gallery](https://gpt-vis.antv.vision/examples)
242
+
143
243
  ## 🔧 Framework Integration
144
244
 
145
245
  <details>
@@ -191,25 +291,22 @@ function ChartComponent({ visSyntax }) {
191
291
  </template>
192
292
 
193
293
  <script setup>
194
- import { ref, onMounted, onUnmounted, watch } from 'vue';
294
+ import { ref, watch, onUnmounted } from 'vue';
195
295
  import { GPTVis } from '@antv/gpt-vis';
196
296
 
197
297
  const props = defineProps(['visSyntax']);
198
298
  const chartRef = ref(null);
199
299
  let gptVis = null;
200
300
 
201
- onMounted(() => {
202
- gptVis = new GPTVis({ container: chartRef.value, width: 600, height: 400 });
203
- gptVis.render(props.visSyntax);
204
- });
205
-
206
301
  watch(
207
302
  () => props.visSyntax,
208
- (newSyntax) => {
209
- if (gptVis) {
210
- gptVis.render(newSyntax);
303
+ (syntax) => {
304
+ if (!gptVis) {
305
+ gptVis = new GPTVis({ container: chartRef.value, width: 600, height: 400 });
211
306
  }
307
+ gptVis.render(syntax);
212
308
  },
309
+ { immediate: true },
213
310
  );
214
311
 
215
312
  onUnmounted(() => gptVis?.destroy());
@@ -218,19 +315,96 @@ onUnmounted(() => gptVis?.destroy());
218
315
 
219
316
  </details>
220
317
 
221
- ## 🧠 Knowledge Base
318
+ <details>
319
+ <summary><strong>Markdown Renderer (marked)</strong></summary>
222
320
 
223
- GPT-Vis includes a comprehensive [knowledge base](https://github.com/antvis/GPT-Vis/tree/main/knowledges) to help LLMs understand when to use each chart type and how to structure data. Evaluated on 200+ scenarios with 90%+ accuracy.
321
+ GPT-Vis syntax naturally works with Markdown code fences and integrates with any Markdown renderer. The following example uses `marked` + `marked-highlight` normal code blocks get syntax highlighting, while `vis` code blocks are rendered as interactive charts.
224
322
 
225
- ## 🤝 Contributing
323
+ **Install dependencies:**
324
+
325
+ ```bash
326
+ npm install @antv/gpt-vis marked marked-highlight highlight.js
327
+ ```
328
+
329
+ **Complete example:**
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
+ `;
226
388
 
227
- > **⚠️ AI-Generated Code Policy**: This project only merges AI-generated code.
389
+ document.getElementById('content').innerHTML = marked.parse(markdown);
390
+ ```
391
+
392
+ </details>
393
+
394
+ ## 🤖 AI Ecosystem
395
+
396
+ GPT-Vis provides a complete AI integration solution:
397
+
398
+ - **[MCP Server](https://github.com/antvis/mcp-server-chart)** — Enable AI models to directly invoke visualization capabilities via Model Context Protocol
399
+ - **[Chart Skill](https://github.com/antvis/GPT-Vis/tree/main/skills/chart-visualization)** — Provide AI assistants with chart recommendation and generation capabilities, supporting both syntax mode and code mode output
400
+
401
+ ## 🤝 Contributing
228
402
 
229
- To contribute:
403
+ > **AI-Generated Code Policy**: This project only merges AI-generated code.
230
404
 
231
- 1. Submit an Issue describing the problem or feature
405
+ 1. Submit an Issue describing the problem or feature request
232
406
  2. Tag @copilot to generate the implementation
233
- 3. Submit PR with AI-generated code
407
+ 3. Submit a PR with AI-generated code
234
408
 
235
409
  ## 📄 License
236
410