X6 v3 Graph Editor
Overview
X6 v3 is AntV's diagram editing engine for flowcharts, DAGs, ER diagrams, org charts, and other interactive node-edge editors. Unlike G2/G6, X6 uses an imperative API — you create a Graph instance, then call graph.addNode(), graph.addEdge(), and register plugins via graph.use().
import { Graph } from '@antv/x6';
const graph = new Graph({
container: 'container',
background: { color: '#F2F7FA' },
});
const source = graph.addNode({
shape: 'rect',
x: 40, y: 40, width: 100, height: 40,
label: 'Source',
attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
});
const target = graph.addNode({
shape: 'rect',
x: 300, y: 200, width: 100, height: 40,
label: 'Target',
attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
});
graph.addEdge({ source, target, attrs: { line: { stroke: '#8f8f8f', strokeWidth: 1 } } });
graph.centerContent();
CDN Usage
<script src="https://unpkg.com/@antv/x6@3/dist/x6.js"></script>
<script>
const graph = new X6.Graph({
container: 'container',
background: { color: '#F2F7FA' },
});
const source = graph.addNode({
shape: 'rect',
x: 40, y: 40, width: 100, height: 40,
label: 'Source',
attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
});
const target = graph.addNode({
shape: 'rect',
x: 300, y: 200, width: 100, height: 40,
label: 'Target',
attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
});
graph.addEdge({ source, target, attrs: { line: { stroke: '#8f8f8f', strokeWidth: 1 } } });
graph.centerContent();
</script>
Content Retrieval Service
When using AntV X6 for data visualization, if you need to understand the concepts, usage, API, examples, and other aspects of X6 v3, you can use the provided context retrieval service. When using the skill, content is retrieved via an antv HTTP API server using GET requests.
- Host:
https://sive.antv.antgroup.com
- Endpoint:
/api/v1/context/retrieve
- Method:
GET
- Parameters:
query, library, topK, content, maxTokens
Retrieve skills by query (hybrid search = FTS + vector + RRF fusion). Constraints docs are indexed as regular skill documents and will appear in search results naturally.
| Parameter |
Type |
Required |
Description |
query |
string |
✅ |
Search keywords, e.g. flowchart stencil port |
library |
string |
✅ |
Library name: g2, g6, x6 |
topK |
number |
|
Number of results to return (default: 5) |
content |
boolean |
|
Return full reference doc markdown (default: true) |
maxTokens |
number |
|
Max tokens per result (default: unlimited) |
curl "https://sive.antv.antgroup.com/api/v1/context/retrieve?query=flowchart+stencil+port&library=x6"
Critical Rules
MUST: graph.render() does NOT exist in X6 v3
// ❌ WRONG — graph.render() is G6 API, not X6
const graph = new Graph({ container: 'container' });
graph.render();
// ✅ CORRECT — X6 auto-renders on addNode/addEdge/fromJSON
const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
graph.addNode({ shape: 'rect', x: 40, y: 40, width: 100, height: 40 });
MUST: Use string literal container: 'container' — no variable declaration
// ❌ WRONG — declaring container variable is forbidden
const container = document.getElementById('container');
const graph = new Graph({ container });
// ✅ CORRECT — string literal, runtime auto-resolves
const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
MUST: Register plugins before using their methods
// ❌ WRONG — calling plugin method without registration
graph.toPNG(); // Error: method not found
graph.select(); // Error: method not found
// ✅ CORRECT — register first, then call
import { Graph, Export, Selection } from '@antv/x6';
const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
graph.use(new Export());
graph.use(new Selection({ enabled: true, rubberband: true }));
// Now graph.toPNG() and graph.select() are available
MUST: Only 11 plugin classes exist — NOT constructor options
✅ Plugin class (import + graph.use) |
❌ NOT a plugin (constructor option) |
Clipboard, Dnd, Export, History, Keyboard, MiniMap, Scroller, Selection, Snapline, Stencil, Transform |
mousewheel, embedding, panning, connecting, translating, interacting, background, grid |
// ❌ WRONG — importing constructor option as "plugin"
import { Graph, Embedding } from '@antv/x6'; // Embedding doesn't exist!
graph.use(new Embedding()); // Error: not a constructor
// ✅ CORRECT — embedding is a Graph constructor option
import { Graph, Selection } from '@antv/x6';
const graph = new Graph({
container: 'container',
embedding: { enabled: true, findParent: 'bbox' },
mousewheel: { enabled: true, zoomAtMousePosition: true, modifiers: ['ctrl'] },
});
graph.use(new Selection({ enabled: true, rubberband: true }));
MUST: All used classes MUST appear in import statement
// ❌ WRONG — Selection used but not imported
import { Graph } from '@antv/x6';
graph.use(new Selection({...})); // falls back to window.Selection → Illegal constructor
// ✅ CORRECT — every used class imported
import { Graph, Selection, Keyboard, History } from '@antv/x6';
graph.use(new Selection({ enabled: true, rubberband: true }));
graph.use(new Keyboard({ enabled: true }));
graph.use(new History({ enabled: true }));
MUST: Always call graph.centerContent() after adding nodes/edges
// ❌ WRONG — no centerContent, content drifts to top-left
graph.addNode({ ... });
graph.addEdge({ ... });
// ✅ CORRECT — content centered after all additions
graph.addNode({ ... });
graph.addEdge({ ... });
graph.centerContent();
// OR: graph.zoomToFit({ padding: 20, maxScale: 1 }) — but NOT both
MUST: Always set background color, default node/edge style
// ❌ WRONG — no background, no default styles
const graph = new Graph({ container: 'container' });
// ✅ CORRECT — mandatory background + default styles
const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
graph.addNode({
shape: 'rect', x: 40, y: 40, width: 100, height: 40,
label: 'Node',
attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
});
graph.addEdge({
source: 'node-1', target: 'node-2',
attrs: { line: { stroke: '#8f8f8f', strokeWidth: 1 } },
});
MUST: mousewheel, panning, Selection.rubberband — use modifiers to avoid conflicts
// ❌ WRONG — panning and mousewheel both grab scroll events
const graph = new Graph({
panning: { enabled: true },
mousewheel: { enabled: true },
});
graph.use(new Selection({ enabled: true, rubberband: true }));
// ✅ CORRECT — modifiers separate the interactions
const graph = new Graph({
panning: { enabled: true, eventTypes: ['leftMouseDown'], modifiers: 'shift' },
mousewheel: { enabled: true, zoomAtMousePosition: true, modifiers: ['ctrl'] },
});
graph.use(new Selection({ enabled: true, rubberband: true }));
MUST: Output pure JavaScript — NO TypeScript syntax
// ❌ WRONG — TypeScript syntax
private width: number = 100;
const node: Node = graph.addNode({...}) as Node;
// ✅ CORRECT — pure JavaScript only
const node = graph.addNode({ shape: 'rect', x: 40, y: 40 });
MUST: Shape.HTML.register for HTML nodes — NOT class extends Node
// ❌ WRONG — class-based HTML node (2.x pattern)
class MyNode extends Node { ... }
// ✅ CORRECT — Shape.HTML.register (3.x pattern)
import { Graph, Shape } from '@antv/x6';
Shape.HTML.register({
shape: 'my-html',
effect: ['data'],
html(node) {
const div = document.createElement('div');
div.innerHTML = node.getData().content || '';
return div;
},
});
Quick Reference
| User Intent |
Retrieve Query |
| Graph init, container, background |
GET /api/v1/context/retrieve?query=graph+init+container+background&library=x6 |
| Flowchart / approval flow |
GET /api/v1/context/retrieve?query=flowchart+approval&library=x6 |
| DAG / data pipeline |
GET /api/v1/context/retrieve?query=DAG+pipeline+port&library=x6 |
| ER diagram / entity relationship |
GET /api/v1/context/retrieve?query=ER+diagram+entity+relationship&library=x6 |
| Lineage / data lineage graph |
GET /api/v1/context/retrieve?query=lineage+data+lineage&library=x6 |
| Org chart / hierarchy |
GET /api/v1/context/retrieve?query=org+chart+hierarchy&library=x6 |
| UML class diagram |
GET /api/v1/context/retrieve?query=UML+class+diagram&library=x6 |
| Node config / custom node |
GET /api/v1/context/retrieve?query=node+custom+shape+rect+circle&library=x6 |
| Edge config / router / connector |
GET /api/v1/context/retrieve?query=edge+router+connector+orth+smooth&library=x6 |
| Ports / connection桩 |
GET /api/v1/context/retrieve?query=ports+connection+layout&library=x6 |
| HTML shape node |
GET /api/v1/context/retrieve?query=html+shape+register&library=x6 |
| Stencil / drag-and-drop panel |
GET /api/v1/context/retrieve?query=stencil+drag+drop+panel&library=x6 |
| Plugin: Selection, History, Clipboard |
GET /api/v1/context/retrieve?query=Selection+History+Clipboard+plugin&library=x6 |
| Plugin: MiniMap, Scroller, Snapline |
GET /api/v1/context/retrieve?query=MiniMap+Scroller+Snapline+plugin&library=x6 |
| Plugin: Keyboard, Export, Transform |
GET /api/v1/context/retrieve?query=Keyboard+Export+Transform+plugin&library=x6 |
| Panning / mousewheel / embedding |
GET /api/v1/context/retrieve?query=panning+mousewheel+embedding&library=x6 |
| Tools (button-remove, etc.) |
GET /api/v1/context/retrieve?query=tools+button-remove+hover&library=x6 |
| Events (click,mouseenter,moved) |
GET /api/v1/context/retrieve?query=events+node+click+mouse&library=x6 |
| Serialization (toJSON, fromJSON) |
GET /api/v1/context/retrieve?query=serialization+toJSON+fromJSON&library=x6 |
| Animation / gradient |
GET /api/v1/context/retrieve?query=animation+gradient+defs+marker&library=x6 |
| Group / nesting / embedding |
GET /api/v1/context/retrieve?query=group+nesting+embedding+parent+child&library=x6 |
Dependencies
@antv/x6 — X6 v3 diagram editing engine (exports Graph + 11 plugin classes)
1---
2name: antv-x6-editor
3description: "Use this skill whenever the user wants to create, customize, or troubleshoot X6 v3 graph editor diagrams. Triggers include: any mention of 'X6', 'antv x6', '@antv/x6', 'X6 editor', 'X6 图编辑', '流程图', 'DAG', 'ER图', '实体关系图', '血缘图', '组织架构图', 'UML类图', 'flowchart', 'DAG diagram', 'ER diagram', 'lineage graph', 'org chart', 'network topology', 'stencil', 'drag-and-drop editor', 'port connection', 'node port edge', 'graph editor', 'diagram editor', or requests about X6 node/edge styling, plugins (Selection, History, Clipboard, Keyboard, MiniMap, Scroller, Snapline, Stencil, Dnd, Transform, Export), interactions (panning, mousewheel, connecting, embedding), HTML shape nodes, custom shapes, serialization, or layout. Also use when debugging X6 rendering errors, v2→v3 migration, or editor interaction issues. Do NOT use for G2 statistical charts, G6 network graphs, or S2 pivot tables."
4tools:
5 - curl
6metadata:
7 source: https://skillmd.com/skills/antvis/antv-x6-editor
8---
9
10# X6 v3 Graph Editor
11
12## Overview
13
14X6 v3 is AntV's diagram editing engine for flowcharts, DAGs, ER diagrams, org charts, and other interactive node-edge editors. Unlike G2/G6, X6 uses an **imperative API** — you create a `Graph` instance, then call `graph.addNode()`, `graph.addEdge()`, and register plugins via `graph.use()`.
15
16```javascript
17import { Graph } from '@antv/x6';
18
19const graph = new Graph({
20 container: 'container',
21 background: { color: '#F2F7FA' },
22});
23
24const source = graph.addNode({
25 shape: 'rect',
26 x: 40, y: 40, width: 100, height: 40,
27 label: 'Source',
28 attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
29});
30
31const target = graph.addNode({
32 shape: 'rect',
33 x: 300, y: 200, width: 100, height: 40,
34 label: 'Target',
35 attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
36});
37
38graph.addEdge({ source, target, attrs: { line: { stroke: '#8f8f8f', strokeWidth: 1 } } });
39graph.centerContent();
40```
41
42### CDN Usage
43
44```html
45<script src="https://unpkg.com/@antv/x6@3/dist/x6.js"></script>
46<script>
47 const graph = new X6.Graph({
48 container: 'container',
49 background: { color: '#F2F7FA' },
50 });
51 const source = graph.addNode({
52 shape: 'rect',
53 x: 40, y: 40, width: 100, height: 40,
54 label: 'Source',
55 attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
56 });
57 const target = graph.addNode({
58 shape: 'rect',
59 x: 300, y: 200, width: 100, height: 40,
60 label: 'Target',
61 attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
62 });
63 graph.addEdge({ source, target, attrs: { line: { stroke: '#8f8f8f', strokeWidth: 1 } } });
64 graph.centerContent();
65</script>
66```
67
68## Content Retrieval Service
69
70When using AntV X6 for data visualization, if you need to understand the concepts, usage, API, examples, and other aspects of X6 v3, you can use the provided context retrieval service. When using the skill, content is retrieved via an antv HTTP API server using GET requests.
71
72- Host: `https://sive.antv.antgroup.com`
73- Endpoint: `/api/v1/context/retrieve`
74- Method: `GET`
75- Parameters: `query`, `library`, `topK`, `content`, `maxTokens`
76
77Retrieve skills by query (hybrid search = FTS + vector + RRF fusion). Constraints docs are indexed as regular skill documents and will appear in search results naturally.
78
79| Parameter | Type | Required | Description |
80|---|---|---|---|
81| `query` | string | ✅ | Search keywords, e.g. `flowchart stencil port` |
82| `library` | string | ✅ | Library name: `g2`, `g6`, `x6` |
83| `topK` | number | | Number of results to return (default: 5) |
84| `content` | boolean | | Return full reference doc markdown (default: true) |
85| `maxTokens` | number | | Max tokens per result (default: unlimited) |
86
87```bash
88curl "https://sive.antv.antgroup.com/api/v1/context/retrieve?query=flowchart+stencil+port&library=x6"
89```
90
91## Critical Rules
92
93### MUST: `graph.render()` does NOT exist in X6 v3
94
95```javascript
96// ❌ WRONG — graph.render() is G6 API, not X6
97const graph = new Graph({ container: 'container' });
98graph.render();
99
100// ✅ CORRECT — X6 auto-renders on addNode/addEdge/fromJSON
101const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
102graph.addNode({ shape: 'rect', x: 40, y: 40, width: 100, height: 40 });
103```
104
105### MUST: Use string literal `container: 'container'` — no variable declaration
106
107```javascript
108// ❌ WRONG — declaring container variable is forbidden
109const container = document.getElementById('container');
110const graph = new Graph({ container });
111
112// ✅ CORRECT — string literal, runtime auto-resolves
113const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
114```
115
116### MUST: Register plugins before using their methods
117
118```javascript
119// ❌ WRONG — calling plugin method without registration
120graph.toPNG(); // Error: method not found
121graph.select(); // Error: method not found
122
123// ✅ CORRECT — register first, then call
124import { Graph, Export, Selection } from '@antv/x6';
125const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
126graph.use(new Export());
127graph.use(new Selection({ enabled: true, rubberband: true }));
128// Now graph.toPNG() and graph.select() are available
129```
130
131### MUST: Only 11 plugin classes exist — NOT constructor options
132
133| ✅ Plugin class (import + `graph.use`) | ❌ NOT a plugin (constructor option) |
134|---|---|
135| `Clipboard`, `Dnd`, `Export`, `History`, `Keyboard`, `MiniMap`, `Scroller`, `Selection`, `Snapline`, `Stencil`, `Transform` | `mousewheel`, `embedding`, `panning`, `connecting`, `translating`, `interacting`, `background`, `grid` |
136
137```javascript
138// ❌ WRONG — importing constructor option as "plugin"
139import { Graph, Embedding } from '@antv/x6'; // Embedding doesn't exist!
140graph.use(new Embedding()); // Error: not a constructor
141
142// ✅ CORRECT — embedding is a Graph constructor option
143import { Graph, Selection } from '@antv/x6';
144const graph = new Graph({
145 container: 'container',
146 embedding: { enabled: true, findParent: 'bbox' },
147 mousewheel: { enabled: true, zoomAtMousePosition: true, modifiers: ['ctrl'] },
148});
149graph.use(new Selection({ enabled: true, rubberband: true }));
150```
151
152### MUST: All used classes MUST appear in import statement
153
154```javascript
155// ❌ WRONG — Selection used but not imported
156import { Graph } from '@antv/x6';
157graph.use(new Selection({...})); // falls back to window.Selection → Illegal constructor
158
159// ✅ CORRECT — every used class imported
160import { Graph, Selection, Keyboard, History } from '@antv/x6';
161graph.use(new Selection({ enabled: true, rubberband: true }));
162graph.use(new Keyboard({ enabled: true }));
163graph.use(new History({ enabled: true }));
164```
165
166### MUST: Always call `graph.centerContent()` after adding nodes/edges
167
168```javascript
169// ❌ WRONG — no centerContent, content drifts to top-left
170graph.addNode({ ... });
171graph.addEdge({ ... });
172
173// ✅ CORRECT — content centered after all additions
174graph.addNode({ ... });
175graph.addEdge({ ... });
176graph.centerContent();
177// OR: graph.zoomToFit({ padding: 20, maxScale: 1 }) — but NOT both
178```
179
180### MUST: Always set background color, default node/edge style
181
182```javascript
183// ❌ WRONG — no background, no default styles
184const graph = new Graph({ container: 'container' });
185
186// ✅ CORRECT — mandatory background + default styles
187const graph = new Graph({ container: 'container', background: { color: '#F2F7FA' } });
188graph.addNode({
189 shape: 'rect', x: 40, y: 40, width: 100, height: 40,
190 label: 'Node',
191 attrs: { body: { stroke: '#8f8f8f', strokeWidth: 1, fill: '#fff', rx: 6, ry: 6 } },
192});
193graph.addEdge({
194 source: 'node-1', target: 'node-2',
195 attrs: { line: { stroke: '#8f8f8f', strokeWidth: 1 } },
196});
197```
198
199### MUST: `mousewheel`, `panning`, `Selection.rubberband` — use modifiers to avoid conflicts
200
201```javascript
202// ❌ WRONG — panning and mousewheel both grab scroll events
203const graph = new Graph({
204 panning: { enabled: true },
205 mousewheel: { enabled: true },
206});
207graph.use(new Selection({ enabled: true, rubberband: true }));
208
209// ✅ CORRECT — modifiers separate the interactions
210const graph = new Graph({
211 panning: { enabled: true, eventTypes: ['leftMouseDown'], modifiers: 'shift' },
212 mousewheel: { enabled: true, zoomAtMousePosition: true, modifiers: ['ctrl'] },
213});
214graph.use(new Selection({ enabled: true, rubberband: true }));
215```
216
217### MUST: Output pure JavaScript — NO TypeScript syntax
218
219```javascript
220// ❌ WRONG — TypeScript syntax
221private width: number = 100;
222const node: Node = graph.addNode({...}) as Node;
223
224// ✅ CORRECT — pure JavaScript only
225const node = graph.addNode({ shape: 'rect', x: 40, y: 40 });
226```
227
228### MUST: `Shape.HTML.register` for HTML nodes — NOT `class extends Node`
229
230```javascript
231// ❌ WRONG — class-based HTML node (2.x pattern)
232class MyNode extends Node { ... }
233
234// ✅ CORRECT — Shape.HTML.register (3.x pattern)
235import { Graph, Shape } from '@antv/x6';
236Shape.HTML.register({
237 shape: 'my-html',
238 effect: ['data'],
239 html(node) {
240 const div = document.createElement('div');
241 div.innerHTML = node.getData().content || '';
242 return div;
243 },
244});
245```
246
247## Quick Reference
248
249| User Intent | Retrieve Query |
250|---|---|
251| Graph init, container, background | `GET /api/v1/context/retrieve?query=graph+init+container+background&library=x6` |
252| Flowchart / approval flow | `GET /api/v1/context/retrieve?query=flowchart+approval&library=x6` |
253| DAG / data pipeline | `GET /api/v1/context/retrieve?query=DAG+pipeline+port&library=x6` |
254| ER diagram / entity relationship | `GET /api/v1/context/retrieve?query=ER+diagram+entity+relationship&library=x6` |
255| Lineage / data lineage graph | `GET /api/v1/context/retrieve?query=lineage+data+lineage&library=x6` |
256| Org chart / hierarchy | `GET /api/v1/context/retrieve?query=org+chart+hierarchy&library=x6` |
257| UML class diagram | `GET /api/v1/context/retrieve?query=UML+class+diagram&library=x6` |
258| Node config / custom node | `GET /api/v1/context/retrieve?query=node+custom+shape+rect+circle&library=x6` |
259| Edge config / router / connector | `GET /api/v1/context/retrieve?query=edge+router+connector+orth+smooth&library=x6` |
260| Ports / connection桩 | `GET /api/v1/context/retrieve?query=ports+connection+layout&library=x6` |
261| HTML shape node | `GET /api/v1/context/retrieve?query=html+shape+register&library=x6` |
262| Stencil / drag-and-drop panel | `GET /api/v1/context/retrieve?query=stencil+drag+drop+panel&library=x6` |
263| Plugin: Selection, History, Clipboard | `GET /api/v1/context/retrieve?query=Selection+History+Clipboard+plugin&library=x6` |
264| Plugin: MiniMap, Scroller, Snapline | `GET /api/v1/context/retrieve?query=MiniMap+Scroller+Snapline+plugin&library=x6` |
265| Plugin: Keyboard, Export, Transform | `GET /api/v1/context/retrieve?query=Keyboard+Export+Transform+plugin&library=x6` |
266| Panning / mousewheel / embedding | `GET /api/v1/context/retrieve?query=panning+mousewheel+embedding&library=x6` |
267| Tools (button-remove, etc.) | `GET /api/v1/context/retrieve?query=tools+button-remove+hover&library=x6` |
268| Events (click,mouseenter,moved) | `GET /api/v1/context/retrieve?query=events+node+click+mouse&library=x6` |
269| Serialization (toJSON, fromJSON) | `GET /api/v1/context/retrieve?query=serialization+toJSON+fromJSON&library=x6` |
270| Animation / gradient | `GET /api/v1/context/retrieve?query=animation+gradient+defs+marker&library=x6` |
271| Group / nesting / embedding | `GET /api/v1/context/retrieve?query=group+nesting+embedding+parent+child&library=x6` |
272
273## Dependencies
274
275- `@antv/x6` — X6 v3 diagram editing engine (exports `Graph` + 11 plugin classes)