When to Use
- Rendering a Neo4j graph in a browser (vanilla JS, React, Vite) with custom interactions, rendering, or data shapes
- Visualizing results as an interactive graph
- Wiring zoom, pan, drag, click, hover, lasso, or box-select interactions
- Embedding NVL inside an existing app and synchronizing graph state
When NOT to Use
- Pre-styled embedded graph view with default behavior, no custom interactions → from (Neo4j Needle / NDL design system) — wraps NVL with default Neo4j styling. See Use NVL or the Needle Component? below.
- Python / Jupyter notebook graph visualization →
neo4j/python-graph-visualization
(the Python port of NVL)
- Writing/optimizing Cypher →
- Driver setup / executeQuery / sessions →
neo4j-driver-javascript-skill
- Server-side data fetching with no rendering →
neo4j-driver-javascript-skill
- GDS algorithm execution → or
neo4j-aura-graph-analytics-skill
- GraphQL API →
Use NVL or the Needle Component?
| Need | Use |
|---|
| Embed a graph view with default Neo4j styling, no custom interactions or rendering | from (Neo4j Needle / NDL design system) — wraps NVL and accepts records shaped { id, labels, properties: { key: { stringified, type } } }
() |
| Custom interactions, custom rendering, non-standard data shapes, or framework-agnostic embedding | This skill — use NVL directly |
If the answer is the first row, install and use the Needle component instead of NVL — do not duplicate styling work.
Install
bash
npm install @neo4j-nvl/base # core (required)
npm install @neo4j-nvl/interaction-handlers # standard interactions (optional, vanilla JS)
npm install @neo4j-nvl/react # React wrappers (optional)
Peer requirements:
React 19 for
. 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.
is a peer of
only when using
.
Starter templates:
https://github.com/neo4j-devtools/nvl-boilerplates — official per-framework scaffolds; prefer these over hand-rolled setups.
License: NVL ships under the Neo4j Visualization Library License — for use with Neo4j products only. Cannot be used against other graph backends.
Pick the Right Paradigm
| Need | Use |
|---|
| React app, default interactions | from |
| React app, custom interaction wiring | + own handlers via |
| Vanilla JS, standard interactions | + @neo4j-nvl/interaction-handlers
|
| Vanilla JS, fully custom event logic | + container.addEventListener
+ |
| Static PNG/SVG image export | or / |
Pick the Right Renderer
| Renderer | Max nodes | Detail | Use case |
|---|
| (default) | ~1,000 | Full captions, icons, arrows, pixel-perfect hit-testing | Detail investigation, small graphs |
| 100,000+ | Reduced label fidelity (bound by GPU max texture size) | Large-scale pattern exploration |
javascript
const nvl = new NVL(container, nodes, rels, { renderer: 'webgl' })
nvl.setRenderer('canvas') // swap at runtime
Container Setup
The container must have an explicit
AND
. Missing height → container collapses to
→ graph invisible. Most-reported NVL bug.
html
<!-- ❌ height defaults to 0; graph invisible -->
<div id="viz"></div>
<!-- ✅ explicit dimensions -->
<div id="viz" style="width: 100%; height: 600px;"></div>
Vanilla — Base Library
javascript
import { NVL } from '@neo4j-nvl/base'
const container = document.getElementById('viz')
const nodes = [{ id: '1' }, { id: '2' }]
const relationships = [{ id: '12', from: '1', to: '2', type: 'KNOWS' }]
const nvl = new NVL(container, nodes, relationships)
With options + callbacks:
javascript
import { NVL } from '@neo4j-nvl/base'
const options = {
initialZoom: 1.0,
minZoom: 0.1,
maxZoom: 8,
layout: 'forceDirected',
renderer: 'canvas',
styling: { defaultNodeColor: '#0e86d4', defaultRelationshipColor: '#888' }
}
const callbacks = {
onInitialization: () => console.log('NVL ready'),
onLayoutDone: () => nvl.fit([]),
onError: (err) => console.error('NVL error', err)
}
const nvl = new NVL(container, nodes, relationships, options, callbacks)
// On teardown — always:
nvl.destroy()
constructor signature:
new NVL(frame, nvlNodes?, nvlRels?, options?, callbacks?)
. All but
are optional and default to empty.
Vanilla — Interaction Handlers
Compose handlers onto an existing
instance. Each handler registers callbacks via
.updateCallback(name, fn)
and must be torn down with
.
javascript
import { NVL } from '@neo4j-nvl/base'
import {
ZoomInteraction, PanInteraction, DragNodeInteraction,
ClickInteraction, HoverInteraction, BoxSelectInteraction,
LassoInteraction, KeyboardInteraction
} from '@neo4j-nvl/interaction-handlers'
const nvl = new NVL(container, nodes, relationships)
const zoom = new ZoomInteraction(nvl)
const pan = new PanInteraction(nvl)
const drag = new DragNodeInteraction(nvl)
const click = new ClickInteraction(nvl, { selectOnClick: true })
const hover = new HoverInteraction(nvl, { drawShadowOnHover: true })
click.updateCallback('onNodeClick', (node, hits, evt) => console.log('node', node.id))
click.updateCallback('onRelationshipClick', (rel, hits, evt) => console.log('rel', rel.id))
click.updateCallback('onCanvasClick', (evt) => console.log('canvas'))
hover.updateCallback('onHover', (el, hits, evt) => el && console.log('over', el.id))
drag.updateCallback('onDragEnd', (nodes, evt) => savePositions(nodes))
zoom.updateCallback('onZoom', (level) => console.log('zoom', level))
// Teardown — destroy all handlers, then the NVL instance
function teardown() {
for (const h of [zoom, pan, drag, click, hover]) h.destroy()
nvl.destroy()
}
Disable an event without removing the handler:
click.removeCallback('onCanvasClick')
. Passing
instead of a function enables the event with a no-op (useful for default selection behavior).
React — InteractiveNvlWrapper
Pre-wires every interaction handler. Toggle events with
(function = on + callback;
= on, no-op;
/omit = off).
tsx
import { InteractiveNvlWrapper } from '@neo4j-nvl/react'
import type { MouseEventCallbacks, NvlOptions } from '@neo4j-nvl/react'
import { useRef } from 'react'
import type { NVL } from '@neo4j-nvl/base'
export function GraphView({ nodes, rels }) {
const nvlRef = useRef<NVL>(null)
const nvlOptions: NvlOptions = { initialZoom: 1, renderer: 'canvas' }
const mouseEventCallbacks: MouseEventCallbacks = {
onNodeClick: (node, hits, evt) => console.log('node', node.id),
onRelationshipClick: (rel, hits, evt) => console.log('rel', rel.id),
onCanvasClick: (evt) => console.log('canvas'),
onHover: (el, hits, evt) => el && console.log('hover', el.id),
onDragEnd: (nodes, evt) => persist(nodes),
onZoom: true, // enable, no callback
onPan: true
}
return (
<div style={{ width: '100%', height: 600 }}>
<InteractiveNvlWrapper
ref={nvlRef}
nodes={nodes}
rels={rels}
nvlOptions={nvlOptions}
interactionOptions={{ selectOnClick: true, drawShadowOnHover: true }}
mouseEventCallbacks={mouseEventCallbacks}
onInitializationError={(err) => console.error('NVL init', err)}
/>
</div>
)
}
resolves to the underlying
instance — call any method on it:
,
nvlRef.current?.setRenderer('webgl')
,
nvlRef.current?.saveToFile()
.
React — BasicNvlWrapper + Ref
No interactions wired. The ref exposes every NVL method via
— use when building custom interaction logic in React.
tsx
import { BasicNvlWrapper } from '@neo4j-nvl/react'
import type { NVL } from '@neo4j-nvl/base'
import { useRef } from 'react'
export function MiniGraph({ nodes, rels }) {
const nvlRef = useRef<NVL>(null)
return (
<div style={{ width: '100%', height: 400 }}>
<BasicNvlWrapper
ref={nvlRef}
nodes={nodes}
rels={rels}
nvlOptions={{ initialZoom: 2 }}
nvlCallbacks={{ onLayoutDone: () => nvlRef.current?.fit([]) }}
/>
<button onClick={() => nvlRef.current?.fit(['1', '2'])}>Zoom to 1,2</button>
</div>
)
}
Wiring a Neo4j Driver Result
exports a
for the JS driver that deduplicates nodes/relationships across any record shape.
javascript
import neo4j from 'neo4j-driver'
import { NVL, nvlResultTransformer } from '@neo4j-nvl/base'
const driver = neo4j.driver(process.env.NEO4J_URI,
neo4j.auth.basic(process.env.NEO4J_USERNAME, process.env.NEO4J_PASSWORD))
const { nodes, relationships } = await driver.executeQuery(
'MATCH (a)-[r]-(b) RETURN a, r, b LIMIT 25',
{},
{ database: 'neo4j', resultTransformer: nvlResultTransformer }
)
const nvl = new NVL(document.getElementById('viz'), nodes, relationships)
javascript
// ❌ raw EagerResult — records are not Node/Relationship objects
const result = await driver.executeQuery('MATCH (a)-[r]-(b) RETURN a, r, b')
new NVL(container, result.records, []) // breaks
// ✅ use the transformer
const { nodes, relationships } = await driver.executeQuery(
'MATCH (a)-[r]-(b) RETURN a, r, b',
{},
{ database: 'neo4j', resultTransformer: nvlResultTransformer }
)
new NVL(container, nodes, relationships)
For driver lifecycle, session management, Integer handling, and TypeScript types →
neo4j-driver-javascript-skill
.
Updating the Graph
| Method | Behavior |
|---|
addAndUpdateElementsInGraph(nodes, rels)
| Insert new; update existing by id (only specified fields) |
updateElementsInGraph(nodes, rels)
| Update existing only; ignores unknown ids |
addElementsToGraph(nodes, rels)
| Insert only; throws on existing id |
| Remove nodes; adjacent relationships auto-removed |
removeRelationshipsWithIds(ids)
| Remove relationships |
setNodePositions(nodes, updateLayout?)
| Override positions; optionally re-run layout |
restart(options?, retainPositions?)
| Restart with new options; positions optional |
Diff updates use
/
— only
is required:
javascript
nvl.updateElementsInGraph(
[{ id: '1', color: '#f00', selected: true }], // PartialNode
[{ id: '12', width: 4 }] // PartialRelationship
)
Hit Testing (Manual)
Use when NOT using the interaction-handlers package.
resolves which node/relationship is under a pointer event.
javascript
const nvl = new NVL(container, nodes, rels)
container.addEventListener('click', (evt) => {
const { nvlTargets } = nvl.getHits(evt, ['node', 'relationship'], { hitNodeMarginWidth: 4 })
const hitNode = nvlTargets.nodes[0]
const hitRel = nvlTargets.relationships[0]
if (hitNode) console.log('hit node', hitNode.data.id)
else if (hitRel) console.log('hit rel', hitRel.data.id)
else console.log('hit canvas')
})
/
carry
,
,
,
(nodes only). See
references/api-surface.md.
Common Mistakes
| Mistake | Fix |
|---|
| Container with no → invisible graph | Set explicit and on the container |
| Pass result directly | Use and consume |
| WebGL for small label-rich graphs | Use ; labels are fully supported |
| Canvas for 10k+ nodes | Switch to via option or |
| New per React render | Use / or wrap in + |
| Forgetting on teardown | Call on unmount; React wrappers handle this automatically |
| Vanilla handlers not torn down | Call on every interaction before |
| Worker construction blocked (strict CSP / sandboxed runtime / older bundler) | nvlOptions: { disableWebWorkers: true }
(NVL has a non-worker fallback) |
| Telemetry enabled in regulated env | nvlOptions: { disableTelemetry: true }
|
| Layout never settles | Pin anchor nodes with ; tune |
| fires double | Toggle once at mount; don't flip per render |
| Hit test misses near node edge | Pass { hitNodeMarginWidth: N }
to |
| Captions missing on WebGL | GPU max texture size exceeded; fall back to Canvas or shrink captions |
References
Load on demand:
- references/api-surface.md — complete method table; , , , , , , , , ; every interaction-handler class + its options + its callback signatures; React / / props; and shapes; named exports inventory; signature
- references/troubleshooting.md — zero-height container, build-tool-agnostic fallback, Canvas/WebGL trade-offs + WebGL2 note, WebGL texture-size cap, recovery, telemetry opt-out, memory leaks, stuck layouts, double selection, hit-margin tuning, license restriction
Canonical web documentation (use
when references above are insufficient):
- https://neo4j.com/docs/nvl/current/ — user guide (installation, base library, interaction handlers, React wrappers)
- https://neo4j.com/docs/api/nvl/current/ — TypeDoc API reference
- https://neo4j.com/docs/api/nvl/current/examples.html — runnable examples
- https://github.com/neo4j-devtools/nvl-boilerplates — official starter templates per supported framework
- https://github.com/neo4j/python-graph-visualization — Python port of NVL (use this skill only for the JavaScript/browser path)
Checklist