vue3-network-graph 0.1.2 → 0.1.4

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.en.md CHANGED
@@ -1,266 +1,656 @@
1
- # vue3-network-graph
1
+ # vue3-network-graph Usage Guide
2
2
 
3
- A network topology component built with **Vue 3 + SVG** — no third-party chart libraries. Supports node dragging, drag-to-resize node boxes, **infinite canvas panning**, **Ctrl + left-drag box selection**, **multi-node group dragging**, wheel zoom, flow animations, three line modes, plus **multi-edge anti-overlap bundling** and **along-path upright edge labels**. The component exposes data APIs and **mouse ⇄ SVG coordinate conversion** methods via template ref.
3
+ A lightweight network topology component based on **Vue 3 + SVG** with no third-party chart library dependencies. Supports node dragging, infinite canvas panning, zoom wheel, connection flow animations, three connection modes, multi-line overlap prevention for the same node pairs, and upright connection text along paths.
4
4
 
5
- ## Features
5
+ ---
6
6
 
7
- - **Line modes**: `straight` / `polyline` / `curve` via the `lineMode` prop
8
- - **Multi-edge anti-overlap**: multiple edges between the same node pair (including opposite directions) fan out into parallel lines / parallel arcs / staggered polylines — no overlap in any mode
9
- - **Along-path upright labels**: `fromText` / `centerText` / `toText` rotate with the path tangent; angles beyond ±90° are auto-flipped so labels are never upside-down
10
- - **Edge merging**: more than 6 edges between the same pair collapse into one line with a count badge; clicking a merged line selects the whole group — `edge-select` returns the representative with a `bundleEdges` array (all edges in the group), and `selection-change` lists every edge of the group
11
- - **Nodes**: 2D / 2.5D icons, breathing status ring, text nodes, custom icon slot `#node-icon`
12
- - **Interaction**: node dragging (**group drag for multi-selections**), drag-to-resize node boxes, **infinite canvas panning**, wheel zoom, node/edge selection, **Ctrl+click multi-select**, **Ctrl+left-drag marquee select**, flow animation (dashed light + particles)
13
- - **Large-graph performance**: decorative effects auto-degrade above size budgets (overridable); nodes take hit priority over dense overlapping edges — thousand-node graphs stay smooth to pan and drag
14
- - **Coordinates**: `clientToSvg` (mouse → SVG) and `svgToClient` (SVG → screen), callable from outside via template ref
15
- - **Appearance config**: canvas background radial gradient (inner/outer colors, custom stops), grid (color / step / opacity) and selection colors — all through `config`
16
- - **Data sync**: in-component ↔ external two-way sync — deep-watched props (array replacement and in-place edits), edits published via events / v-model, `setData()` for full external replacement
17
- - **Extras**: group dashed frames, grid background, 10 node states
7
+ ## Table of Contents
18
8
 
19
- ## Install
9
+ - [Name](#name)
10
+ - [Description](#description)
11
+ - [Usage](#usage)
12
+ - [Examples](#examples)
13
+ - [Global Configuration Properties](#global-configuration-properties)
14
+ - [Node Properties](#node-properties)
15
+ - [Connection Properties](#connection-properties)
16
+ - [API Methods](#api-methods)
17
+ - [Events](#events)
18
+ - [Interactions](#interactions)
19
+
20
+ ---
21
+
22
+ ## Name
23
+
24
+ **vue3-network-graph** - Vue3 Network Topology Component
25
+
26
+ ---
27
+
28
+ ## Description
29
+
30
+ A lightweight network topology component implemented with pure SVG, providing the following core capabilities:
31
+
32
+ ### Core Features
33
+
34
+ - **Multiple Connection Modes**: Straight (straight) / Polyline (polyline) / Curve (curve)
35
+ - **Smart Multi-line Handling**: Multiple connections between the same pair of nodes automatically prevent overlap, staying parallel in any mode
36
+ - **Upright Connection Text**: `fromText` / `centerText` / `toText` rotate along the path tangentially, automatically flipping when exceeding ±90° to maintain readability
37
+ - **Rich Node Types**: 8 icon nodes + text nodes + border-only nodes
38
+ - **2D/3D Views**: Supports both 2D plane and 2.5D card styles
39
+ - **Flow Animations**: Dashed流光 + particle effects, with per-connection animation control
40
+
41
+ ### Interaction Capabilities
42
+
43
+ - **Node Operations**: Drag to move, drag to resize, multi-select overall drag
44
+ - **Canvas Operations**: Infinite panning (blank left-click/middle-click), zoom wheel (0.2x–5x)
45
+ - **Selection Modes**: Single-click select, Ctrl+click multi-select, Ctrl+left-drag box select
46
+ - **Connection Creation**: Auto-connect by dragging from node handle to target node
47
+ - **Layer Management**: Z-axis sorting, right-click menu, keyboard shortcuts (requires `enableZOrder`)
48
+
49
+ ### Performance Optimization
50
+
51
+ - **Automatic Degradation**: Decorative animations automatically disabled based on scale (connections>200 disable流光,>500 disable glow, nodes>300 disable breathing)
52
+ - **Large-scale Performance**: Thousands of nodes can pan/drag smoothly, nodes always responsive to clicks in dense graphics
53
+
54
+ ---
55
+
56
+ ## Usage
57
+
58
+ ### 1. Installation
20
59
 
21
60
  ```bash
22
61
  npm install vue3-network-graph
23
62
  # or: pnpm add vue3-network-graph | yarn add vue3-network-graph
24
63
  ```
25
64
 
65
+ ### 2. Import Component
66
+
26
67
  ```js
68
+ // main.js
69
+ import { createApp } from "vue";
27
70
  import { Topology } from "vue3-network-graph";
28
- import "vue3-network-graph/style.css"; // styles are imported separately
71
+ import "vue3-network-graph/style.css";
29
72
 
30
- // Optional global registration:
31
- import Vue3NetworkGraph from "vue3-network-graph";
32
- app.use(Vue3NetworkGraph); // then <Topology /> is available everywhere
73
+ const app = createApp(App);
74
+ app.component("Topology", Topology);
75
+ app.mount("#app");
33
76
  ```
34
77
 
35
- - Vue is a peer dependency (`^3.2.0`). Ships ESM + UMD builds and TypeScript declarations.
78
+ Or local import:
79
+
80
+ ```vue
81
+ <script setup>
82
+ import { Topology } from "vue3-network-graph";
83
+ import "vue3-network-graph/style.css";
84
+ </script>
85
+ ```
36
86
 
37
- ## Basic Usage
87
+ ### 3. Basic Usage
38
88
 
39
89
  ```vue
90
+ <template>
91
+ <Topology
92
+ ref="topoRef"
93
+ :editable="true"
94
+ v-model:nodes="myNodes"
95
+ v-model:edges="myEdges"
96
+ :config="config"
97
+ @node-click="handleNodeClick"
98
+ @selection-change="handleSelectionChange"
99
+ />
100
+ </template>
101
+
40
102
  <script setup>
41
103
  import { ref } from "vue";
42
104
  import { Topology } from "vue3-network-graph";
43
- import "vue3-network-graph/style.css";
44
105
 
45
- /* Nodes / edges (/ groups) are plain arrays — bring your own data */
46
106
  const myNodes = ref([
47
- { id: "core", label: "Core", type: "core", state: "normal", x: 0, y: 0 },
107
+ { id: "node1", label: "Node 1", type: "core", state: "normal", x: 0, y: 0 },
48
108
  {
49
- id: "web-1",
50
- label: "Web-1",
109
+ id: "node2",
110
+ label: "Node 2",
51
111
  type: "server",
52
112
  state: "normal",
53
- x: 160,
54
- y: -80,
113
+ x: 200,
114
+ y: 100,
55
115
  },
56
- { id: "db-1", label: "DB-1", type: "database", state: "idle", x: 160, y: 80 },
57
116
  ]);
117
+
58
118
  const myEdges = ref([
59
- { id: "e1", from: "core", to: "web-1" },
60
- { id: "e2", from: "core", to: "db-1", centerText: "query" },
119
+ { id: "edge1", from: "node1", to: "node2", centerText: "Connection" },
120
+ ]);
121
+
122
+ const config = ref({
123
+ showGrid: true,
124
+ nodeDraggable: true,
125
+ nodeResizable: true,
126
+ });
127
+ </script>
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Examples
133
+
134
+ ### Complete Example
135
+
136
+ ```vue
137
+ <template>
138
+ <div class="topology-container">
139
+ <Topology
140
+ ref="topoRef"
141
+ :editable="true"
142
+ v-model:nodes="nodes"
143
+ v-model:edges="edges"
144
+ v-model:line-mode="lineMode"
145
+ v-model:view-mode="viewMode"
146
+ :groups="groups"
147
+ :config="config"
148
+ @node-click="onNodeClick"
149
+ @edge-select="onEdgeSelect"
150
+ @selection-change="onSelectionChange"
151
+ @data-change="onDataChange"
152
+ @edge-create="onEdgeCreate"
153
+ >
154
+ <!-- Custom node icon slot -->
155
+ <template #node-icon="{ node, color, viewMode }">
156
+ <circle r="16" :fill="color" opacity="0.9" />
157
+ </template>
158
+ </Topology>
159
+ </div>
160
+ </template>
161
+
162
+ <script setup>
163
+ import { ref, onMounted } from "vue";
164
+ import { Topology } from "vue3-network-graph";
165
+ import "vue3-network-graph/style.css";
166
+
167
+ // Node data
168
+ const nodes = ref([
169
+ {
170
+ id: "core",
171
+ label: "Core Switch",
172
+ nodeType: "core",
173
+ state: "normal",
174
+ x: 0,
175
+ y: 0,
176
+ width: 80,
177
+ height: 80,
178
+ },
179
+ {
180
+ id: "server1",
181
+ label: "Web Server",
182
+ nodeType: "server",
183
+ state: "normal",
184
+ x: 300,
185
+ y: -150,
186
+ },
187
+ {
188
+ id: "db1",
189
+ label: "Database",
190
+ nodeType: "database",
191
+ state: "idle",
192
+ x: 300,
193
+ y: 150,
194
+ },
195
+ // Border-only node example
196
+ {
197
+ id: "border-box",
198
+ label: "",
199
+ nodeType: "border-only",
200
+ state: "none",
201
+ x: -400,
202
+ y: -200,
203
+ width: 250,
204
+ height: 150,
205
+ borderWidth: 2,
206
+ borderColor: "#00f0ff",
207
+ },
208
+ ]);
209
+
210
+ // Connection data
211
+ const edges = ref([
212
+ { id: "e1", from: "core", to: "server1", speed: 1.5, endMarker: "arrow" },
213
+ {
214
+ id: "e2",
215
+ from: "core",
216
+ to: "db1",
217
+ speed: 2,
218
+ centerText: "Query Traffic",
219
+ endMarker: "arrow",
220
+ },
61
221
  ]);
62
- const myGroups = ref([
222
+
223
+ // Group example
224
+ const groups = ref([
63
225
  {
64
226
  id: "g1",
65
- label: "App layer",
227
+ label: "Application Zone",
66
228
  color: "#409eff",
67
- nodeIds: ["web-1", "db-1"],
229
+ nodeIds: ["server1", "db1"],
230
+ padding: 20,
68
231
  },
69
232
  ]);
70
- const lineMode = ref("straight"); // straight | polyline | curve
233
+
234
+ // Connection mode and view mode
235
+ const lineMode = ref("curve"); // straight | polyline | curve
71
236
  const viewMode = ref("2d"); // 2d | 3d
237
+
238
+ // Configuration
239
+ const config = ref({
240
+ selectedBorderColor: "#ffd400",
241
+ selectedLineColor: "#ffd400",
242
+ nodeDraggable: true,
243
+ nodeResizable: true,
244
+ enableZoom: true,
245
+ enablePan: true,
246
+ enableMarquee: true,
247
+ showGrid: true,
248
+ gridColor: "#1a2240",
249
+ gridStep: 40,
250
+ gridOpacity: 0.5,
251
+ radialGradient: {
252
+ startColor: "#0f1729",
253
+ endColor: "#060a14",
254
+ },
255
+ showStatusDot: true,
256
+ motionFx: true,
257
+ maxSelectNodes: "unlimited",
258
+ maxSelectEdges: "unlimited",
259
+ enableZOrder: false,
260
+ });
261
+
262
+ // Component instance reference
72
263
  const topoRef = ref(null);
264
+
265
+ // Event handlers
266
+ const onNodeClick = (node) => {
267
+ console.log("Node clicked:", node);
268
+ };
269
+
270
+ const onEdgeSelect = (edge) => {
271
+ console.log("Connection selected:", edge);
272
+ };
273
+
274
+ const onSelectionChange = (selection) => {
275
+ console.log("Selection changed:", selection);
276
+ console.log("Selected nodes:", selection.nodes);
277
+ console.log("Selected connections:", selection.edges);
278
+ };
279
+
280
+ const onDataChange = (payload) => {
281
+ console.log("Data changed:", payload);
282
+ console.log("Change summary:", payload.summary);
283
+ };
284
+
285
+ const onEdgeCreate = (edge) => {
286
+ console.log("New connection:", edge);
287
+ // Persist newly created connection
288
+ edges.value = [...edges.value, edge];
289
+ };
290
+
291
+ // Method call examples
292
+ const handleMethods = () => {
293
+ // Get current data
294
+ const data = topoRef.value.getData();
295
+
296
+ // Add nodes
297
+ topoRef.value.addNodes([
298
+ { label: "New Node", nodeType: "server", x: 500, y: 0 },
299
+ ]);
300
+
301
+ // Add connections
302
+ topoRef.value.addEdges([{ from: "core", to: "new-node-id" }]);
303
+
304
+ // Update nodes
305
+ topoRef.value.updateNodes([{ id: "core", label: "Updated Name" }]);
306
+
307
+ // Delete selected elements
308
+ topoRef.value.removeSelected();
309
+
310
+ // Coordinate conversion
311
+ const svgPos = topoRef.value.clientToSvg(event);
312
+ const clientPos = topoRef.value.svgToClient(node.x, node.y);
313
+
314
+ // Layer management (requires enableZOrder)
315
+ topoRef.value.moveToFront("node-id");
316
+ topoRef.value.moveToBack("node-id");
317
+ topoRef.value.moveLayerUp("node-id");
318
+ topoRef.value.moveLayerDown("node-id");
319
+ };
73
320
  </script>
74
321
 
322
+ <style scoped>
323
+ .topology-container {
324
+ width: 100%;
325
+ height: 600px;
326
+ background: radial-gradient(ellipse at center, #0f1729 0%, #060a14 100%);
327
+ }
328
+ </style>
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Global Configuration Properties
334
+
335
+ | Config Item | Type | Default | Description |
336
+ | --------------------- | ----------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
337
+ | `selectedBorderColor` | `String` | `#fbbf24` | Selected node border color |
338
+ | `selectedLineColor` | `String` | `#fbbf24` | Selected connection color |
339
+ | `nodeDraggable` | `Boolean` | `true` | Node drag switch (requires `editable`) |
340
+ | `nodeResizable` | `Boolean` | `true` | Node resize switch (requires `editable`) |
341
+ | `enableZoom` | `Boolean` | `true` | Zoom wheel switch |
342
+ | `enablePan` | `Boolean` | `true` | Canvas pan switch |
343
+ | `enableMarquee` | `Boolean` | `true` | Ctrl + left-drag box select switch |
344
+ | `maxSelectNodes` | `Number \| "unlimited"` | Unlimited | Max selectable nodes: `0` (disabled) / `1` / `2` or any non-negative integer; unset or `"unlimited"` no limit |
345
+ | `maxSelectEdges` | `Number \| "unlimited"` | Unlimited | Max selectable connections (merged bundles count all connections in group) |
346
+ | `showGrid` | `Boolean` | `true` | Grid background (set `false` to disable) |
347
+ | `gridColor` | `String` | `#1a2240` | Grid line color |
348
+ | `gridStep` | `Number` | `40` | Grid spacing (px at 1x zoom, scales with zoom) |
349
+ | `gridOpacity` | `Number` | `0.5` | Grid overlay opacity (0–1) |
350
+ | `radialGradient` | `Object` | See notes | Canvas background radial gradient |
351
+ | `showCenterPoint` | `Boolean` | `false` | Canvas center cross marker |
352
+ | `showEdgeTextBg` | `Boolean` | `false` | Connection text background |
353
+ | `edgeTextBgColor` | `String` | `#0a0e1a` | Connection text background color |
354
+ | `showNodeHandles` | `Boolean` | `false` | Node handles (four small circles appear at top/bottom/left/right of nodes, auto-connect when dragged to another node) |
355
+ | `showStatusDot` | `Boolean` | `true` | Status dot at top-right corner of each node |
356
+ | `labelGap` | `Number` | `18` | Fixed gap between node box edge and its label (px at 1x zoom) |
357
+ | `watchDataChanges` | `Boolean` | `false` | Component internal data change detection (debounce 300ms then trigger `data-change`) |
358
+ | `fx` | `Boolean` | Auto | Master decorative animation switch: `false` all off / `true` all on / unset = auto |
359
+ | `motionFx` | `Boolean` | Auto | Per-feature override - connection line animation (flow + particles) |
360
+ | `glowFx` | `Boolean` | Auto | Per-feature override - connection glow |
361
+ | `breatheFx` | `Boolean` | Auto | Per-feature override - breathing ring |
362
+ | `fxMotionMaxEdges` | `Number` | `200` | Edge count above which flow + particle animation auto-disables |
363
+ | `fxGlowMaxEdges` | `Number` | `500` | Edge count above which edge glow auto-disables |
364
+ | `fxBreatheMaxNodes` | `Number` | `300` | Node count above which breathing rings auto-disable |
365
+ | `enableZOrder` | `Boolean` | `false` | **Enable Z-axis layer sorting**: After enabling, nodes render according to `zIndex` property, supporting layer operation API, right-click menu and keyboard shortcuts |
366
+
367
+ ### radialGradient Configuration
368
+
369
+ ```javascript
370
+ // Simple mode
371
+ radialGradient: {
372
+ startColor: "#0f1729",
373
+ endColor: "#060a14"
374
+ }
375
+
376
+ // Advanced mode (custom gradient center and color stops)
377
+ radialGradient: {
378
+ cx: "50%",
379
+ cy: "50%",
380
+ r: "50%",
381
+ stops: [
382
+ { offset: "0%", color: "#0f1729", opacity: 1 },
383
+ { offset: "60%", color: "#1e293b", opacity: 0.8 },
384
+ { offset: "100%", color: "#060a14", opacity: 1 }
385
+ ]
386
+ }
387
+ ```
388
+
389
+ ---
390
+
391
+ ## Node Properties
392
+
393
+ | Property | Type | Required | Default | Description |
394
+ | --------------- | ------------------------------- | -------- | ----------- | ---------------------------------------------------------------------------------- |
395
+ | `id` | `String` | ✅ | - | Unique node identifier |
396
+ | `label` | `String \| null` | ❌ | `null` | Node display text (supports `\n` newline), border-only and text nodes can be empty |
397
+ | `nodeType` | `String` | ❌ | `"server"` | Node type (see types list below) |
398
+ | `state` | `String` | ❌ | `"none"` | Node status (see status list below) |
399
+ | `x` | `Number` | ✅ | - | Node X coordinate (SVG coordinate system) |
400
+ | `y` | `Number` | ✅ | - | Node Y coordinate (SVG coordinate system) |
401
+ | `width` | `Number` | ❌ | `60` | Node width (required for border-only nodes) |
402
+ | `height` | `Number` | ❌ | `60` | Node height (required for border-only nodes) |
403
+ | `rotation` | `Number` | ❌ | `0` | Node rotation angle (degrees) |
404
+ | `fontColor` | `String` | ❌ | `"#ffffff"` | Text color |
405
+ | `fontSize` | `Number` | ❌ | `11` | Font size |
406
+ | `fontWeight` | `Number \| String` | ❌ | `500` | Font weight (100–900) |
407
+ | `borderColor` | `String` | ❌ | `"#94a3b8"` | Border color |
408
+ | `borderWidth` | `Number` | ❌ | `0` | Border width (0 means no border) |
409
+ | `borderStyle` | `"dashed" \| ""` | ❌ | `""` | Border style: `"dashed"` dashed, `""` solid |
410
+ | `background` | `String` | ❌ | `"#0f1729"` | Background color |
411
+ | `borderRadius` | `Number` | ❌ | `6` | Corner radius (px) |
412
+ | `labelPosition` | `"top" \| "center" \| "bottom"` | ❌ | `"bottom"` | Label position |
413
+ | `zIndex` | `Number` | ❌ | `0` | Z-axis layer index (requires `enableZOrder`) |
414
+
415
+ ### Node Types (nodeType)
416
+
417
+ | Type | Icon | Description |
418
+ | ---------------- | ----------------------------- | ------------------------------------------------ |
419
+ | `"core"` | Hexagon | Core device |
420
+ | `"server"` | Stacked rectangles | Server |
421
+ | `"firewall"` | Rectangle with lines | Firewall |
422
+ | `"loadbalancer"` | Circle + polyline | Load balancer |
423
+ | `"database"` | Cylinder | Database |
424
+ | `"cdn"` | Concentric circles | CDN node |
425
+ | `"cache"` | Hexagon + center circle | Cache |
426
+ | `"queue"` | Rectangle with vertical lines | Queue |
427
+ | `"text"` | Text lines | Pure text node |
428
+ | `"border-only"` | Hollow rectangle | Border-only node (only border outline displayed) |
429
+
430
+ ### Node Status (state)
431
+
432
+ | Status | Color | Description |
433
+ | ------------ | ------------ | ------------------- |
434
+ | `"none"` | Hidden | No status indicator |
435
+ | `"normal"` | Green | Normal |
436
+ | `"warning"` | Yellow | Warning |
437
+ | `"error"` | Red | Error |
438
+ | `"info"` | Blue | Info |
439
+ | `"active"` | Cyan | Active |
440
+ | `"disabled"` | Gray | Disabled |
441
+ | `"locked"` | Purple | Locked |
442
+ | `"master"` | Dark red | Master node |
443
+ | `"expert"` | Pink | Expert node |
444
+ | `"advanced"` | Orange | Advanced node |
445
+ | `"adept"` | Light orange | Adept node |
446
+ | `"awakened"` | Blue | Awakened node |
447
+ | `"dormant"` | Gray-purple | Dormant node |
448
+
449
+ ---
450
+
451
+ ## Connection Properties
452
+
453
+ | Property | Type | Required | Default | Description |
454
+ | ------------ | ---------------------------- | -------- | ----------- | ------------------------------------------------------------------------------------ |
455
+ | `id` | `String` | ✅ | - | Unique connection identifier (auto-generated uuid) |
456
+ | `from` | `String` | ✅ | - | Source node id |
457
+ | `to` | `String` | ✅ | - | Target node id |
458
+ | `speed` | `Number` | ❌ | `1` | Flow speed multiplier (animation speed) |
459
+ | `animated` | `Boolean` | ❌ | `true` | Per-connection animation switch (`false` disables流光/particles for this connection) |
460
+ | `fromAnchor` | `"center" \| "edge"` | ❌ | `"edge"` | Start anchor: `"center"` center / `"edge"` boundary intersection |
461
+ | `toAnchor` | `"center" \| "edge"` | ❌ | `"edge"` | End anchor: `"center"` center / `"edge"` boundary intersection |
462
+ | `fromText` | `String \| Object` | ❌ | `""` | Start text (see text format below) |
463
+ | `centerText` | `String \| Object` | ❌ | `""` | Center text (see text format below) |
464
+ | `toText` | `String \| Object` | ❌ | `""` | End text (see text format below) |
465
+ | `endMarker` | `"none" \| "arrow" \| "dot"` | ❌ | `"none"` | End marker: `"none"` none / `"arrow"` arrow / `"dot"` dot |
466
+ | `fontSize` | `Number` | ❌ | `8` | Connection text size |
467
+ | `fontColor` | `String` | ❌ | `"#00f0ff"` | Connection text color |
468
+
469
+ ### Connection Text Format
470
+
471
+ ```javascript
472
+ // String shorthand form
473
+ fromText: "Start Text"
474
+
475
+ // Object full form
476
+ fromText: {
477
+ text: "Start Text", // Text content
478
+ rotation: 0, // Additional rotation angle (degrees)
479
+ fontSize: 10, // Font size
480
+ color: "#ffffff" // Color
481
+ }
482
+ ```
483
+
484
+ ---
485
+
486
+ ## API Methods
487
+
488
+ Call methods exposed by the component via template ref:
489
+
490
+ ```vue
75
491
  <template>
76
- <Topology
77
- ref="topoRef"
78
- :editable="true"
79
- v-model:nodes="myNodes"
80
- v-model:line-mode="lineMode"
81
- v-model:view-mode="viewMode"
82
- :edges="myEdges"
83
- :groups="myGroups"
84
- :config="{
85
- showGrid: false,
86
- nodeDraggable: true,
87
- nodeResizable: true,
88
- enableZoom: true,
89
- }"
90
- @node-click="(n) => console.log(n)"
91
- @edge-select="(e) => console.log(e)"
92
- @selection-change="(sel) => console.log(sel.nodes, sel.edges)"
93
- >
94
- <!-- Optional: custom node icon -->
95
- <template #node-icon="{ node, color, viewMode }">
96
- <circle r="16" :fill="color" opacity="0.9" />
97
- </template>
98
- </Topology>
492
+ <Topology ref="topoRef" />
99
493
  </template>
494
+
495
+ <script setup>
496
+ import { ref } from "vue";
497
+
498
+ const topoRef = ref(null);
499
+
500
+ // All method call examples
501
+ const methods = () => {
502
+ // === Data Methods ===
503
+
504
+ // Get current latest data (deep copy)
505
+ const { nodes, edges } = topoRef.value.getData();
506
+
507
+ // Reset data change detection baseline
508
+ topoRef.value.resetDataBaseline();
509
+
510
+ // Replace entire dataset from outside
511
+ topoRef.value.setData({ nodes: nextNodes });
512
+
513
+ // Delete currently selected nodes and connections (deleting nodes cascades to delete all connected connections)
514
+ const removed = topoRef.value.removeSelected();
515
+
516
+ // Add nodes (array or single)
517
+ topoRef.value.addNodes([{ label: "New Node", x: 0, y: 0 }]);
518
+
519
+ // Add connections (array or single)
520
+ topoRef.value.addEdges([{ from: "a", to: "b" }]);
521
+
522
+ // Partially update nodes by id (shallow merge, undefined ignored, unknown ids skipped)
523
+ topoRef.value.updateNodes([{ id: "node-1", label: "Renamed", width: 120 }]);
524
+
525
+ // Partially update connections by id
526
+ topoRef.value.updateEdges([{ id: "edge-1", speed: 2 }]);
527
+
528
+ // === Layer Management (requires enableZOrder: true) ===
529
+
530
+ // Move up one layer
531
+ topoRef.value.moveLayerUp("node-id");
532
+
533
+ // Move down one layer
534
+ topoRef.value.moveLayerDown("node-id");
535
+
536
+ // Move to front (highest zIndex)
537
+ topoRef.value.moveToFront("node-id");
538
+
539
+ // Move to back (lowest zIndex)
540
+ topoRef.value.moveToBack("node-id");
541
+
542
+ // === Coordinate Conversion ===
543
+
544
+ // Scenario 1: Mouse coordinates → SVG coordinates (parameters can be event object or coordinate pair)
545
+ const p1 = topoRef.value.clientToSvg(e); // Pass event object directly
546
+ const p2 = topoRef.value.clientToSvg(clientX, y); // Pass coordinate pair
547
+
548
+ // Scenario 2: SVG coordinates → Screen coordinates (input node.x / node.y, output clientX/clientY)
549
+ const node = topoRef.value.getData().nodes[0];
550
+ const { x, y } = topoRef.value.svgToClient(node.x, node.y);
551
+ menu.style.left = `${x}px`;
552
+ menu.style.top = `${y}px`;
553
+ };
554
+ </script>
100
555
  ```
101
556
 
102
- ## Interaction Reference (mouse / keyboard)
103
-
104
- | Action | Gesture | Notes |
105
- | ---------------------- | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
106
- | Select a node / edge | Left click | Clicking an already-selected item deselects it; clicking blank canvas clears the whole selection |
107
- | Multi-select (click) | Ctrl (⌘ on macOS) + click | Adds/removes nodes and edges to/from the selection — mixed node+edge selections supported |
108
- | Multi-select (marquee) | Ctrl (⌘ on macOS) + left-drag | Draws a rectangle on the blank canvas; **every node intersecting it** joins the selection (union semantics; nodes only) |
109
- | Drag one node | Drag anywhere on the node area | Requires `editable` and `config.nodeDraggable !== false`; the whole node area (box + label strip, icon-label gap included) is a hit area; dragging an unselected node selects it first |
110
- | Drag many nodes | Drag any **already-selected** node | The whole selection moves together — identical deltas; the selection survives the drag |
111
- | Pan (infinite) | Left-drag on blank canvas, or middle-drag anywhere | No bounds at all; content and grid move together; selection untouched |
112
- | Zoom | Wheel | Zooms around the mouse position (0.2x–5x) |
113
- | Resize a node | Drag one of the 8 handles on a single-selected node | Requires `editable`, `config.nodeResizable !== false` |
114
- | Create an edge | Drag a node handle onto another node | Requires `config.showNodeHandles: true` |
115
-
116
- > Left-button “click” vs “drag” on the blank canvas is separated by a small threshold (4px pan / 3px marquee / 3px node drag): below it the gesture still counts as a click (clears or toggles the selection); above it the drag takes over. A stray click dispatched by the browser right after a drag gesture is suppressed, so selections are never changed accidentally. The whole node area (box + label strip) is a hit area: click and drag work anywhere inside it, including the gap between icon and label.
117
-
118
- ## Performance with large graphs
119
-
120
- Large-graph performance optimizations ship on by default — no configuration needed. Decorative effects (the most expensive SVG features) switch off above size budgets:
121
-
122
- ### Decorative effects auto-degrade (overridable)
123
-
124
- Flow/particle animations, glow filters and breathing rings are the most expensive SVG features; they switch off above size budgets:
125
-
126
- | Effect | Auto-off threshold (default) | Override |
127
- | ------------------------- | ---------------------------- | ------------------------------------------------- |
128
- | Flow + particle animation | edges > 200 | `motionFx: true/false` or `fxMotionMaxEdges: n` |
129
- | Edge glow filter | edges > 500 | `glowFx: true/false` or `fxGlowMaxEdges: n` |
130
- | Node breathing ring | nodes > 300 | `breatheFx: true/false` or `fxBreatheMaxNodes: n` |
131
-
132
- - Master switch `config.fx`: `false` = everything off (cheapest) / `true` = everything on / unset = automatic; per-feature overrides win over the master switch.
133
- - Typical use: a "performance mode" toggle = `config.fx = false`.
134
-
135
- ### Hit priority in dense graphs
136
-
137
- Wherever an edge and a node overlap, clicks/drags act on the **node**; edges stay clickable wherever no node covers them — nodes remain selectable and draggable no matter how dense the wiring gets.
138
-
139
- ## Props
140
-
141
- | Prop | Type | Default | Description |
142
- | ------------------ | --------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143
- | `nodes` | `Array` | `[]` | `id` `label` `type` `state` `x` `y` `width` `height` `fontColor` `fontSize` `fontWeight` `borderColor` `borderWidth` `borderStyle` `background` `labelPosition`(`top`/`center`/`bottom`) `rotation`; `type: "text"` for text-only nodes |
144
- | `edges` | `Array` | `[]` | `id` `from` `to` `speed` `animated` (per-edge animation switch; `false` stops this edge's flow + particles) `fromAnchor` `toAnchor` (`center`/`edge` boundary intersection) `fromText` `centerText` `toText` `endMarker` (`none`/`arrow`/`dot`) `fontSize` `fontColor` |
145
- | `groups` | `Array` | `[]` | Dashed group frames: `id` `label` `color` `nodeIds` `padding` `rotation` |
146
- | `lineMode` | `String` | `"curve"` | `straight` / `polyline` / `curve` (`v-model:line-mode` supported) |
147
- | `viewMode` | `String` | `"2d"` | `2d` / `3d` (2.5D card style, `v-model:view-mode` supported) |
148
- | `editable` | `Boolean` | `false` | Master switch for editing: enables node dragging and resizing (pan / marquee are not gated by it — control them via `config`) |
149
- | `width` / `height` | `Number` | container size | Base canvas size |
150
- | `config` | `Object` | `{}` | Interaction & appearance options — see below |
151
-
152
- > `nodes` / `edges` / `groups` all default to empty arrays (blank canvas) — simply pass your own data. For `type` / `state` palettes, see the exported `nodeColors` (type colors: `core` / `server` / `firewall` / `loadbalancer` / `database` / `cdn` / `cache` / `queue` / `text`) and `nodeStates` (10 status colors incl. `normal` / `warning` / `error`).
153
-
154
- ### config Options
155
-
156
- | Option | Type | Default | Description |
157
- | ----------------------------------- | ----------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
158
- | `selectedBorderColor` | `String` | `#fbbf24` | Selected node border color |
159
- | `selectedLineColor` | `String` | `#fbbf24` | Selected edge color |
160
- | `nodeDraggable` | `Boolean` | `true` | Node dragging (requires `editable`) |
161
- | `nodeResizable` | `Boolean` | `true` | Drag-handle resizing (requires `editable`; 4 corner + 4 edge handles on single selection) |
162
- | `enableZoom` | `Boolean` | `true` | Wheel zoom |
163
- | `enablePan` | `Boolean` | `true` | **Canvas panning** (blank left-drag / middle-drag) |
164
- | `enableMarquee` | `Boolean` | `true` | **Ctrl + left-drag marquee selection** |
165
- | `maxSelectNodes` | `Number \| "unlimited"` | unlimited | **Max selectable nodes**: `0` (nodes cannot be selected) / `1` / `2` or any non-negative integer; unset or `"unlimited"` = no cap. Over-sized gestures only add what fits (deselecting is never blocked); lowering the cap trims the selection (first N kept) |
166
- | `maxSelectEdges` | `Number \| "unlimited"` | unlimited | **Max selectable edges** (a merged bundle counts every edge it contains); otherwise same as `maxSelectNodes` |
167
- | `showGrid` | `Boolean` | `true` | Grid background (set `false` to hide) |
168
- | `gridColor` | `String` | `#1a2240` | Grid line color |
169
- | `gridStep` | `Number` | `40` | Grid cell size in px at 1x zoom (scales with zoom) |
170
- | `gridOpacity` | `Number` | `0.5` | Grid overlay opacity (0–1) |
171
- | `radialGradient` | `Object` | see notes | Canvas background radial gradient: `{ startColor, endColor }` or `{ cx, cy, r, stops: [...] }`; default `#0f1729 → #060a14` |
172
- | `showCenterPoint` | `Boolean` | `false` | Canvas center crosshair |
173
- | `showEdgeTextBg` | `Boolean` | `false` | Edge label plates |
174
- | `edgeTextBgColor` | `String` | `#0a0e1a` | Plate color |
175
- | `showNodeHandles` | `Boolean` | `false` | Node handles (four small circles for drag-to-connect) |
176
- | `showStatusDot` | `Boolean` | `true` | Status dot at each node's top-right corner (**shown by default**; set `false` to hide all) |
177
- | `watchDataChanges` | `Boolean` | `false` | In-component data change tracking (debounced 300ms → `data-change`) |
178
- | `fx` | `Boolean` | auto | Master switch for decorative effects: `false` = all off (cheapest) / `true` = all on / unset = automatic (see "Performance with large graphs") |
179
- | `motionFx` / `glowFx` / `breatheFx` | `Boolean` | auto | Per-feature overrides: **connection-line animation (flow + particles)** / edge glow / breathing rings; a single edge can opt out via the data field `edge.animated: false` |
180
- | `fxMotionMaxEdges` | `Number` | `200` | Edge-count threshold above which flow+particle animation turns off |
181
- | `fxGlowMaxEdges` | `Number` | `500` | Edge-count threshold above which edge glow turns off |
182
- | `fxBreatheMaxNodes` | `Number` | `300` | Node-count threshold above which breathing rings turn off |
557
+ ---
183
558
 
184
559
  ## Events
185
560
 
186
- | Event | Payload | Description |
187
- | --------------------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
188
- | `update:nodes` | `nodes` | Node data updated (`v-model:nodes`); keeps firing while dragging / resizing |
189
- | `update:lineMode` / `update:viewMode` | `string` | Mode changes (`v-model:*`) |
190
- | `node-click` | `node` | Node clicked |
191
- | `node-select` | `node\|null` | Single-selection change (use `selection-change` for multi) |
192
- | `edge-select` | `edge\|null` | Edge selection (merged bundles carry `bundleEdges`) |
193
- | `selection-change` | `{ nodes, edges }` | Fired whenever the selection changes; `nodes`/`edges` are the selected object arrays. **Ctrl+click and marquee selections are both read from here** |
194
- | `data-change` | `{ nodes, edges, summary }` | With `watchDataChanges` on, fired (300ms debounced) after changes; `nodes`/`edges` are a deep copy of the full current data, `summary` holds `added/removed/updated` id lists relative to the baseline |
195
- | `edge-create` | `edge` | Fired after dragging a node handle onto another node; the edge is already rendered temporarily — persist it here |
196
- | `edge-remove` | `edges` | Fired after `removeSelected()` removes edges; includes edges cascaded from deleted nodes |
197
- | `edge-update` | `edges` | Fired after `updateEdges()`; merge the payload back into your own array by id |
198
- | `node-drag-start` / `node-drag-end` | `node` / — | Drag lifecycle; also fired for group drags (payload = the grabbed node) |
199
- | `node-resize-start` / `node-resize-end` | `node` / `node\|null` | Resize gesture start / end (`update:nodes` keeps firing while resizing) |
200
-
201
- **Multi-select notes**: hold `Ctrl` (⌘ on macOS) and click to toggle items in the selection (mixed node+edge supported); `Ctrl + left-drag` on the blank canvas marquee-selects nodes (union); a plain click selects a single item and clears the rest; clicking blank canvas clears everything. The number of selected items can be capped via `config.maxSelectNodes` / `config.maxSelectEdges` (`0` = that kind cannot be selected; unset = no cap).
202
-
203
- Edge labels accept a plain string or `{ text, rotation, fontSize, color }`.
204
-
205
- ### Slots
206
-
207
- | Slot | Slot props | Description |
208
- | ------------ | --------------------------- | ------------------------------------------------------- |
209
- | `#node-icon` | `{ node, color, viewMode }` | Custom node icon content (replaces the built-in shapes) |
210
-
211
- ## Component Methods (via template ref)
212
-
213
- | Method | Description |
214
- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
215
- | `getData()` | Pull the latest data on demand (deep copy): returns `{ nodes, edges }` including all in-component edits (drag positions, resized dimensions, handle-created edges). Call it anytime — independent of `watchDataChanges` — and mutate the result safely |
216
- | `resetDataBaseline()` | Re-arms data change tracking: snapshots the current data as the new baseline |
217
- | `setData(data?)` | Full replace from outside (load a new graph / restore a snapshot): clears in-component bookkeeping (locally created edges, removal tombstones, field patches) and re-arms change tracking; pass `{ nodes }` to have them published via `update:nodes`, omit it to re-sync from current props; update your own `edges` array in the same operation; returns a deep copy of the new data |
218
- | `removeSelected()` | Delete the current selection: removing a node also **cascades to every connected edge**; syncs via `update:nodes` / `edge-remove`; returns `{ nodes, edges }` deep copies of what was deleted |
219
- | `addNodes(nodes)` | Append nodes: missing `id`s auto-generated, existing ids skipped; syncs via `update:nodes`; returns deep copies |
220
- | `addEdges(edges)` | Append edges: requires `from`/`to`, missing `id`s auto-generated, duplicates skipped; emits `edge-create`; returns deep copies |
221
- | `updateNodes(nodes)` | Patch nodes by id (shallow merge, `undefined` ignored); syncs via `update:nodes`; returns deep copies |
222
- | `updateEdges(edges)` | Patch edges by id; emits `edge-update`; returns deep copies |
223
- | `clientToSvg(input, clientY?)` | **Mouse → SVG coordinates**: pass a mouse event object (`clientToSvg(e)`) or an explicit pair (`clientToSvg(clientX, clientY)`); returns `{ x, y }` **in the node coordinate system** (zoom & pan already accounted for), directly comparable to `node.x` / `node.y`; returns `null` when the SVG is not mounted |
224
- | `svgToClient(x, y)` | **SVG → screen coordinates**: feed `node.x` / `node.y` and get `{ x, y }` in `clientX/clientY` terms — handy for positioning DOM overlays above a node; returns `null` when not mounted |
561
+ | Event Name | Parameters | Description |
562
+ | ------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------- |
563
+ | `update:nodes` | `nodes` | Node data update (`v-model:nodes`); continuously triggered during drag/resize |
564
+ | `update:lineMode` | `string` | Connection mode change (`v-model:line-mode`) |
565
+ | `update:viewMode` | `string` | View mode change (`v-model:view-mode`) |
566
+ | `node-click` | `node` | Node clicked |
567
+ | `node-select` | `node \| null` | Single node selection change (use `selection-change` for multi-select scenarios) |
568
+ | `edge-select` | `edge \| null` | Connection selection change (merged connections include `bundleEdges` array) |
569
+ | `selection-change` | `{ nodes, edges }` | Triggered when selection set changes; `nodes`/`edges` are arrays of selected node and connection objects |
570
+ | `data-change` | `{ nodes, edges, summary }` | When `watchDataChanges` is enabled, triggered after data change debounce (300ms) |
571
+ | `edge-create` | `edge` | Triggered after node handle drag connects two nodes |
572
+ | `edge-remove` | `edges` | Triggered after deleting connections (includes cascaded deletions due to node deletion) |
573
+ | `edge-update` | `edges` | Triggered after `updateEdges()` modifies connections |
574
+ | `node-drag-start` | `node` | Node drag starts; also triggered when dragging multi-select set, payload is the node being held |
575
+ | `node-drag-end` | — | Node drag ends |
576
+ | `node-resize-start` | `node` | Resize starts |
577
+ | `node-resize-end` | `node \| null` | Resize ends |
578
+
579
+ ### selection-change Event Details
580
+
581
+ ```javascript
582
+ // Supports multiple selection methods
583
+ // 1. Ctrl+click multi-select
584
+ // 2. Ctrl+left-drag box select
585
+ // 3. Normal click single select
586
+ // 4. Click blank to clear
587
+
588
+ @selection-change="(sel) => {
589
+ console.log('Selected nodes:', sel.nodes.map(n => n.id));
590
+ console.log('Selected connections:', sel.edges.map(e => e.id));
591
+ }"
592
+ ```
225
593
 
226
- ```js
227
- const topoRef = ref(null);
594
+ ---
228
595
 
229
- // --- data methods ---
230
- topoRef.value.resetDataBaseline();
231
- const { nodes, edges } = topoRef.value.getData();
232
- topoRef.value.setData({ nodes: nextNodes }); // full swap: update your nodes / edges first, then clear in-component bookkeeping
233
- const removed = topoRef.value.removeSelected();
234
- topoRef.value.addNodes([{ label: "New node", x: 0, y: 0 }]);
235
- topoRef.value.addEdges([{ from: "a", to: "b" }]);
236
- topoRef.value.updateNodes([{ id: "node-1", label: "Renamed", width: 120 }]);
237
- topoRef.value.updateEdges([{ id: "edge-1", speed: 2 }]);
238
-
239
- // --- coordinate conversion ---
240
- // 1) add a node where the user clicked
241
- function onContextMenu(e) {
242
- const p = topoRef.value.clientToSvg(e); // event object accepted
243
- topoRef.value.addNodes([{ label: "New node", x: p.x, y: p.y }]);
244
- }
245
- // 2) position a DOM overlay above a node
246
- const node = topoRef.value.getData().nodes[0];
247
- const { x, y } = topoRef.value.svgToClient(node.x, node.y);
248
- menu.style.left = `${x}px`;
249
- menu.style.top = `${y}px`;
250
- ```
596
+ ## Interactions
597
+
598
+ | Operation | Gesture | Description |
599
+ | ---------------------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
600
+ | Select node/connection | Left-click | Repeated clicking unselects; clicking blank clears all |
601
+ | Multi-select (point) | Ctrl (macOS ⌘) + click | Add/remove nodes/connections from selection set, supports mixed node and connection multi-select |
602
+ | Multi-select (box) | Ctrl (macOS ⌘) + left-drag | Draw rectangular selection box on blank canvas, **nodes intersecting the box** are added to current selection (union semantics; only nodes participate in box select) |
603
+ | Drag single node | Hold and drag anywhere on node area | Requires `editable` enabled and `config.nodeDraggable !== false`; dragging unselected node will first select it |
604
+ | Drag multiple nodes | Drag any **selected** node | Selection set moves together, all nodes displace equally; selection state retained after release |
605
+ | Canvas pan (infinite) | Hold left-drag on blank; or hold **middle-click** anywhere | Panning has no boundaries; content and grid move together; does not change selection state |
606
+ | Zoom | Scroll wheel | Zoom centered on mouse position (0.2x–5x) |
607
+ | Resize node | After selecting **single** node, drag 8 control points | Requires `editable` and `config.nodeResizable !== false` |
608
+ | Create connection | Drag from node handle to target node | Requires `config.showNodeHandles: true` |
609
+
610
+ ### Layer Management Keyboard Shortcuts (requires `enableZOrder`)
611
+
612
+ | Shortcut | Operation |
613
+ | ---------------------- | ------------------- |
614
+ | `Ctrl/Cmd + Shift + ↑` | Move up one layer |
615
+ | `Ctrl/Cmd + Shift + ↓` | Move down one layer |
616
+ | `Ctrl/Cmd + Shift + ←` | Move to back |
617
+ | `Ctrl/Cmd + Shift + →` | Move to front |
618
+
619
+ ### Interaction Priority Notes
620
+
621
+ - **Node and connection overlap**: Click/drag acts on **node**; connections normally clickable where not occluded—nodes always selectable and draggable in dense graphics
622
+ - **Click vs drag distinction**: Left-click on blank distinguishes by small threshold (pan 4px / box select 3px / node drag 3px): below threshold treated as click (clear or toggle selection), above threshold enters drag mode
251
623
 
252
- `data-change` cadence: the baseline only moves when you call `resetDataBaseline()`; every change between resets is reported against the same baseline, and writing the returned data back into the component does not cause trigger loops.
624
+ ---
253
625
 
254
- **Data sync in short**: `props.nodes` / `props.edges` are deep-synced — array replacement or in-place edits both flow in; in-component edits (drag / resize / add / update / remove) are published via `update:nodes`, `edge-create`, `edge-update` and `edge-remove`. Writing the component's own output back does not cause loops or rebuild churn. To load a whole new dataset, update your `nodes` / `edges` first, then call `setData()` to clear any in-component leftovers.
626
+ ## Supplementary Notes
627
+
628
+ ### Data Synchronization Mechanism
629
+
630
+ `props.nodes` / `props.edges` use deep synchronization—parent replacing entire array or modifying fields in-place will update component internally; component's drag/resize/add/delete/update will also emit via `update:nodes`, `edge-create`, `edge-update`, `edge-remove` in real-time. Parent writing component-emitted data back without modification won't cause loops or duplicate reconstruction.
631
+
632
+ When loading a complete new dataset, first update your `nodes` / `edges`, then call `setData()` to clean up component internal residual state.
633
+
634
+ ### TypeScript Support
635
+
636
+ ```typescript
637
+ import type { TopologyInstance } from "vue3-network-graph";
638
+
639
+ const topoRef = ref<TopologyInstance | null>(null);
640
+
641
+ // Type-safe method calls
642
+ topoRef.value?.getData();
643
+ topoRef.value?.clientToSvg(event);
644
+ ```
255
645
 
256
- > TypeScript users: `import type { TopologyInstance } from "vue3-network-graph"` gives you a component instance type with all the exposed methods (`getData` / `clientToSvg` / …).
646
+ ### Coordinate System Notes
257
647
 
258
- ### Coordinates & Conversion
648
+ - Component node coordinates (`node.x` / `node.y`) are in **SVG user coordinate system**
649
+ - Canvas zoom and pan are implemented via `viewBox`, so conversion between this coordinate system and screen pixels varies with view state
650
+ - `clientToSvg` uses matrix transformation, **automatically accounting for current zoom and pan**, returning coordinates identical to `node.x` / `node.y`
651
+ - `svgToClient` is its inverse: input node coordinates, output screen `clientX` / `clientY`, suitable for DOM floating layers
259
652
 
260
- - Node coordinates (`node.x` / `node.y`) live in the **SVG user coordinate system**; zoom & pan are implemented through the `viewBox`, so the mapping to screen pixels changes with the view state.
261
- - `clientToSvg` applies `svg.getScreenCTM().inverse()` — **zoom and pan are folded in automatically**, and the result is directly comparable to `node.x` / `node.y`. It is the recommended way to align mouse positions with graph content; no manual math needed.
262
- - `svgToClient` is the inverse: feed node coordinates, get screen `clientX` / `clientY` — ideal for DOM overlays.
263
- - All internal coordinate math (dragging, marquee, resizing, connection preview) converges on the same conversion function, so the public API behaves exactly like the built-in interactions.
653
+ ---
264
654
 
265
655
  ## License
266
656