Creates a new NVL instance.
The DOM element to display the graph in.
An array of nodes.
An array of relationships.
The options for the NVL instance.
Callbacks triggered on NVL events.
Adds nodes and relationships to NVL and updates existing nodes and relationships.
An Array of nodes to be added or updated.
An Array of relationships to be added or updated. To update nodes or relationships, they must have an id that matches the id of the node or relationship to be updated. Only the properties that are provided will be updated. If an existing property is not provided, it will not be changed.
Adding and updating nodes and relationships
import { NVL } from '@neo4j-nvl/base'
const nvl = new NVL(document.getElementById('frame'), [{ id: '0' }], [])
const nodes = [
{ id: '1', caption: 'Node 1', color: '#e04141' },
{ id: '2', caption: 'Node 2', color: '#e09c41' }
]
const relationships = [{ id: '12', from: '1', to: '2' }]
// Adds new nodes and relationships
nvl.addAndUpdateElementsInGraph(nodes, relationships)
// Updates an existing relationship
nvl.addAndUpdateElementsInGraph([], [{ id: '12', color: '#e0df41' }])
Adds nodes and relationships in the current scene.
The nodes to be added.
The relationships to be added.
Elements whose id already exists are skipped silently; use addAndUpdateElementsInGraph to add and update in one call.
De-selects all nodes and relationships.
Removes the graph visualization from the DOM and cleans up everything.
Updates pan and zoom to fit the specified nodes in the viewport.
The ids of the nodes to fit on the screen. Unknown ids are ignored; an empty array (or only unknown ids) does nothing. Pass every id to fit the whole graph.
OptionalzoomOptions: ZoomOptions
Specific options on how to transition the zoom.
Zoom is limited by ZoomOptions.minZoom / ZoomOptions.maxZoom and the minZoom / maxZoom / allowDynamicMinZoom options. See those for details.
Provides the container DOM element the graph is rendered in.
The container element of the NVL instance.
Gets the nodes, relationships, and clusters that have been hit by a pointer event.
The mouse event.
The graph elements to check for hits. Defaults to ['node', 'relationship', 'cluster'].
Options for the hit test. hitNodeMarginWidth widens the node hit area in layout units.
A NvlMouseEvent with the HitTargets property containing the nodes, relationships, and clusters that have been hit by the pointer event.
Clusters are hit when the pointer is inside a cluster hull, including over its nodes. This is the way to react to cluster hover; the hover interaction handler only reports nodes and relationships.
import { NVL } from '@neo4j-nvl/base'
const container = document.createElement('div')
const nvl = new NVL(container, [{ id: '0' }], [])
// Get the nodes and relationships that have been hit by a pointer event.
container.addEventListener('click', (evt) => {
const { nvlTargets } = nvl.getHits(evt)
console.log('clicked elements:', nvlTargets)
})
// Cluster hover
container.addEventListener('mousemove', (evt) => {
const cluster = nvl.getHits(evt, ['cluster']).nvlTargets.clusters[0]?.data
console.log('hovered cluster:', cluster?.id)
})
Returns the current view of the graph visualization canvas as a data URL.
The options for the image.
OptionalbackgroundColor?: stringThe background color of the data URL.
A data URL of the current view of the graph visualization canvas.
Returns all nodes that is currently stored in the visualisation.
Each node includes layout coordinates (x, y) and a clientPosition in screen space.
The array of nodes.
Returns the nodes that are currently in the visualization.
The rels property of the returned object is always empty.
An object containing the nodes and relationships in the visualization.
The nodes in the visualization.
The relationships in the visualization.
Returns the current pan of the viewport, in layout coordinates.
The layout-space point shown at the center of the container.
NodeWithClientPosition for the layout-to-screen formula.
Returns the node position that is currently stored in the visualisation for a given id.
The id of the node position that should be returned.
The position information for the given id, or undefined if there is no such node. or the layout has not yet run with that node.
Returns the relationship data that is currently stored in the visualisation for a given id.
The id of the relationship that should be returned.
The relationship or undefined if there is no relationship with the given id.
Returns the relationships that are currently in the visualization.
An array of the relationships in the visualization.
Get the current zoom level of the viewport.
The current zoom level.
NodeWithClientPosition for the layout-to-screen formula.
Gets the currently selected relationships.
An array of all currently selected relationships.
Experimental
Returns the entire graph visualization as an SVG data URL.
Options for the SVG export
OptionalbackgroundColor?: stringThe background color of the SVG (defaults to transparent).
A Promise resolving to a data URL string representing the graph as SVG (data:image/svg+xml;...)
import { NVL } from '@neo4j-nvl/base'
const nvl = new NVL(document.getElementById('frame'), [{ id: '0' }], [])
const renderSvg = async () => {
const svgDataUrl = await nvl.getSvgDataUrl({ backgroundColor: '#ffffff' })
const img = document.createElement('img')
img.src = svgDataUrl
document.body.appendChild(img)
}
Returns the effective zoom limits.
The current minZoom and maxZoom. minZoom can be lower than the configured
option when NvlOptions.allowDynamicMinZoom let the graph zoom out further.
The highest zoom level the graph can currently reach.
The lowest zoom level the graph can currently reach.
Checks and returns whether the current layout is still in flux.
Whether or not the layout is moving.
Pins the specified node so it is not affected by layout forces.
The id of the node to be pinned.
Removes the specified nodes from the current scene.
The node ids to be removed. Adjacent relationships will also be removed.
Removes the specified relationships from the current scene.
The relationship ids to be removed.
Resets the zoom of the viewport back to the default zoom level of 0.75.
Restarts the NVL instance.
New NvlOptions for the NVL instance.
Whether or not to retain the current node positions. New options will be merged with current options
Saves the entire graph visualization canvas as a png to the client.
The filename and background color of the png.
OptionalbackgroundColor?: stringThe background color of the png file. The size of the png file will be as large as the entire graph at the default zoom level. Can result in a very large file.
Optionalfilename?: stringThe filename of the png file.
Saves the current view of the graph visualization canvas as a png to the client.
The filename and background color of the png.
OptionalbackgroundColor?: stringThe background color of the png file. The size of the png file will be the size of the canvas in the DOM.
Optionalfilename?: stringThe filename of the png file.
Experimental
Saves the entire graph visualization as an SVG file to the client.
Options for the SVG export
OptionalbackgroundColor?: stringThe background color of the SVG file.
Optionalfilename?: stringThe filename of the SVG file.
Experimental
Restarts NVL with or without WebGL support.
Whether or not WebGL should be disabled.
Updates the configuration of the current layout.
The LayoutOptions configuration. Replaces the previous options.
Sets the node positions based on data provided.
The positions that the nodes should be set to.
Whether or not the current layout algorithm should update the graph after setting the node positions.
Ids that are not in the graph are skipped with a warning.
This is the way to position nodes; do not set x and y on the nodes passed to
addAndUpdateElementsInGraph or updateElementsInGraph.
For node positions to be unaffected by layout algorithms, use the 'free' layout type
or use pinNode to pin the nodes that should remain still.
Sets the zoom of the viewport to a specific value.
The desired panX value.
The desired panY value.
When updating both the zoom level and pan coordinates, use setZoomAndPan instead of calling setZoom and setPan separately to avoid jittering.
Switches between rendering methods
which rendering method to use
Sets the zoom of the viewport to a specific value.
The desired zoom level.
When updating both the zoom level and pan coordinates, use setZoomAndPan instead of calling setZoom and setPan separately to avoid jittering.
If the zoom level is outside of the range provided by the NvlOptions.minZoom and NvlOptions.maxZoom options, the zoom level will be set to the closest valid zoom level. If NvlOptions.allowDynamicMinZoom is set to true, the NvlOptions.minZoom option will be ignored of the current graph does not fit the viewport.
Sets the zoom and pan of the viewport to specific values.
The desired zoom level.
The desired panX value.
The desired panY value.
When only updating zoom level or pan coordinates, use setZoom or setPan instead.
If the zoom level is outside of the range provided by the NvlOptions.minZoom and NvlOptions.maxZoom options, the zoom level will be set to the closest valid zoom level. If NvlOptions.allowDynamicMinZoom is set to true, the NvlOptions.minZoom option will be ignored of the current graph does not fit the viewport.
Un-pins the specified nodes so they are affected by layout forces again.
The ids of the nodes to be un-pinned.
A settled force-directed layout does not restart on its own after un-pinning.
Call setNodePositions with updateLayout: true to wake it up.
Updates relationships in the current scene with the provided array of nodes and relationships.
The updated nodes.
The updated relationships. Ignores any nodes or relationships that do not exist in the current scene. To update nodes or relationships, they must have an id that matches the id of the node or relationship to be updated. Only the properties that are provided will be updated. If an existing property is not provided, it will not be changed.
Updating nodes and relationships
import { NVL } from '@neo4j-nvl/base'
const nodes = [{ id: '1' }, { id: '2' }]
const relationships = [{ id: '12', from: '1', to: '2' }]
const nvl = new NVL(document.getElementById('frame'), nodes, relationships)
// Updates an existing node and relationship
nvl.updateElementsInGraph([{ id: '1', selected: true }], [{ id: '12', color: '#e0df41' }])
Class for a NVL instance.
Example
This is a basic setup for a NVL instance.