vue3-network-graph 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -7,10 +7,13 @@ A network topology component built with **Vue 3 + SVG** — no third-party chart
7
7
  - **Line modes**: `straight` / `polyline` / `curve` via the `lineMode` prop
8
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
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 (`MAX_BUNDLE`) 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
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
11
  - **Nodes**: 2D / 2.5D icons, breathing status ring, text nodes, custom icon slot `#node-icon`
12
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
13
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
14
17
  - **Extras**: group dashed frames, grid background, 10 node states
15
18
 
16
19
  ## Install
@@ -36,19 +39,36 @@ app.use(Vue3NetworkGraph); // then <Topology /> is available everywhere
36
39
  ```vue
37
40
  <script setup>
38
41
  import { ref } from "vue";
39
- import {
40
- Topology,
41
- initialNodes,
42
- initialEdges,
43
- initialGroups,
44
- } from "vue3-network-graph";
42
+ import { Topology } from "vue3-network-graph";
45
43
  import "vue3-network-graph/style.css";
46
44
 
47
- const myNodes = ref(initialNodes);
48
- const myEdges = ref(initialEdges);
49
- const myGroups = ref(initialGroups);
45
+ /* Nodes / edges (/ groups) are plain arrays — bring your own data */
46
+ const myNodes = ref([
47
+ { id: "core", label: "Core", type: "core", state: "normal", x: 0, y: 0 },
48
+ {
49
+ id: "web-1",
50
+ label: "Web-1",
51
+ type: "server",
52
+ state: "normal",
53
+ x: 160,
54
+ y: -80,
55
+ },
56
+ { id: "db-1", label: "DB-1", type: "database", state: "idle", x: 160, y: 80 },
57
+ ]);
58
+ const myEdges = ref([
59
+ { id: "e1", from: "core", to: "web-1" },
60
+ { id: "e2", from: "core", to: "db-1", centerText: "query" },
61
+ ]);
62
+ const myGroups = ref([
63
+ {
64
+ id: "g1",
65
+ label: "App layer",
66
+ color: "#409eff",
67
+ nodeIds: ["web-1", "db-1"],
68
+ },
69
+ ]);
50
70
  const lineMode = ref("straight"); // straight | polyline | curve
51
- const viewMode = ref("2d"); // 2d | 3d
71
+ const viewMode = ref("2d"); // 2d | 3d
52
72
  const topoRef = ref(null);
53
73
  </script>
54
74
 
@@ -61,7 +81,12 @@ const topoRef = ref(null);
61
81
  v-model:view-mode="viewMode"
62
82
  :edges="myEdges"
63
83
  :groups="myGroups"
64
- :config="{ showGrid: false, nodeDraggable: true, nodeResizable: true, enableZoom: true }"
84
+ :config="{
85
+ showGrid: false,
86
+ nodeDraggable: true,
87
+ nodeResizable: true,
88
+ enableZoom: true,
89
+ }"
65
90
  @node-click="(n) => console.log(n)"
66
91
  @edge-select="(e) => console.log(e)"
67
92
  @selection-change="(sel) => console.log(sel.nodes, sel.edges)"
@@ -76,94 +101,127 @@ const topoRef = ref(null);
76
101
 
77
102
  ## Interaction Reference (mouse / keyboard)
78
103
 
79
- | Action | Gesture | Notes |
80
- |---|---|---|
81
- | Select a node / edge | Left click | Clicking an already-selected item deselects it; clicking blank canvas clears the whole selection |
82
- | Multi-select (click) | Ctrl (⌘ on macOS) + click | Adds/removes nodes and edges to/from the selection — mixed node+edge selections supported |
83
- | 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) |
84
- | Drag one node | Drag a node | Requires `editable` and `config.nodeDraggable !== false`; dragging an unselected node selects it first |
85
- | Drag many nodes | Drag any **already-selected** node | The whole selection moves together — identical deltas; the selection survives the drag |
86
- | Pan (infinite) | Left-drag on blank canvas, or middle-drag anywhere | No bounds at all; content and grid move together; selection untouched |
87
- | Zoom | Wheel | Zooms around the mouse position (0.2x–5x) |
88
- | Resize a node | Drag one of the 8 handles on a single-selected node | Requires `editable`, `config.nodeResizable !== false` |
89
- | Create an edge | Drag a node handle onto another node | Requires `config.showNodeHandles: true` |
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)
90
123
 
91
- > 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.
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.
92
138
 
93
139
  ## Props
94
140
 
95
- | Prop | Type | Default | Description |
96
- |---|---|---|---|
97
- | `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 |
98
- | `edges` | `Array` | `[]` | `id` `from` `to` `speed` `fromAnchor` `toAnchor` (`center`/`edge` boundary intersection) `fromText` `centerText` `toText` `endMarker` (`none`/`arrow`/`dot`) `fontSize` `fontColor` |
99
- | `groups` | `Array` | `[]` | Dashed group frames: `id` `label` `color` `nodeIds` `padding` `rotation` |
100
- | `lineMode` | `String` | `"curve"` | `straight` / `polyline` / `curve` (`v-model:line-mode` supported) |
101
- | `viewMode` | `String` | `"2d"` | `2d` / `3d` (2.5D card style, `v-model:view-mode` supported) |
102
- | `editable` | `Boolean` | `false` | Master switch for editing: enables node dragging and resizing (pan / marquee are not gated by it — control them via `config`) |
103
- | `width` / `height` | `Number` | container size | Base canvas size |
104
- | `config` | `Object` | `{}` | Interaction & appearance options — see below |
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 |
105
151
 
106
- > `nodes` / `edges` / `groups` all default to empty arrays (blank canvas). The generic demo datasets are exported as `initialNodes` / `initialEdges` / `initialGroups`.
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`).
107
153
 
108
154
  ### config Options
109
155
 
110
- | Option | Type | Default | Description |
111
- |---|---|---|---|
112
- | `selectedBorderColor` | `String` | `#fbbf24` | Selected node border color |
113
- | `selectedLineColor` | `String` | `#fbbf24` | Selected edge color |
114
- | `nodeDraggable` | `Boolean` | `true` | Node dragging (requires `editable`) |
115
- | `nodeResizable` | `Boolean` | `true` | Drag-handle resizing (requires `editable`; 4 corner + 4 edge handles on single selection) |
116
- | `enableZoom` | `Boolean` | `true` | Wheel zoom |
117
- | `enablePan` | `Boolean` | `true` | **Canvas panning** (blank left-drag / middle-drag) |
118
- | `enableMarquee` | `Boolean` | `true` | **Ctrl + left-drag marquee selection** |
119
- | `showGrid` | `Boolean` | `true` | Grid background (set `false` to hide) |
120
- | `gridColor` | `String` | `#1a2240` | Grid line color |
121
- | `showCenterPoint` | `Boolean` | `false` | Canvas center crosshair |
122
- | `showEdgeTextBg` | `Boolean` | `false` | Edge label plates |
123
- | `edgeTextBgColor` | `String` | `#0a0e1a` | Plate color |
124
- | `showNodeHandles` | `Boolean` | `false` | Node handles (four small circles for drag-to-connect) |
125
- | `watchDataChanges` | `Boolean` | `false` | In-component data change tracking (debounced 300ms → `data-change`) |
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 |
126
183
 
127
184
  ## Events
128
185
 
129
- | Event | Payload | Description |
130
- |---|---|---|
131
- | `update:nodes` | `nodes` | Node data updated (`v-model:nodes`); keeps firing while dragging / resizing |
132
- | `update:lineMode` / `update:viewMode` | `string` | Mode changes (`v-model:*`) |
133
- | `node-click` | `node` | Node clicked |
134
- | `node-select` | `node\|null` | Single-selection change (use `selection-change` for multi) |
135
- | `edge-select` | `edge\|null` | Edge selection (merged bundles carry `bundleEdges`) |
136
- | `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** |
137
- | `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 |
138
- | `edge-create` | `edge` | Fired after dragging a node handle onto another node; the edge is already rendered temporarily — persist it here |
139
- | `edge-remove` | `edges` | Fired after `removeSelected()` removes edges; includes edges cascaded from deleted nodes |
140
- | `edge-update` | `edges` | Fired after `updateEdges()`; merge the payload back into your own array by id |
141
- | `node-drag-start` / `node-drag-end` | `node` / — | Drag lifecycle; also fired for group drags (payload = the grabbed node) |
142
- | `node-resize-start` / `node-resize-end` | `node` / `node\|null` | Resize gesture start / end (`update:nodes` keeps firing while resizing) |
143
-
144
- **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.
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).
145
202
 
146
203
  Edge labels accept a plain string or `{ text, rotation, fontSize, color }`.
147
204
 
148
205
  ### Slots
149
206
 
150
- | Slot | Slot props | Description |
151
- |---|---|---|
207
+ | Slot | Slot props | Description |
208
+ | ------------ | --------------------------- | ------------------------------------------------------- |
152
209
  | `#node-icon` | `{ node, color, viewMode }` | Custom node icon content (replaces the built-in shapes) |
153
210
 
154
211
  ## Component Methods (via template ref)
155
212
 
156
- | Method | Description |
157
- |---|---|
158
- | `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 |
159
- | `resetDataBaseline()` | Re-arms data change tracking: snapshots the current data as the new baseline |
160
- | `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 |
161
- | `addNodes(nodes)` | Append nodes: missing `id`s auto-generated, existing ids skipped; syncs via `update:nodes`; returns deep copies |
162
- | `addEdges(edges)` | Append edges: requires `from`/`to`, missing `id`s auto-generated, duplicates skipped; emits `edge-create`; returns deep copies |
163
- | `updateNodes(nodes)` | Patch nodes by id (shallow merge, `undefined` ignored); syncs via `update:nodes`; returns deep copies |
164
- | `updateEdges(edges)` | Patch edges by id; emits `edge-update`; returns deep copies |
165
- | `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 |
166
- | `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 |
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 |
167
225
 
168
226
  ```js
169
227
  const topoRef = ref(null);
@@ -171,6 +229,7 @@ const topoRef = ref(null);
171
229
  // --- data methods ---
172
230
  topoRef.value.resetDataBaseline();
173
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
174
233
  const removed = topoRef.value.removeSelected();
175
234
  topoRef.value.addNodes([{ label: "New node", x: 0, y: 0 }]);
176
235
  topoRef.value.addEdges([{ from: "a", to: "b" }]);
@@ -192,6 +251,8 @@ menu.style.top = `${y}px`;
192
251
 
193
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.
194
253
 
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.
255
+
195
256
  > TypeScript users: `import type { TopologyInstance } from "vue3-network-graph"` gives you a component instance type with all the exposed methods (`getData` / `clientToSvg` / …).
196
257
 
197
258
  ### Coordinates & Conversion