Neo4j Visualization Library (@neo4j-nvl/base)
Shipped with
@neo4j-nvl/basev2.1.0. Once installed into a project this folder is detached from the package: the installed types innode_modules/@neo4j-nvl/*are the source of truth. If the project's@neo4j-nvl/baseis a different version andnode_modules/@neo4j-nvl/base/skills/neo4j-nvl-skill/SKILL.mdexists, read that copy instead.
When to use
- Rendering a Neo4j graph in the browser with custom interactions, rendering or data shapes
- Visualizing
driver.executeQueryresults as an interactive graph - Zoom, pan, drag, click, hover, lasso or box-select interactions; clustering; custom layouts
Not for: a pre-styled graph view with default behaviour (GraphVisualization from @neo4j-ndl/react wraps
NVL for that), Python notebooks (neo4j/python-graph-visualization), Cypher, driver setup, GDS or GraphQL.
Rules
- Types win. Confirm every option, callback and method against this skill or the
.d.tsfiles innode_modules/@neo4j-nvl/*before using it. If they disagree, trust the types and say so. - Never invent options. NVL options and callbacks are flat, named keys. If a key is not in the API reference below or the types, it does not exist.
- Do not reverse-engineer from compiled
dist/orlib/output. Use the types and these docs. - Symptom first. When something does not work, check the table below before changing code.
Before you code
- The container has explicit
widthandheight; otherwise the graph is invisible. - React wrappers:
layout,layoutOptionsand every other option go insidenvlOptions. - Wheel zoom in
<InteractiveNvlWrapper>is enabled bymouseEventCallbacks.onZoomAndPan; there is noonZoom. fit()needs explicit node ids.fit([])fits nothing.- The WebGL renderer draws no captions. Use
'canvas'when labels matter, orhtml/iconoverlays. - If the hierarchical layout never finishes under the Vite dev server, add
optimizeDeps: { include: ['bin-pack'] }. Vite 7.3 pre-bundles it on its own, so only apply it when the symptom appears. nvlResultTransformerreturns bare{ id }elements; labels and properties are inrecordObjectMap.- React:
nvlCallbacksare captured once; use refs or stable functions.interactionOptionsreplaces the defaults, so pass every option you need. - Destroy interaction handlers, then
nvl.destroy(), on teardown. The React wrappers do this for you. updateCallback(name, cb)on interaction handlers is untyped:cbis(...args: unknown[]) => void, so parameters arrive asunknownand a typed callback such as(node: Node) => …fails understrict. Cast inside the callback; the ReactmouseEventCallbacksare fully typed.
Symptom → cause → fix
| Symptom | Cause | Fix |
|---|---|---|
| Graph invisible / blank | Container has no height | Explicit width and height on the container |
| Wheel does not zoom (React) | Zoom handler only wired from onZoomAndPan | mouseEventCallbacks={{ onZoomAndPan: true }} → react-wrappers |
| Hierarchical layout never finishes (Vite dev) | Layout SharedWorker imports CJS bin-pack; seen on older Vite, not on 7.3 | optimizeDeps: { include: ['bin-pack'] } → vite-and-bundlers |
| No text on nodes with WebGL | Captions are Canvas-only | html / icon, own overlay, or setRenderer('canvas') → labels-and-overlays |
fit([]) does nothing | Empty array = no nodes | fit(nvl.getNodes().map((n) => n.id)) |
fit() stops zoomed in on a huge graph | minZoom clamp (default 0.075) | fit(ids, { minZoom }) or lower the minZoom option |
| Clicking a cluster selects all its nodes | selectOnClick selects cluster.nodeIds | selectOnClick: false and select in onNodeClick → clustering |
| No cluster outlines / halos | Not force-directed, or mixed colours (halo) | Force-directed with layoutOptions.clustering; one colour per cluster → clustering |
| Pinned nodes move when clustering is on | Cluster forces ignore pins | Do not combine → clustering |
| Changing circle options does nothing | Layout is not re-run on option change | Bounce via setLayout('free') → layouts-and-positions |
| Un-pinned nodes stay frozen | Settled simulation is not restarted | setNodePositions(current, true) → layouts-and-positions |
Node x/y are ignored | Positions are owned by the layout; never set x/y on node data | setNodePositions(nodes) or the React positions prop → layouts-and-positions |
| Callbacks see stale state (React) | nvlCallbacks captured at creation | Refs or stable functions → react-wrappers |
| Minimap empty (React) | Container did not exist at creation | Keep the element in state → react-wrappers |
| Hover / shadow defaults lost | interactionOptions replaces defaults | Pass every option → react-wrappers |
| Many icons not drawn (WebGL) | More than 256 distinct icon images | Fewer distinct icons, or 'canvas' → labels-and-overlays |
| Layout looks hung in headless Chrome | Software WebGL | Hardware-GL flags → verifying-nvl-apps |
Raw executeQuery result passed to NVL | Records are not graph elements | resultTransformer: nvlResultTransformer → data-from-neo4j |
Choose
NVL or Needle? Default Neo4j styling and no custom interaction → GraphVisualization from @neo4j-ndl/react.
Anything custom → NVL.
| Need | Use |
|---|---|
| React, default interactions | <InteractiveNvlWrapper> from @neo4j-nvl/react |
| React, custom interaction logic | <BasicNvlWrapper> + ref to the NVL instance |
| Vanilla, standard interactions | NVL + @neo4j-nvl/interaction-handlers |
| Vanilla, custom events | NVL + container.addEventListener + nvl.getHits() |
| Static PNG / SVG | <StaticPictureWrapper> or nvl.saveToFile() / nvl.saveToSvg() |
| Renderer | Nodes | Notes |
|---|---|---|
'canvas' (default) | up to ~1,000 | Captions, icons, arrows, exact hit-testing |
'webgl' | 100,000+ | WebGL2 only; no captions; icons and arrowheads supported |
disableWebGL: true forces Canvas rendering and non-GPU layouts.
Install
bashnpm install @neo4j-nvl/base # required npm install @neo4j-nvl/interaction-handlers # vanilla interactions npm install @neo4j-nvl/react # React wrappers (React 19)
@neo4j-nvl/layout-workers is transitive; never install it directly. neo4j-driver is only needed for
nvlResultTransformer. License: Neo4j Visualization Library License, for use with Neo4j products.
Starters: https://github.com/neo4j-devtools/nvl-boilerplates
Minimal examples
javascriptimport { NVL } from '@neo4j-nvl/base' import { ClickInteraction, ZoomInteraction, PanInteraction, DragNodeInteraction } from '@neo4j-nvl/interaction-handlers' const nodes = [{ id: '1', caption: 'A' }, { id: '2', caption: 'B' }] const rels = [{ id: '12', from: '1', to: '2', type: 'KNOWS' }] const nvl = new NVL(container, nodes, rels, { layout: 'forceDirected' }, { onLayoutDone: () => nvl.fit(nodes.map((n) => n.id)) }) const click = new ClickInteraction(nvl, { selectOnClick: true }) click.updateCallback('onNodeClick', (node) => console.log('clicked', node)) const handlers = [click, new ZoomInteraction(nvl), new PanInteraction(nvl), new DragNodeInteraction(nvl)] // teardown: handlers.forEach((h) => h.destroy()); nvl.destroy()
tsximport { InteractiveNvlWrapper } from '@neo4j-nvl/react' import type { NVL } from '@neo4j-nvl/base' import { useRef } from 'react' export function Graph({ nodes, rels }) { const nvlRef = useRef<NVL>(null) return ( <div style={{ width: '100%', height: 600 }}> <InteractiveNvlWrapper ref={nvlRef} nodes={nodes} rels={rels} nvlOptions={{ layout: 'forceDirected', renderer: 'canvas' }} interactionOptions={{ selectOnClick: true, drawShadowOnHover: true }} mouseEventCallbacks={{ onNodeClick: (node) => console.log(node.id), onZoomAndPan: true, onPan: true, onDrag: true }} nvlCallbacks={{ onLayoutDone: () => nvlRef.current?.fit(nodes.map((n) => n.id)) }} /> </div> ) }
Topic guides
Read the one that matches the task before writing code.
- references/data-from-neo4j.md —
nvlResultTransformeroutput,recordObjectMap, enriching nodes, Integer and temporal values - references/react-wrappers.md — callback-to-handler mapping, stale callbacks, live vs creation-time options, minimap container
- references/clustering.md —
clusterByper layout, outlines and halos, cluster click and hover, pins - references/layouts-and-positions.md — when layouts re-run,
setNodePositions, pinning, layout callbacks - references/labels-and-overlays.md — captions vs
html/icon/overlayIcon, coordinates for custom overlays - references/vite-and-bundlers.md — worker setup per bundler, dev vs production,
disableWebWorkers - references/verifying-nvl-apps.md —
window.__Nvl_*hooks, headless Chrome flags, detecting a settled layout - references/lifecycle-and-updates.md — add/update/remove methods,
restart, teardown, context loss, telemetry,onError - references/migrating-1x-to-2.md — removed options and renamed callbacks
API reference
Generated from the installed version's type declarations. Open the page for the symbol you need; do not load all of them.
@neo4j-nvl/base
NVL class, options, callbacks, graph element types, hit testing, nvlResultTransformer.
Classes
- NVL — Class for a NVL instance.
Functions
- getZoomTargetForNodePositions — Gets the zoom target to fit the given node positions into the scene.
Interfaces
- CircularOptions — The options for the circular layout.
- ClusteringOptions — Options that control physical clustering and cluster decorations for the force-directed layout.
- ExternalCallbacks — An object specifying the required callback functions for certain actions
- ForceDirectedOptions — The options for the force directed layout
- HierarchicalOptions — The options for the hierarchical layout
- HitTargetCluster — A ClusteringOptions.clusterBy cluster hull that has been hit by a pointer event
- HitTargetNode — A node that has been hit by a pointer event
- HitTargetRelationship — A relationship that has been hit by a pointer event
- Node — A node inside the graph visualization.
- NvlMouseEvent — The result of a NVL.getHits call.
- NvlOptions — Configurations for a NVL instance
- NvlWindow — Read-only debugging hooks that every NVL instance registers on
window, for tests and tooling - Point — An object representing a point in 2D space.
- Relationship — A relationship inside the graph visualization.
Types
- CanvasRendererType — A renderer using canvas.
- Cluster — A physical cluster produced by ClusteringOptions.clusterBy.
- ClusterByFn — Function that maps a node id to a ClusterId for force-directed clustering.
- ClusterId — Identifier returned by ClusterByFn to group nodes into physical clusters.
- HitTargets — A collection of nodes, relationships and clusters that have been hit by a pointer event
- HitTestTarget — The kinds of element NVL.getHits can test for.
- Layout — The different types of layouts available
- LayoutOptions — The options for the layout.
- NodeWithClientPosition — A node returned by NVL.getNodes with layout coordinates and screen position.
- PartialNode — A node with only a subset of its properties.
- PartialRelationship — A relationship with only a subset of its properties.
- Renderer — The different types of renderers available
- StyledCaption — The caption text and its text style.
- WebGLRendererType — A WebGL2 renderer that uses the GPU for rendering.
- ZoomOptions — Options that influence how fit-to-zoom should behave
Variables
- CircularLayoutType — A basic circular layout.
- d3ForceLayoutType — The commonly used d3-force layout.
- ForceDirectedLayoutType — NVL's main force directed layout.
- FreeLayoutType — A free layout that allows for arbitrary positioning of elements using NVL's setPosition method.
- GridLayoutType — A basic grid layout.
- HierarchicalLayoutType — A hierarchical layout using the dagre algorithm.
- nvlResultTransformer — Result transformer for the Neo4j JavaScript driver results to NVL graph elements.
@neo4j-nvl/interaction-handlers
Zoom, pan, drag, click, hover, box/lasso select, keyboard handlers and their callbacks.
Classes
- BoxSelectInteraction — An interaction handler for multi-selecting nodes and relationships.
- ClickInteraction — Click interaction handler that handles click, double click and right click events on
- DragNodeInteraction — Interaction handler for dragging nodes,
- HoverInteraction — Interaction handler for hovering nodes and relationships.
- KeyboardInteraction — Opinionated interaction handler for keyboard-driven focus navigation
- LassoInteraction — An interaction handler that lets you select nodes and relationships by drawing a lasso around them.
- PanInteraction — Interaction handler for panning the scene, which is achieved by clicking and moving the scene.
- ZoomInteraction — Interaction handler for zooming the canvas, which is achieved by:
Types
- BoxSelectInteractionCallbacks — Callbacks for the box select interaction handler.
- BoxSelectInteractionOptions — Options for the multi-select interaction handler to customize its behavior.
- ClickInteractionCallbacks — Callbacks for the click interaction handler.
- ClickInteractionOptions — Options for the click interaction handler to customize its behavior.
- DragNodeInteractionCallbacks — Callbacks for the drag node interaction handler.
- DrawInteractionOptions — Options for the draw interaction handler.
- HoverInteractionCallbacks — Callbacks for the hover interaction handler.
- HoverInteractionOptions — Options for the hover interaction handler to customize its behavior.
- KeyboardInteractionCallbacks — Callbacks for the keyboard interaction handler.
- KeyboardInteractionOptions — Options for the keyboard interaction handler.
- LassoInteractionCallbacks — Callbacks for the lasso interaction handler.
- LassoInteractionOptions — Options for the lasso interaction handler to customize its behavior.
- PanInteractionCallbacks — Callbacks for the pan interaction handler.
- PanInteractionOptions — Options for the pan interaction handler to customize its behavior.
- ZoomInteractionCallbacks — Callbacks for the zoom interaction handler.
- ZoomInteractionOptions — Options for the zoom interaction handler to customize its behavior.
@neo4j-nvl/react
InteractiveNvlWrapper, BasicNvlWrapper, StaticPictureWrapper and their props.
Functions
- StaticPictureWrapper — A React component that creates a static picture of a graph using NVL.
Interfaces
- BasicReactWrapperProps — The properties that can be passed to the BasicNvlWrapper component.
- InteractiveNvlWrapperProps — The properties that can be passed to the InteractiveNvlWrapper component.
Types
- InteractionOptions — Collection of interaction options that can be used with
- KeyboardEvent — The events that can be passed to the KeyboardEventCallbacks object
- KeyboardEventCallbacks — Collection of keyboard event callbacks that can be used with
- MouseEvent — The events that can be passed to the MouseEventCallbacks object
- MouseEventCallbacks — Collection of mouse event callbacks that can be used with
- StaticPictureWrapperProps — The properties that can be passed to the StaticPictureWrapper component.
Variables
- BasicNvlWrapper — A basic React wrapper that wraps the NVL base library within a React component.
- InteractiveNvlWrapper — The interactive React wrapper component contains a collection of interaction handlers by default
Web: user guide https://neo4j.com/docs/nvl/current/ · API https://neo4j.com/docs/api/nvl/current/ · examples https://neo4j.com/docs/api/nvl/current/examples.html


