@neo4j-nvl/base 1.2.2 → 2.0.0-2b04269b

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +8 -0
  3. package/dist/base.mjs +39758 -2
  4. package/dist/types/index.d.ts +21 -20
  5. package/dist/types/layouts/animatedlayout/AnimatedLayout.d.ts +2 -2
  6. package/dist/types/layouts/d3forcelayout/constants.d.ts +0 -1
  7. package/dist/types/layouts/d3forcelayout/d3ForceLayout.d.ts +3 -3
  8. package/dist/types/layouts/forcedirectedlayout/PhysLayout.d.ts +275 -0
  9. package/dist/types/layouts/forcedirectedlayout/clustering/ClusterByMerger.d.ts +62 -0
  10. package/dist/types/layouts/forcedirectedlayout/clustering/SolarMerger.d.ts +56 -0
  11. package/dist/types/layouts/forcedirectedlayout/clustering/clustering-utils.d.ts +143 -0
  12. package/dist/types/layouts/forcedirectedlayout/{physlayout/solarmerger → clustering}/types.d.ts +11 -1
  13. package/dist/types/layouts/forcedirectedlayout/shaders/multilevel-fragment.d.ts +2 -0
  14. package/dist/types/layouts/forcedirectedlayout/shaders/multilevel-repulsive-fragment.d.ts +2 -0
  15. package/dist/types/layouts/forcedirectedlayout/shaders/multilevel-update-fragment.d.ts +2 -0
  16. package/dist/types/layouts/forcedirectedlayout/shaders/sim-vertex.d.ts +2 -0
  17. package/dist/types/layouts/freeLayout/FreeLayout.d.ts +2 -4
  18. package/dist/types/layouts/gridLayout/GridLayout.d.ts +2 -6
  19. package/dist/types/layouts/hierarchicallayout/HierarchicalLayout.d.ts +5 -0
  20. package/dist/types/modules/ExternalCallbackHandler.d.ts +4 -10
  21. package/dist/types/modules/NvlController.d.ts +87 -7
  22. package/dist/types/modules/Shader.d.ts +1 -1
  23. package/dist/types/modules/dataset.d.ts +4 -2
  24. package/dist/types/modules/state/types.d.ts +114 -23
  25. package/dist/types/renderers/ClusterOverlay.d.ts +73 -0
  26. package/dist/types/renderers/ClusterOverlay.test.d.ts +1 -0
  27. package/dist/types/renderers/domrenderer/canvasrenderer/CanvasRenderer.d.ts +1 -1
  28. package/dist/types/renderers/domrenderer/shared/ImageCache.d.ts +1 -0
  29. package/dist/types/renderers/domrenderer/shared/types.d.ts +1 -2
  30. package/dist/types/renderers/webglrenderer/Controller.d.ts +27 -6
  31. package/dist/types/renderers/webglrenderer/IconLayerRegistry.d.ts +14 -0
  32. package/dist/types/renderers/webglrenderer/IconLayerRegistry.test.d.ts +1 -0
  33. package/dist/types/renderers/webglrenderer/Renderer.d.ts +43 -3
  34. package/dist/types/renderers/webglrenderer/node-animation-fragment.d.ts +1 -1
  35. package/dist/types/renderers/webglrenderer/node-animation-vertex.d.ts +1 -1
  36. package/dist/types/renderers/webglrenderer/node-fragment-point.d.ts +1 -1
  37. package/dist/types/renderers/webglrenderer/node-vertex-point.d.ts +1 -1
  38. package/dist/types/renderers/webglrenderer/rel-fragment-line.d.ts +1 -1
  39. package/dist/types/renderers/webglrenderer/rel-glsl-utils.d.ts +1 -0
  40. package/dist/types/renderers/webglrenderer/rel-vertex-arrow.d.ts +2 -0
  41. package/dist/types/renderers/webglrenderer/rel-vertex-line.d.ts +1 -1
  42. package/dist/types/renderers/webglrenderer/viewport-box-fragment.d.ts +1 -1
  43. package/dist/types/renderers/webglrenderer/viewport-box-vertex.d.ts +1 -1
  44. package/dist/types/types/graph-element.d.ts +9 -1
  45. package/dist/types/types/nvl-window-functions.d.ts +2 -2
  46. package/dist/types/utils/canvasManagement.d.ts +7 -1
  47. package/dist/types/utils/clusterGeometry.d.ts +14 -0
  48. package/dist/types/utils/clusterGeometry.test.d.ts +1 -0
  49. package/dist/types/utils/clusterHitRegions.d.ts +42 -0
  50. package/dist/types/utils/clusterHitRegions.test.d.ts +1 -0
  51. package/dist/types/utils/constants.d.ts +6 -0
  52. package/dist/types/utils/geometry.d.ts +44 -1
  53. package/dist/types/utils/{hittest.d.ts → hitTest.d.ts} +30 -4
  54. package/dist/types/utils/hitTest.test.d.ts +1 -0
  55. package/dist/types/utils/jsDriverResultTransformer.d.ts +11 -9
  56. package/dist/types/utils/layoutSeeding.d.ts +7 -0
  57. package/dist/types/utils/layoutSeeding.test.d.ts +1 -0
  58. package/dist/types/utils/webWorkerUtils.d.ts +1 -1
  59. package/dist/types/utils/zoomFunctions.d.ts +9 -2
  60. package/package.json +13 -15
  61. package/skills/neo4j-nvl-skill/README.md +39 -0
  62. package/skills/neo4j-nvl-skill/SKILL.md +456 -0
  63. package/skills/neo4j-nvl-skill/references/api-surface.md +596 -0
  64. package/skills/neo4j-nvl-skill/references/troubleshooting.md +317 -0
  65. package/dist/base.mjs.LICENSE.txt +0 -21
  66. package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +0 -22
  67. package/dist/types/layouts/forcedirectedlayout/cosebilkentlayout/CoseBilkentLayout.d.ts +0 -33
  68. package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +0 -174
  69. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +0 -2
  70. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +0 -2
  71. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-update-fragment.d.ts +0 -2
  72. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/sim-vertex.d.ts +0 -2
  73. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/workaround-fragment.d.ts +0 -2
  74. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +0 -21
  75. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/solar-placer.d.ts +0 -2
  76. /package/dist/types/layouts/forcedirectedlayout/{physlayout/PhysLayout.test.d.ts → PhysLayout.test.d.ts} +0 -0
  77. /package/dist/types/layouts/forcedirectedlayout/{physlayout/solarmerger/SolarMerger.bench.d.ts → clustering/ClusterByMerger.test.d.ts} +0 -0
  78. /package/dist/types/layouts/forcedirectedlayout/{physlayout/solarmerger/SolarMerger.test.d.ts → clustering/SolarMerger.bench.d.ts} +0 -0
  79. /package/dist/types/layouts/forcedirectedlayout/{physlayout/solarmerger/solar-placer.test.d.ts → clustering/SolarMerger.test.d.ts} +0 -0
  80. /package/dist/types/{utils/hittest.test.d.ts → layouts/forcedirectedlayout/clustering/clustering-utils.test.d.ts} +0 -0
  81. /package/dist/types/layouts/forcedirectedlayout/{physlayout/glwrapper.d.ts → glwrapper.d.ts} +0 -0
@@ -0,0 +1,456 @@
1
+ ---
2
+ name: neo4j-nvl-skill
3
+ description: Neo4j Visualization Library (NVL) — framework-agnostic graph rendering for the browser.
4
+ Covers @neo4j-nvl/base (NVL class, nodes/relationships, Canvas vs WebGL renderer),
5
+ @neo4j-nvl/interaction-handlers (ZoomInteraction, PanInteraction, DragNodeInteraction, ClickInteraction,
6
+ HoverInteraction, BoxSelectInteraction, LassoInteraction, KeyboardInteraction), and @neo4j-nvl/react
7
+ (InteractiveNvlWrapper, BasicNvlWrapper, StaticPictureWrapper). Use when rendering a Neo4j graph in
8
+ a browser, feeding driver results through nvlResultTransformer, choosing Canvas vs WebGL,
9
+ wiring node/relationship click/hover/drag handlers, or embedding NVL in React, Vite,
10
+ or vanilla JS apps.
11
+ Does NOT handle Cypher query authoring — use neo4j-cypher-skill.
12
+ Does NOT handle driver lifecycle, sessions, or executeQuery setup — use neo4j-driver-javascript-skill.
13
+ Does NOT handle GraphVisualization/Needle default embed — use @neo4j-ndl/react.
14
+ compatibility: "@neo4j-nvl packages 2.0.x; React 19 for @neo4j-nvl/react; modern browsers with Canvas2D + WebGL2"
15
+ version: 2.0.0
16
+ ---
17
+
18
+ > **Version note:** This skill documents the NVL version in `compatibility`. If the project's installed `@neo4j-nvl/base` is a different version and `node_modules/@neo4j-nvl/base/skills/neo4j-nvl-skill/SKILL.md` exists, read that copy instead.
19
+
20
+ ## When to Use
21
+ - Rendering a Neo4j graph in a browser (vanilla JS, React, Vite) with custom interactions, rendering, or data shapes
22
+ - Visualizing `driver.executeQuery` results as an interactive graph
23
+ - Wiring zoom, pan, drag, click, hover, lasso, or box-select interactions
24
+ - Embedding NVL inside an existing app and synchronizing graph state
25
+
26
+ ## When NOT to Use
27
+ - **Pre-styled embedded graph view with default behavior, no custom interactions** → `GraphVisualization` from `@neo4j-ndl/react` (Neo4j Needle / NDL design system) — wraps NVL with default Neo4j styling. See [Use NVL or the Needle Component?](#use-nvl-or-the-needle-component) below.
28
+ - **Python / Jupyter notebook graph visualization** → `neo4j/python-graph-visualization` (the Python port of NVL)
29
+ - **Writing/optimizing Cypher** → `neo4j-cypher-skill`
30
+ - **Driver setup / executeQuery / sessions** → `neo4j-driver-javascript-skill`
31
+ - **Server-side data fetching with no rendering** → `neo4j-driver-javascript-skill`
32
+ - **GDS algorithm execution** → `neo4j-gds-skill` or `neo4j-aura-graph-analytics-skill`
33
+ - **GraphQL API** → `neo4j-graphql-skill`
34
+
35
+ ---
36
+
37
+ ## Use NVL or the Needle Component?
38
+
39
+ | Need | Use |
40
+ |---|---|
41
+ | Embed a graph view with default Neo4j styling, no custom interactions or rendering | `GraphVisualization` from `@neo4j-ndl/react` (Neo4j Needle / NDL design system) — wraps NVL and accepts records shaped `{ id, labels, properties: { key: { stringified, type } } }` (`NeoNode`) |
42
+ | Custom interactions, custom rendering, non-standard data shapes, or framework-agnostic embedding | This skill — use NVL directly |
43
+
44
+ If the answer is the first row, install and use the Needle component instead of NVL — do not duplicate styling work.
45
+
46
+ ---
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ npm install @neo4j-nvl/base # core (required)
52
+ npm install @neo4j-nvl/interaction-handlers # standard interactions (optional, vanilla JS)
53
+ npm install @neo4j-nvl/react # React wrappers (optional)
54
+ ```
55
+
56
+ Peer requirements: **React 19** for `@neo4j-nvl/react`. The published peerDependency range still permits React 18, but mixing major versions is not recommended — target 19. `@neo4j-nvl/layout-workers` is a transitive dependency — never install directly. `neo4j-driver` is a peer of `@neo4j-nvl/base` only when using `nvlResultTransformer`.
57
+
58
+ Starter templates: https://github.com/neo4j-devtools/nvl-boilerplates — official per-framework scaffolds; prefer these over hand-rolled setups.
59
+
60
+ License: NVL ships under the **Neo4j Visualization Library License** — for use with Neo4j products only. Cannot be used against other graph backends.
61
+
62
+ ---
63
+
64
+ ## Pick the Right Paradigm
65
+
66
+ | Need | Use |
67
+ |---|---|
68
+ | React app, default interactions | `<InteractiveNvlWrapper>` from `@neo4j-nvl/react` |
69
+ | React app, custom interaction wiring | `<BasicNvlWrapper>` + own handlers via `ref` |
70
+ | Vanilla JS, standard interactions | `NVL` + `@neo4j-nvl/interaction-handlers` |
71
+ | Vanilla JS, fully custom event logic | `NVL` + `container.addEventListener` + `nvl.getHits()` |
72
+ | Static PNG/SVG image export | `<StaticPictureWrapper>` or `nvl.saveToFile()` / `nvl.saveToSvg()` |
73
+
74
+ ---
75
+
76
+ ## Pick the Right Renderer
77
+
78
+ | Renderer | Max nodes | Detail | Use case |
79
+ |---|---|---|---|
80
+ | `'canvas'` (default) | ~1,000 | Captions, icons, arrows, pixel-perfect hit-testing | Detail investigation, small graphs |
81
+ | `'webgl'` | 100,000+ | No captions; supports node icons and relationship arrowheads in 2.0 | Large-scale pattern exploration |
82
+
83
+ ```javascript
84
+ const nvl = new NVL(container, nodes, rels, { renderer: 'webgl' })
85
+ nvl.setRenderer('canvas') // swap at runtime
86
+ ```
87
+
88
+ NVL 2.0 requires **WebGL2** for the GPU renderer and force-directed physics engine. When GPU acceleration is unavailable, NVL can fall back to Canvas rendering and non-GPU layout implementations; use `disableWebGL: true` to explicitly avoid WebGL.
89
+
90
+ ---
91
+
92
+ ## Container Setup
93
+
94
+ The container must have an explicit `width` AND `height`. Missing height → container collapses to `0` → graph invisible. Most-reported NVL bug.
95
+
96
+ ```html
97
+ <!-- ❌ height defaults to 0; graph invisible -->
98
+ <div id="viz"></div>
99
+
100
+ <!-- ✅ explicit dimensions -->
101
+ <div id="viz" style="width: 100%; height: 600px;"></div>
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Vanilla — Base Library
107
+
108
+ ```javascript
109
+ import { NVL } from '@neo4j-nvl/base'
110
+
111
+ const container = document.getElementById('viz')
112
+ const nodes = [{ id: '1' }, { id: '2' }]
113
+ const relationships = [{ id: '12', from: '1', to: '2', type: 'KNOWS' }]
114
+
115
+ const nvl = new NVL(container, nodes, relationships)
116
+ ```
117
+
118
+ With options + callbacks:
119
+
120
+ ```javascript
121
+ import { NVL } from '@neo4j-nvl/base'
122
+
123
+ const options = {
124
+ initialZoom: 1.0,
125
+ minZoom: 0.1,
126
+ maxZoom: 8,
127
+ layout: 'forceDirected',
128
+ renderer: 'canvas',
129
+ styling: { defaultNodeColor: '#0e86d4', defaultRelationshipColor: '#888' }
130
+ }
131
+ const callbacks = {
132
+ onInitialization: () => console.log('NVL ready'),
133
+ onLayoutDone: () => nvl.fit([]),
134
+ onError: (err) => console.error('NVL error', err)
135
+ }
136
+
137
+ const nvl = new NVL(container, nodes, relationships, options, callbacks)
138
+
139
+ // On teardown — always:
140
+ nvl.destroy()
141
+ ```
142
+
143
+ `NVL` constructor signature: `new NVL(frame, nvlNodes?, nvlRels?, options?, callbacks?)`. All but `frame` are optional and default to empty.
144
+
145
+ ---
146
+
147
+ ## Vanilla — Interaction Handlers
148
+
149
+ Compose handlers onto an existing `NVL` instance. Each handler registers callbacks via `.updateCallback(name, fn)` and must be torn down with `.destroy()`.
150
+
151
+ ```javascript
152
+ import { NVL } from '@neo4j-nvl/base'
153
+ import {
154
+ ZoomInteraction, PanInteraction, DragNodeInteraction,
155
+ ClickInteraction, HoverInteraction, BoxSelectInteraction,
156
+ LassoInteraction, KeyboardInteraction
157
+ } from '@neo4j-nvl/interaction-handlers'
158
+
159
+ const nvl = new NVL(container, nodes, relationships)
160
+
161
+ const zoom = new ZoomInteraction(nvl)
162
+ const pan = new PanInteraction(nvl)
163
+ const drag = new DragNodeInteraction(nvl)
164
+ const click = new ClickInteraction(nvl, { selectOnClick: true })
165
+ const hover = new HoverInteraction(nvl, { drawShadowOnHover: true })
166
+
167
+ click.updateCallback('onNodeClick', (node, hits, evt) => console.log('node', node.id))
168
+ click.updateCallback('onRelationshipClick', (rel, hits, evt) => console.log('rel', rel.id))
169
+ click.updateCallback('onClusterClick', (cluster, hits, evt) => console.log('cluster', cluster.id))
170
+ click.updateCallback('onCanvasClick', (evt) => console.log('canvas'))
171
+ hover.updateCallback('onHover', (el, hits, evt) => el && console.log('over', el.id))
172
+ drag.updateCallback('onDragEnd', (nodes, evt) => savePositions(nodes))
173
+ zoom.updateCallback('onZoomAndPan', (level, panX, panY) => console.log(level, panX, panY))
174
+
175
+ // Teardown — destroy all handlers, then the NVL instance
176
+ function teardown() {
177
+ for (const h of [zoom, pan, drag, click, hover]) h.destroy()
178
+ nvl.destroy()
179
+ }
180
+ ```
181
+
182
+ Disable an event without removing the handler: `click.removeCallback('onCanvasClick')`. Passing `true` instead of a function enables the event with a no-op (useful for default selection behavior).
183
+
184
+ ---
185
+
186
+ ## React — InteractiveNvlWrapper
187
+
188
+ Pre-wires every interaction handler. Toggle events with `mouseEventCallbacks` (function = on + callback; `true` = on, no-op; `false`/omit = off).
189
+
190
+ ```tsx
191
+ import { InteractiveNvlWrapper } from '@neo4j-nvl/react'
192
+ import type { MouseEventCallbacks } from '@neo4j-nvl/react'
193
+ import { useRef } from 'react'
194
+ import type { NVL, NvlOptions } from '@neo4j-nvl/base'
195
+
196
+ export function GraphView({ nodes, rels }) {
197
+ const nvlRef = useRef<NVL>(null)
198
+
199
+ const nvlOptions: NvlOptions = { initialZoom: 1, renderer: 'canvas' }
200
+
201
+ const mouseEventCallbacks: MouseEventCallbacks = {
202
+ onNodeClick: (node, hits, evt) => console.log('node', node.id),
203
+ onRelationshipClick: (rel, hits, evt) => console.log('rel', rel.id),
204
+ onClusterClick: (cluster, hits, evt) => console.log('cluster', cluster.id),
205
+ onCanvasClick: (evt) => console.log('canvas'),
206
+ onHover: (el, hits, evt) => {
207
+ if (el) console.log('hover', el.id)
208
+ if (hits.clusters[0]) console.log('cluster hover', hits.clusters[0].data.id)
209
+ },
210
+ onDragEnd: (nodes, evt) => persist(nodes),
211
+ onZoomAndPan: true, // enable, no callback
212
+ onPan: true
213
+ }
214
+
215
+ return (
216
+ <div style={{ width: '100%', height: 600 }}>
217
+ <InteractiveNvlWrapper
218
+ ref={nvlRef}
219
+ nodes={nodes}
220
+ rels={rels}
221
+ nvlOptions={nvlOptions}
222
+ interactionOptions={{ selectOnClick: true, drawShadowOnHover: true }}
223
+ mouseEventCallbacks={mouseEventCallbacks}
224
+ onInitializationError={(err) => console.error('NVL init', err)}
225
+ />
226
+ </div>
227
+ )
228
+ }
229
+ ```
230
+
231
+ `ref` resolves to the underlying `NVL` instance — call any method on it: `nvlRef.current?.fit([])`, `nvlRef.current?.setRenderer('webgl')`, `nvlRef.current?.saveToFile()`.
232
+
233
+ ---
234
+
235
+ ## NVL 2.0 — Layout Clustering
236
+
237
+ `clusterBy` groups nodes whose callback returns the same string or number. Return `undefined` for independent nodes. Keep the callback reference stable in React with `useCallback`.
238
+
239
+ Force-directed clustering nests all clustering settings under `layoutOptions.clustering`:
240
+
241
+ ```javascript
242
+ const clusterBy = (nodeId) => categoryByNodeId[nodeId]
243
+
244
+ const nvl = new NVL(container, nodes, relationships, {
245
+ layout: 'forceDirected',
246
+ layoutOptions: {
247
+ seedingMethod: 'circle',
248
+ clustering: {
249
+ clusterBy,
250
+ drawOutline: true,
251
+ drawHalo: true,
252
+ crossClusterRelationshipMultiplier: 0.2
253
+ }
254
+ },
255
+ minFps: 3,
256
+ maxFps: 30
257
+ })
258
+ ```
259
+
260
+ `crossClusterRelationshipMultiplier` is experimental, capped to `0..1`, and can destabilize highly connected graphs near `1`. It affects cross-cluster spring pull only; intra-cluster edges remain full strength.
261
+
262
+ Hierarchical clustering places `clusterBy` directly in `layoutOptions`:
263
+
264
+ ```javascript
265
+ const nvl = new NVL(container, nodes, relationships, {
266
+ layout: 'hierarchical',
267
+ layoutOptions: {
268
+ direction: 'down',
269
+ clusterBy
270
+ }
271
+ })
272
+ ```
273
+
274
+ Cluster decorations and cluster hull interactions apply to force-directed `layoutOptions.clustering`. A `Cluster` is not a graph element; it has `{ id: string | number, nodeIds: string[] }`. Cluster callbacks fire only for empty space inside a cluster hull; node and relationship hits retain priority.
275
+
276
+ ---
277
+
278
+ ## Migrating from NVL 1.x to 2.0
279
+
280
+ - Move React wrapper `layout` and `layoutOptions` props into `nvlOptions`:
281
+ `<InteractiveNvlWrapper nvlOptions={{ layout, layoutOptions }} />`.
282
+ - Replace interaction callback `onZoom` with `onZoomAndPan(zoom, panX, panY, event)`.
283
+ - Remove `intelWorkaround` and Cytoscape-related layout settings; they no longer exist.
284
+ - Treat WebGL as WebGL2-only and do not expect captions in the WebGL renderer.
285
+ - `getNodes()` and `onLayoutStep` return `NodeWithClientPosition[]`: `x`/`y` are layout coordinates and `clientPosition` is relative to the canvas element.
286
+ - Use `styling.overlayLineColor`; `styling.minimapViewportBoxColor` is deprecated.
287
+
288
+ ---
289
+
290
+ ## React — BasicNvlWrapper + Ref
291
+
292
+ No interactions wired. The ref exposes every NVL method via `IncludeMethods<NVL>` — use when building custom interaction logic in React.
293
+
294
+ ```tsx
295
+ import { BasicNvlWrapper } from '@neo4j-nvl/react'
296
+ import type { NVL } from '@neo4j-nvl/base'
297
+ import { useRef } from 'react'
298
+
299
+ export function MiniGraph({ nodes, rels }) {
300
+ const nvlRef = useRef<NVL>(null)
301
+
302
+ return (
303
+ <div style={{ width: '100%', height: 400 }}>
304
+ <BasicNvlWrapper
305
+ ref={nvlRef}
306
+ nodes={nodes}
307
+ rels={rels}
308
+ nvlOptions={{ initialZoom: 2 }}
309
+ nvlCallbacks={{ onLayoutDone: () => nvlRef.current?.fit([]) }}
310
+ />
311
+ <button onClick={() => nvlRef.current?.fit(['1', '2'])}>Zoom to 1,2</button>
312
+ </div>
313
+ )
314
+ }
315
+ ```
316
+
317
+ ---
318
+
319
+ ## Wiring a Neo4j Driver Result
320
+
321
+ `@neo4j-nvl/base` exports a `ResultTransformer` for the JS driver that deduplicates nodes/relationships across any record shape.
322
+
323
+ ```javascript
324
+ import neo4j from 'neo4j-driver'
325
+ import { NVL, nvlResultTransformer } from '@neo4j-nvl/base'
326
+
327
+ const driver = neo4j.driver(process.env.NEO4J_URI,
328
+ neo4j.auth.basic(process.env.NEO4J_USERNAME, process.env.NEO4J_PASSWORD))
329
+
330
+ const { nodes, relationships } = await driver.executeQuery(
331
+ 'MATCH (a)-[r]-(b) RETURN a, r, b LIMIT 25',
332
+ {},
333
+ { database: 'neo4j', resultTransformer: nvlResultTransformer }
334
+ )
335
+
336
+ const nvl = new NVL(document.getElementById('viz'), nodes, relationships)
337
+ ```
338
+
339
+ ```javascript
340
+ // ❌ raw EagerResult — records are not Node/Relationship objects
341
+ const result = await driver.executeQuery('MATCH (a)-[r]-(b) RETURN a, r, b')
342
+ new NVL(container, result.records, []) // breaks
343
+
344
+ // ✅ use the transformer
345
+ const { nodes, relationships } = await driver.executeQuery(
346
+ 'MATCH (a)-[r]-(b) RETURN a, r, b',
347
+ {},
348
+ { database: 'neo4j', resultTransformer: nvlResultTransformer }
349
+ )
350
+ new NVL(container, nodes, relationships)
351
+ ```
352
+
353
+ For driver lifecycle, session management, Integer handling, and TypeScript types → `neo4j-driver-javascript-skill`.
354
+
355
+ ---
356
+
357
+ ## Updating the Graph
358
+
359
+ | Method | Behavior |
360
+ |---|---|
361
+ | `addAndUpdateElementsInGraph(nodes, rels)` | Insert new; update existing by id (only specified fields) |
362
+ | `updateElementsInGraph(nodes, rels)` | Update existing only; ignores unknown ids |
363
+ | `addElementsToGraph(nodes, rels)` | Insert only; throws on existing id |
364
+ | `removeNodesWithIds(ids)` | Remove nodes; adjacent relationships auto-removed |
365
+ | `removeRelationshipsWithIds(ids)` | Remove relationships |
366
+ | `setNodePositions(nodes, updateLayout?)` | Override positions; optionally re-run layout |
367
+ | `restart(options?, retainPositions?)` | Restart with new options; positions optional |
368
+
369
+ Diff updates use `PartialNode` / `PartialRelationship` — only `id` is required:
370
+
371
+ ```javascript
372
+ nvl.updateElementsInGraph(
373
+ [{ id: '1', color: '#f00', selected: true }], // PartialNode
374
+ [{ id: '12', width: 4 }] // PartialRelationship
375
+ )
376
+ ```
377
+
378
+ ---
379
+
380
+ ## Hit Testing (Manual)
381
+
382
+ Use when NOT using the interaction-handlers package. In 2.0, `getHits()` resolves nodes, relationships, and force-directed cluster hulls. Its default targets are `['node', 'relationship', 'cluster']`.
383
+
384
+ ```javascript
385
+ const nvl = new NVL(container, nodes, rels)
386
+
387
+ container.addEventListener('click', (evt) => {
388
+ const { nvlTargets } = nvl.getHits(evt, ['node', 'relationship', 'cluster'], { hitNodeMarginWidth: 4 })
389
+ const hitNode = nvlTargets.nodes[0]
390
+ const hitRel = nvlTargets.relationships[0]
391
+ const hitCluster = nvlTargets.clusters[0]
392
+ if (hitNode) console.log('hit node', hitNode.data.id)
393
+ else if (hitRel) console.log('hit rel', hitRel.data.id)
394
+ else if (hitCluster) console.log('hit cluster', hitCluster.data.id, hitCluster.data.nodeIds)
395
+ else console.log('hit canvas')
396
+ })
397
+ ```
398
+
399
+ `HitTargetNode` / `HitTargetRelationship` carry element hit data. `HitTargetCluster` carries `data`, `pointerCoordinates`, and the fitted convex `hull`. See [references/api-surface.md](references/api-surface.md).
400
+
401
+ ---
402
+
403
+ ## Common Mistakes
404
+
405
+ | Mistake | Fix |
406
+ |---|---|
407
+ | Container with no `height` → invisible graph | Set explicit `width` and `height` on the container |
408
+ | Pass `driver.executeQuery` result directly | Use `nvlResultTransformer` and consume `{ nodes, relationships }` |
409
+ | WebGL for small label-rich graphs | Use `'canvas'`; labels are fully supported |
410
+ | Canvas for 10k+ nodes | Switch to `'webgl'` via `renderer` option or `setRenderer` |
411
+ | New `NVL` per React render | Use `<InteractiveNvlWrapper>` / `<BasicNvlWrapper>` or wrap in `useEffect` + `destroy()` |
412
+ | Forgetting `nvl.destroy()` on teardown | Call `destroy()` on unmount; React wrappers handle this automatically |
413
+ | Vanilla handlers not torn down | Call `.destroy()` on every interaction before `nvl.destroy()` |
414
+ | Worker construction blocked (strict CSP / sandboxed runtime / older bundler) | `nvlOptions: { disableWebWorkers: true }` (NVL has a non-worker fallback) |
415
+ | Telemetry enabled in regulated env | `nvlOptions: { disableTelemetry: true }` |
416
+ | Layout never settles | Pin anchor nodes with `pinNode(id)`; tune `layoutTimeLimit` |
417
+ | `selectOnClick` fires double | Toggle once at mount; don't flip `interactionOptions` per render |
418
+ | Hit test misses near node edge | Pass `{ hitNodeMarginWidth: N }` to `getHits` |
419
+ | Captions missing on WebGL | Expected in 2.0; captions are Canvas-only, so use `'canvas'` when labels matter |
420
+ | React wrapper ignores `layout` / `layoutOptions` | In 2.0 these must be nested in `nvlOptions` |
421
+ | `onZoom` never fires | It was removed in 2.0; use `onZoomAndPan` |
422
+ | Cluster callback misses clicks on a node | Cluster callbacks target empty cluster-hull space; node hits take priority |
423
+
424
+ ---
425
+
426
+ ## References
427
+
428
+ Load on demand:
429
+ - [references/api-surface.md](references/api-surface.md) — complete 2.0 `NVL` method table; clustering, FPS, seeding, `NodeWithClientPosition`, hit target and interaction callback types; React props; named exports; `nvlResultTransformer`
430
+ - [references/troubleshooting.md](references/troubleshooting.md) — zero-height container, WebGL2 and Canvas trade-offs, clustering configuration, 1.x migration errors, worker fallback, context loss, telemetry, lifecycle, layout and hit-testing issues
431
+
432
+ Canonical web documentation (use `WebFetch` when references above are insufficient):
433
+ - https://neo4j.com/docs/nvl/current/ — user guide (installation, base library, interaction handlers, React wrappers)
434
+ - https://neo4j.com/docs/api/nvl/current/ — TypeDoc API reference
435
+ - https://neo4j.com/docs/api/nvl/current/examples.html — runnable examples
436
+ - https://github.com/neo4j-devtools/nvl-boilerplates — official starter templates per supported framework
437
+ - https://github.com/neo4j/python-graph-visualization — Python port of NVL (use this skill only for the JavaScript/browser path)
438
+
439
+ ---
440
+
441
+ ## Checklist
442
+ - [ ] Container has explicit `width` AND `height` CSS
443
+ - [ ] Correct paradigm chosen from the decision table (vanilla / handlers / React)
444
+ - [ ] Renderer matches expected node count (Canvas ≲1k / WebGL 100k+)
445
+ - [ ] Canvas selected whenever captions are required
446
+ - [ ] React `layout` and `layoutOptions` nested inside `nvlOptions`
447
+ - [ ] Zoom handlers use `onZoomAndPan`, not removed `onZoom`
448
+ - [ ] `clusterBy` is stable in React and placed correctly for the selected layout
449
+ - [ ] Driver `executeQuery` results piped through `nvlResultTransformer`
450
+ - [ ] `database` specified on every `executeQuery` call (delegate to `neo4j-driver-javascript-skill`)
451
+ - [ ] All interaction handlers `.destroy()`-ed before `nvl.destroy()` on teardown
452
+ - [ ] `nvl.destroy()` called on React unmount (manual instances only — wrappers handle it)
453
+ - [ ] `disableTelemetry: true` set when in regulated / offline environments
454
+ - [ ] `disableWebWorkers: true` set when bundler / CSP blocks worker construction
455
+ - [ ] Graph updates use `addAndUpdateElementsInGraph` / `updateElementsInGraph` — not `restart`
456
+ - [ ] License compatible: target is a Neo4j product