@neo4j-nvl/base 2.0.0-8a6da460 → 2.0.0-d21c8bbe
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.md +8 -0
- package/dist/base.mjs +35832 -39698
- package/dist/types/index.d.ts +4 -6
- package/dist/types/modules/state/types.d.ts +16 -5
- package/dist/types/renderers/domrenderer/canvasrenderer/CanvasRenderer.d.ts +1 -1
- package/package.json +6 -6
- package/skills/neo4j-nvl-skill/README.md +39 -0
- package/skills/neo4j-nvl-skill/SKILL.md +456 -0
- package/skills/neo4j-nvl-skill/references/api-surface.md +596 -0
- package/skills/neo4j-nvl-skill/references/troubleshooting.md +317 -0
- /package/dist/types/utils/{hittest.d.ts → hitTest.d.ts} +0 -0
- /package/dist/types/utils/{hittest.test.d.ts → hitTest.test.d.ts} +0 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { StyledCaption } from './renderers/domrenderer/shared/types';
|
|
|
6
6
|
import type { Node, NodeWithClientPosition, PartialNode, PartialRelationship, Relationship } from './types/graph-element';
|
|
7
7
|
import { CompatibilityError } from './utils/errors';
|
|
8
8
|
import type { Point } from './utils/geometry';
|
|
9
|
-
import type { HitTargetCluster, HitTargetNode, HitTargetRelationship, HitTargets, HitTestTarget } from './utils/
|
|
9
|
+
import type { HitTargetCluster, HitTargetNode, HitTargetRelationship, HitTargets, HitTestTarget } from './utils/hitTest';
|
|
10
10
|
import { nvlResultTransformer } from './utils/jsDriverResultTransformer';
|
|
11
11
|
import { getZoomTargetForNodePositions } from './utils/zoomFunctions';
|
|
12
12
|
/**
|
|
@@ -184,11 +184,9 @@ declare class NVL {
|
|
|
184
184
|
* @param zoomOptions - Specific options on how to transition the zoom.
|
|
185
185
|
*
|
|
186
186
|
* @remarks
|
|
187
|
-
*
|
|
188
|
-
* {@link NvlOptions.minZoom minZoom}
|
|
189
|
-
* {@link NvlOptions.allowDynamicMinZoom allowDynamicMinZoom}
|
|
190
|
-
* the zoom level will be set to the closest valid zoom level,
|
|
191
|
-
* even if the given nodes do not fit the viewport yet.
|
|
187
|
+
* Zoom is limited by {@link ZoomOptions.minZoom} / {@link ZoomOptions.maxZoom} and the
|
|
188
|
+
* {@link NvlOptions.minZoom minZoom} / {@link NvlOptions.maxZoom maxZoom} /
|
|
189
|
+
* {@link NvlOptions.allowDynamicMinZoom allowDynamicMinZoom} options. See those for details.
|
|
192
190
|
*/
|
|
193
191
|
fit(nodeIds: string[], zoomOptions?: NvlState['zoomOptions']): void;
|
|
194
192
|
/**
|
|
@@ -237,9 +237,10 @@ export interface NvlOptions {
|
|
|
237
237
|
/**
|
|
238
238
|
* Whether or not to dynamically allow decreasing minimum zoom value
|
|
239
239
|
* if current graph does not fit on screen at minimum zoom.
|
|
240
|
-
* When set to true
|
|
241
|
-
* further than
|
|
242
|
-
*
|
|
240
|
+
* When set to `true`, zoom and fit operations will allow zooming out
|
|
241
|
+
* further than {@link NvlOptions.minZoom minZoom} if the graph does not fit on screen.
|
|
242
|
+
* {@link NvlOptions.minZoom minZoom} is lowered to the new zoom level, so later zoom operations can go that low too.
|
|
243
|
+
* When set to `false`, zoom and fit operations will stop at the minimum zoom value,
|
|
243
244
|
* even if the full graph does not fit on screen at that zoom level.
|
|
244
245
|
* @defaultValue true
|
|
245
246
|
*/
|
|
@@ -360,9 +361,17 @@ export type ZoomOptions = {
|
|
|
360
361
|
noPan?: boolean;
|
|
361
362
|
/** If true, will only zoom out if specified nodes won't fit into viewport but won't zoom in any further. */
|
|
362
363
|
outOnly?: boolean;
|
|
363
|
-
/**
|
|
364
|
+
/**
|
|
365
|
+
* The minimum zoom value for the fit-to-zoom operation. The fit never zooms out further than this.
|
|
366
|
+
* If {@link NvlOptions.allowDynamicMinZoom} is `true`, it can be lower than {@link NvlOptions.minZoom},
|
|
367
|
+
* which is then lowered to the resulting zoom level.
|
|
368
|
+
* If it is `false`, this can only raise the {@link NvlOptions.minZoom} limit, not lower it.
|
|
369
|
+
*/
|
|
364
370
|
minZoom?: number;
|
|
365
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* The maximum zoom value for the fit-to-zoom operation.
|
|
373
|
+
* This can only lower the {@link NvlOptions.maxZoom} limit, not raise it.
|
|
374
|
+
*/
|
|
366
375
|
maxZoom?: number;
|
|
367
376
|
/** If true, will not animate the zoom/pan transition. */
|
|
368
377
|
animated?: boolean;
|
|
@@ -390,6 +399,7 @@ export interface NvlState {
|
|
|
390
399
|
maxDistance: number;
|
|
391
400
|
minZoom: number;
|
|
392
401
|
maxZoom: number;
|
|
402
|
+
allowDynamicMinZoom: boolean;
|
|
393
403
|
minMinimapZoom: number;
|
|
394
404
|
maxMinimapZoom: number;
|
|
395
405
|
nodes: NodeDataSet;
|
|
@@ -412,6 +422,7 @@ export interface NvlState {
|
|
|
412
422
|
clearFit: Function;
|
|
413
423
|
clearReset: Function;
|
|
414
424
|
updateZoomToFit: Function;
|
|
425
|
+
lowerMinZoom: (zoom: number) => void;
|
|
415
426
|
updateMinimapZoomToFit: Function;
|
|
416
427
|
autorun: Function;
|
|
417
428
|
reaction: Function;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NvlState } from '../../../modules/state/types';
|
|
2
2
|
import type { Node } from '../../../types/graph-element';
|
|
3
3
|
import type { Point } from '../../../utils/geometry';
|
|
4
|
-
import type { HitTargetNode, HitTargetRelationship } from '../../../utils/
|
|
4
|
+
import type { HitTargetNode, HitTargetRelationship } from '../../../utils/hitTest';
|
|
5
5
|
import type { RendererOptions } from '../BaseRenderer';
|
|
6
6
|
import BaseRenderer from '../BaseRenderer';
|
|
7
7
|
export default class CanvasRenderer extends BaseRenderer {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-nvl/base",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-d21c8bbe",
|
|
4
4
|
"license": "SEE LICENSE IN 'LICENSE.txt'",
|
|
5
5
|
"homepage": "https://neo4j.com/docs/nvl/current/",
|
|
6
6
|
"description": "Base library for the Neo4j Visualization Library",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"types": "dist/types/index.d.ts",
|
|
17
17
|
"files": [
|
|
18
18
|
"LICENSE.txt",
|
|
19
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"skills"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "yarn global:tsc && vite build",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"postpack": "rm LICENSE.txt && rm CHANGELOG.md"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@neo4j-nvl/layout-workers": "2.0.0-
|
|
34
|
+
"@neo4j-nvl/layout-workers": "2.0.0-d21c8bbe",
|
|
34
35
|
"@segment/analytics-next": "1.81.1",
|
|
35
36
|
"color-string": "1.9.1",
|
|
36
37
|
"d3-force": "3.0.0",
|
|
@@ -41,17 +42,16 @@
|
|
|
41
42
|
"mobx": "6.15.0",
|
|
42
43
|
"node-pid-controller": "1.0.1",
|
|
43
44
|
"tinycolor2": "1.6.0",
|
|
44
|
-
"uuid": "14.0.
|
|
45
|
+
"uuid": "14.0.3"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@babel/core": "7.29.7",
|
|
48
48
|
"@types/color-string": "1.5.5",
|
|
49
49
|
"@types/d3-force": "3.0.10",
|
|
50
50
|
"@types/lodash": "4.17.21",
|
|
51
51
|
"@types/segment-analytics": "0.0.38",
|
|
52
52
|
"@types/tinycolor2": "1.4.6",
|
|
53
53
|
"neo4j-driver": "5.28.2",
|
|
54
|
-
"vite": "
|
|
54
|
+
"vite": "8.3.5",
|
|
55
55
|
"vite-plugin-static-copy": "4.1.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# neo4j-nvl-skill
|
|
2
|
+
|
|
3
|
+
Skill for the Neo4j Visualization Library (NVL) — covering:
|
|
4
|
+
|
|
5
|
+
- `@neo4j-nvl/base` — `NVL` class, nodes/relationships, options, callbacks, hit testing, image export
|
|
6
|
+
- `@neo4j-nvl/interaction-handlers` — `ZoomInteraction`, `PanInteraction`, `DragNodeInteraction`, `ClickInteraction`, `HoverInteraction`, `BoxSelectInteraction`, `LassoInteraction`, `KeyboardInteraction`
|
|
7
|
+
- `@neo4j-nvl/react` — `InteractiveNvlWrapper`, `BasicNvlWrapper`, `StaticPictureWrapper`
|
|
8
|
+
- `nvlResultTransformer` for piping `driver.executeQuery` results straight into NVL
|
|
9
|
+
- Canvas vs WebGL renderer selection (~1k vs 100k+ nodes)
|
|
10
|
+
- Layout selection (`forceDirected`, `hierarchical`, `circular`, `grid`, `free`, `d3Force`)
|
|
11
|
+
- force-directed and hierarchical `clusterBy`, cluster decorations, hit testing, and callbacks
|
|
12
|
+
- Container setup, Web Worker fallback, telemetry opt-out
|
|
13
|
+
|
|
14
|
+
**Not covered** (see sibling tools / skills):
|
|
15
|
+
- Out-of-the-box embedded graph view with default styling → `GraphVisualization` component in `@neo4j-ndl/react` (Neo4j Needle design system) — wraps NVL with defaults
|
|
16
|
+
- Python / Jupyter graph visualization → `neo4j/python-graph-visualization` (Python port of NVL)
|
|
17
|
+
- Cypher query authoring → `neo4j-cypher-skill`
|
|
18
|
+
- Driver lifecycle, sessions, `executeQuery` setup → `neo4j-driver-javascript-skill`
|
|
19
|
+
- GDS algorithms → `neo4j-gds-skill` / `neo4j-aura-graph-analytics-skill`
|
|
20
|
+
|
|
21
|
+
**Compatibility:** `@neo4j-nvl` packages 2.0.x; React 19 for `@neo4j-nvl/react`; modern browsers with Canvas2D and WebGL2.
|
|
22
|
+
|
|
23
|
+
**Install:**
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @neo4j-nvl/base
|
|
27
|
+
npm install @neo4j-nvl/interaction-handlers # optional, for vanilla JS interactions
|
|
28
|
+
npm install @neo4j-nvl/react # optional, for React apps
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Starter templates: https://github.com/neo4j-devtools/nvl-boilerplates
|
|
32
|
+
|
|
33
|
+
**Install skill:**
|
|
34
|
+
|
|
35
|
+
This skill ships inside `@neo4j-nvl/base`. After installing the package, sync it into your agent's skills directory:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx skills experimental_sync
|
|
39
|
+
```
|
|
@@ -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
|