vue3-network-graph 0.1.1 → 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,10 @@ 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**: viewport culling (only on-screen elements render) + decorative effects auto-degrade above size budgets + edge geometry caching; nodes take hit priority over dense overlapping edges — thousand-node graphs stay smooth to pan and drag
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
14
  - **Coordinates**: `clientToSvg` (mouse → SVG) and `svgToClient` (SVG → screen), callable from outside via template ref
15
15
  - **Appearance config**: canvas background radial gradient (inner/outer colors, custom stops), grid (color / step / opacity) and selection colors — all through `config`
16
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
@@ -39,19 +39,36 @@ app.use(Vue3NetworkGraph); // then <Topology /> is available everywhere
39
39
  ```vue
40
40
  <script setup>
41
41
  import { ref } from "vue";
42
- import {
43
- Topology,
44
- initialNodes,
45
- initialEdges,
46
- initialGroups,
47
- } from "vue3-network-graph";
42
+ import { Topology } from "vue3-network-graph";
48
43
  import "vue3-network-graph/style.css";
49
44
 
50
- const myNodes = ref(initialNodes);
51
- const myEdges = ref(initialEdges);
52
- 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
+ ]);
53
70
  const lineMode = ref("straight"); // straight | polyline | curve
54
- const viewMode = ref("2d"); // 2d | 3d
71
+ const viewMode = ref("2d"); // 2d | 3d
55
72
  const topoRef = ref(null);
56
73
  </script>
57
74
 
@@ -64,7 +81,12 @@ const topoRef = ref(null);
64
81
  v-model:view-mode="viewMode"
65
82
  :edges="myEdges"
66
83
  :groups="myGroups"
67
- :config="{ showGrid: false, nodeDraggable: true, nodeResizable: true, enableZoom: true }"
84
+ :config="{
85
+ showGrid: false,
86
+ nodeDraggable: true,
87
+ nodeResizable: true,
88
+ enableZoom: true,
89
+ }"
68
90
  @node-click="(n) => console.log(n)"
69
91
  @edge-select="(e) => console.log(e)"
70
92
  @selection-change="(sel) => console.log(sel.nodes, sel.edges)"
@@ -79,140 +101,127 @@ const topoRef = ref(null);
79
101
 
80
102
  ## Interaction Reference (mouse / keyboard)
81
103
 
82
- | Action | Gesture | Notes |
83
- |---|---|---|
84
- | Select a node / edge | Left click | Clicking an already-selected item deselects it; clicking blank canvas clears the whole selection |
85
- | Multi-select (click) | Ctrl (⌘ on macOS) + click | Adds/removes nodes and edges to/from the selection — mixed node+edge selections supported |
86
- | 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) |
87
- | 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 |
88
- | Drag many nodes | Drag any **already-selected** node | The whole selection moves together — identical deltas; the selection survives the drag |
89
- | Pan (infinite) | Left-drag on blank canvas, or middle-drag anywhere | No bounds at all; content and grid move together; selection untouched |
90
- | Zoom | Wheel | Zooms around the mouse position (0.2x–5x) |
91
- | Resize a node | Drag one of the 8 handles on a single-selected node | Requires `editable`, `config.nodeResizable !== false` |
92
- | 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` |
93
115
 
94
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.
95
117
 
96
118
  ## Performance with large graphs
97
119
 
98
- The component ships automatic, large-graph-oriented rendering and cost controls. At the bundled demo scale (≤128 edges) the look is unchanged.
99
-
100
- ### Viewport culling (automatic)
101
-
102
- Only nodes/edges intersecting the current viewport (plus a small margin) are rendered — off-screen elements never enter the DOM, and the set updates as you pan/zoom. Per-frame cost drops from "whole graph" to "what is on screen". All interactions (marquee, hit tests, dragging, selection) run on the underlying data and are unaffected.
120
+ Large-graph performance optimizations ship on by default — no configuration needed. Decorative effects (the most expensive SVG features) switch off above size budgets:
103
121
 
104
122
  ### Decorative effects auto-degrade (overridable)
105
123
 
106
124
  Flow/particle animations, glow filters and breathing rings are the most expensive SVG features; they switch off above size budgets:
107
125
 
108
- | Effect | Auto-off threshold (default) | Override |
109
- |---|---|---|
110
- | Flow + particle animation | edges > 200 | `motionFx: true/false` or `fxMotionMaxEdges: n` |
111
- | Edge glow filter | edges > 500 | `glowFx: true/false` or `fxGlowMaxEdges: n` |
112
- | Node breathing ring | nodes > 300 | `breatheFx: true/false` or `fxBreatheMaxNodes: n` |
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` |
113
131
 
114
132
  - Master switch `config.fx`: `false` = everything off (cheapest) / `true` = everything on / unset = automatic; per-feature overrides win over the master switch.
115
133
  - Typical use: a "performance mode" toggle = `config.fx = false`.
116
134
 
117
135
  ### Hit priority in dense graphs
118
136
 
119
- The edge hit layer sits *below* the node layer: 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.
120
-
121
- ### Benchmark tooling (`perf/`)
122
-
123
- ```bash
124
- npm run dev # open http://localhost:5173/perf/stress.html?nodes=800&edges=1100
125
- node perf/bench.mjs --label=baseline # headless-Chrome benchmark: idle / pan / node-drag / zoom
126
- ```
127
-
128
- - `perf/stress.html`: parameterized stress canvas (`?nodes=800&edges=1100&fx=on|off`) with a live HUD (rendered nodes, element count, fps).
129
- - `perf/bench.mjs`: CDP-driven benchmark producing JSON (frame intervals, longtasks, CPU metrics), comparable with `perf/results-*.json`.
130
- - 800/1100 reference: first frame under 1s (measured 0.3–0.5s), idle 60fps, worst pan/drag frame ≈0.1s (before optimization: first frame 23.6s, worst pan frame 18.0s, initial DOM elements 26,002 → ~3,000) — measure on your own machine for exact figures.
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.
131
138
 
132
139
  ## Props
133
140
 
134
- | Prop | Type | Default | Description |
135
- |---|---|---|---|
136
- | `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 |
137
- | `edges` | `Array` | `[]` | `id` `from` `to` `speed` `fromAnchor` `toAnchor` (`center`/`edge` boundary intersection) `fromText` `centerText` `toText` `endMarker` (`none`/`arrow`/`dot`) `fontSize` `fontColor` |
138
- | `groups` | `Array` | `[]` | Dashed group frames: `id` `label` `color` `nodeIds` `padding` `rotation` |
139
- | `lineMode` | `String` | `"curve"` | `straight` / `polyline` / `curve` (`v-model:line-mode` supported) |
140
- | `viewMode` | `String` | `"2d"` | `2d` / `3d` (2.5D card style, `v-model:view-mode` supported) |
141
- | `editable` | `Boolean` | `false` | Master switch for editing: enables node dragging and resizing (pan / marquee are not gated by it — control them via `config`) |
142
- | `width` / `height` | `Number` | container size | Base canvas size |
143
- | `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 |
144
151
 
145
- > `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`).
146
153
 
147
154
  ### config Options
148
155
 
149
- | Option | Type | Default | Description |
150
- |---|---|---|---|
151
- | `selectedBorderColor` | `String` | `#fbbf24` | Selected node border color |
152
- | `selectedLineColor` | `String` | `#fbbf24` | Selected edge color |
153
- | `nodeDraggable` | `Boolean` | `true` | Node dragging (requires `editable`) |
154
- | `nodeResizable` | `Boolean` | `true` | Drag-handle resizing (requires `editable`; 4 corner + 4 edge handles on single selection) |
155
- | `enableZoom` | `Boolean` | `true` | Wheel zoom |
156
- | `enablePan` | `Boolean` | `true` | **Canvas panning** (blank left-drag / middle-drag) |
157
- | `enableMarquee` | `Boolean` | `true` | **Ctrl + left-drag marquee selection** |
158
- | `showGrid` | `Boolean` | `true` | Grid background (set `false` to hide) |
159
- | `gridColor` | `String` | `#1a2240` | Grid line color |
160
- | `gridStep` | `Number` | `40` | Grid cell size in px at 1x zoom (scales with zoom) |
161
- | `gridOpacity` | `Number` | `0.5` | Grid overlay opacity (0–1) |
162
- | `radialGradient` | `Object` | see notes | Canvas background radial gradient: `{ startColor, endColor }` or `{ cx, cy, r, stops: [...] }`; default `#0f1729 → #060a14` |
163
- | `showCenterPoint` | `Boolean` | `false` | Canvas center crosshair |
164
- | `showEdgeTextBg` | `Boolean` | `false` | Edge label plates |
165
- | `edgeTextBgColor` | `String` | `#0a0e1a` | Plate color |
166
- | `showNodeHandles` | `Boolean` | `false` | Node handles (four small circles for drag-to-connect) |
167
- | `showStatusDot` | `Boolean` | `true` | Status dot at each node's top-right corner (**shown by default**; set `false` to hide all) |
168
- | `watchDataChanges` | `Boolean` | `false` | In-component data change tracking (debounced 300ms → `data-change`) |
169
- | `fx` | `Boolean` | auto | Master switch for decorative effects: `false` = all off (cheapest) / `true` = all on / unset = automatic (see "Performance with large graphs") |
170
- | `motionFx` / `glowFx` / `breatheFx` | `Boolean` | auto | Per-feature overrides: flow+particles / edge glow / breathing rings |
171
- | `fxMotionMaxEdges` | `Number` | `200` | Edge-count threshold above which flow+particle animation turns off |
172
- | `fxGlowMaxEdges` | `Number` | `500` | Edge-count threshold above which edge glow turns off |
173
- | `fxBreatheMaxNodes` | `Number` | `300` | Node-count threshold above which breathing rings turn off |
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 |
174
183
 
175
184
  ## Events
176
185
 
177
- | Event | Payload | Description |
178
- |---|---|---|
179
- | `update:nodes` | `nodes` | Node data updated (`v-model:nodes`); keeps firing while dragging / resizing |
180
- | `update:lineMode` / `update:viewMode` | `string` | Mode changes (`v-model:*`) |
181
- | `node-click` | `node` | Node clicked |
182
- | `node-select` | `node\|null` | Single-selection change (use `selection-change` for multi) |
183
- | `edge-select` | `edge\|null` | Edge selection (merged bundles carry `bundleEdges`) |
184
- | `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** |
185
- | `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 |
186
- | `edge-create` | `edge` | Fired after dragging a node handle onto another node; the edge is already rendered temporarily — persist it here |
187
- | `edge-remove` | `edges` | Fired after `removeSelected()` removes edges; includes edges cascaded from deleted nodes |
188
- | `edge-update` | `edges` | Fired after `updateEdges()`; merge the payload back into your own array by id |
189
- | `node-drag-start` / `node-drag-end` | `node` / — | Drag lifecycle; also fired for group drags (payload = the grabbed node) |
190
- | `node-resize-start` / `node-resize-end` | `node` / `node\|null` | Resize gesture start / end (`update:nodes` keeps firing while resizing) |
191
-
192
- **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).
193
202
 
194
203
  Edge labels accept a plain string or `{ text, rotation, fontSize, color }`.
195
204
 
196
205
  ### Slots
197
206
 
198
- | Slot | Slot props | Description |
199
- |---|---|---|
207
+ | Slot | Slot props | Description |
208
+ | ------------ | --------------------------- | ------------------------------------------------------- |
200
209
  | `#node-icon` | `{ node, color, viewMode }` | Custom node icon content (replaces the built-in shapes) |
201
210
 
202
211
  ## Component Methods (via template ref)
203
212
 
204
- | Method | Description |
205
- |---|---|
206
- | `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 |
207
- | `resetDataBaseline()` | Re-arms data change tracking: snapshots the current data as the new baseline |
208
- | `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 |
209
- | `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 |
210
- | `addNodes(nodes)` | Append nodes: missing `id`s auto-generated, existing ids skipped; syncs via `update:nodes`; returns deep copies |
211
- | `addEdges(edges)` | Append edges: requires `from`/`to`, missing `id`s auto-generated, duplicates skipped; emits `edge-create`; returns deep copies |
212
- | `updateNodes(nodes)` | Patch nodes by id (shallow merge, `undefined` ignored); syncs via `update:nodes`; returns deep copies |
213
- | `updateEdges(edges)` | Patch edges by id; emits `edge-update`; returns deep copies |
214
- | `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 |
215
- | `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 |
216
225
 
217
226
  ```js
218
227
  const topoRef = ref(null);
@@ -220,7 +229,7 @@ const topoRef = ref(null);
220
229
  // --- data methods ---
221
230
  topoRef.value.resetDataBaseline();
222
231
  const { nodes, edges } = topoRef.value.getData();
223
- topoRef.value.setData({ nodes: nextNodes }); // full swap: update your nodes / edges first, then clear in-component bookkeeping
232
+ topoRef.value.setData({ nodes: nextNodes }); // full swap: update your nodes / edges first, then clear in-component bookkeeping
224
233
  const removed = topoRef.value.removeSelected();
225
234
  topoRef.value.addNodes([{ label: "New node", x: 0, y: 0 }]);
226
235
  topoRef.value.addEdges([{ from: "a", to: "b" }]);