@neo4j-nvl/base 2.0.0-ec6fdba7 → 2.1.0-307fceac

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 (42) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +5 -1
  3. package/dist/types/index.d.ts +62 -27
  4. package/dist/types/modules/ExternalCallbackHandler.d.ts +17 -4
  5. package/dist/types/modules/NvlController.d.ts +1 -1
  6. package/dist/types/modules/state/types.d.ts +20 -2
  7. package/dist/types/types/graph-element.d.ts +32 -15
  8. package/dist/types/types/nvl-window-functions.d.ts +16 -0
  9. package/dist/types/utils/hitTest.d.ts +3 -0
  10. package/dist/types/utils/jsDriverResultTransformer.d.ts +10 -0
  11. package/dist/types/utils/zoomFunctions.d.ts +1 -2
  12. package/package.json +3 -3
  13. package/skills/neo4j-nvl-skill/SKILL.md +13 -9
  14. package/skills/neo4j-nvl-skill/references/api/base/classes/NVL.md +76 -33
  15. package/skills/neo4j-nvl-skill/references/api/base/functions/getZoomTargetForNodePositions.md +1 -1
  16. package/skills/neo4j-nvl-skill/references/api/base/index.md +3 -2
  17. package/skills/neo4j-nvl-skill/references/api/base/interfaces/CircularOptions.md +1 -1
  18. package/skills/neo4j-nvl-skill/references/api/base/interfaces/ClusteringOptions.md +17 -0
  19. package/skills/neo4j-nvl-skill/references/api/base/interfaces/ExternalCallbacks.md +4 -4
  20. package/skills/neo4j-nvl-skill/references/api/base/interfaces/HierarchicalOptions.md +1 -1
  21. package/skills/neo4j-nvl-skill/references/api/base/interfaces/Node.md +5 -5
  22. package/skills/neo4j-nvl-skill/references/api/base/interfaces/NvlOptions.md +1 -1
  23. package/skills/neo4j-nvl-skill/references/api/base/interfaces/NvlWindow.md +18 -0
  24. package/skills/neo4j-nvl-skill/references/api/base/interfaces/Relationship.md +3 -3
  25. package/skills/neo4j-nvl-skill/references/api/base/type-aliases/HitTestTarget.md +2 -0
  26. package/skills/neo4j-nvl-skill/references/api/base/type-aliases/NodeWithClientPosition.md +10 -4
  27. package/skills/neo4j-nvl-skill/references/api/base/type-aliases/Renderer.md +3 -1
  28. package/skills/neo4j-nvl-skill/references/api/base/variables/nvlResultTransformer.md +11 -0
  29. package/skills/neo4j-nvl-skill/references/api/interaction-handlers/classes/HoverInteraction.md +6 -0
  30. package/skills/neo4j-nvl-skill/references/api/interaction-handlers/classes/PanInteraction.md +2 -1
  31. package/skills/neo4j-nvl-skill/references/api/interaction-handlers/classes/ZoomInteraction.md +5 -0
  32. package/skills/neo4j-nvl-skill/references/api/react/functions/StaticPictureWrapper.md +7 -0
  33. package/skills/neo4j-nvl-skill/references/api/react/index.md +2 -2
  34. package/skills/neo4j-nvl-skill/references/api/react/interfaces/BasicReactWrapperProps.md +3 -3
  35. package/skills/neo4j-nvl-skill/references/api/react/interfaces/InteractiveNvlWrapperProps.md +4 -4
  36. package/skills/neo4j-nvl-skill/references/api/react/type-aliases/KeyboardEvent.md +3 -0
  37. package/skills/neo4j-nvl-skill/references/api/react/type-aliases/MouseEventCallbacks.md +9 -0
  38. package/skills/neo4j-nvl-skill/references/api/react/variables/BasicNvlWrapper.md +16 -1
  39. package/skills/neo4j-nvl-skill/references/api/react/variables/InteractiveNvlWrapper.md +1 -0
  40. package/skills/neo4j-nvl-skill/references/labels-and-overlays.md +3 -1
  41. package/skills/neo4j-nvl-skill/references/layouts-and-positions.md +3 -3
  42. package/skills/neo4j-nvl-skill/references/react-wrappers.md +6 -2
package/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to NVL will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
4
4
 
5
- ## [Unreleased]
5
+ ## [2.1.0] - 2026-11-10
6
6
 
7
7
  This release adds keyboard actions for moving nodes, ships an agent skill for NVL, and makes all packages loadable as ESM in Node.js without a bundler.
8
8
 
@@ -24,6 +24,7 @@ This release adds keyboard actions for moving nodes, ships an agent skill for NV
24
24
  * `fit()` zooms out beyond `minZoom` when `allowDynamicMinZoom` is `true` and the graph does not fit the viewport.
25
25
  * `onHover` callback's `element` parameter is now typed as possibly `undefined`, matching the runtime behaviour.
26
26
  * Added missing caret for the React 18 peer dependency range in `@neo4j-nvl/react`.
27
+ * Several dependency updates
27
28
 
28
29
  ## [2.0.0] - 2026-09-15
29
30
 
package/README.md CHANGED
@@ -38,12 +38,16 @@ You can find more instructions and examples on how to use NVL in the [docs](http
38
38
 
39
39
  ### Agent skills
40
40
 
41
- This package ships an agent skill for NVL (`neo4j-nvl-skill`) that helps AI coding assistants write correct NVL code for the version you have installed. To make the skill available to your agent, run:
41
+ This package ships an agent skill for NVL (`neo4j-nvl-skill`) that helps AI coding assistants write correct NVL code for the version you have installed. `@neo4j-nvl/react` and `@neo4j-nvl/interaction-handlers` point to this skill as well. To make it available to your agent, run the following with a recent version of the `skills` CLI:
42
42
 
43
43
  ```bash
44
44
  npx skills experimental_sync
45
45
  ```
46
46
 
47
+ ### Debugging hooks
48
+
49
+ Every NVL instance registers read-only helpers on `window` for tests and tooling: `__Nvl_dumpNodes`, `__Nvl_dumpRelationships`, `__Nvl_getNodesOnScreen`, `__Nvl_getZoomLevel` and `__Nvl_registerDoneCallback`. Each takes the `instanceId` from `nvlOptions` (default `'default'`). See the `NvlWindow` type for details.
50
+
47
51
  ### Product analytics
48
52
 
49
53
  In order to improve the library we are collecting some information about the usage of NVL. If you prefer to disable this behavior set the parameter `disableTelemetry=true` as a parameter in `nvlOptions`.
@@ -2,8 +2,9 @@ import { Point } from "./utils/geometry.js";
2
2
  import { StyledCaption } from "./renderers/domrenderer/shared/types.js";
3
3
  import { Node, NodeWithClientPosition, PartialNode, PartialRelationship, Relationship } from "./types/graph-element.js";
4
4
  import { ExternalCallbacks } from "./modules/ExternalCallbackHandler.js";
5
- import { CanvasRendererType, CircularLayoutType, CircularOptions, Cluster, ClusterByFn, ClusterId, ClusteringOptions, ForceDirectedLayoutType, ForceDirectedOptions, FreeLayoutType, GridLayoutType, HierarchicalLayoutType, HierarchicalOptions, Layout, LayoutOptions, NvlOptions, NvlState, Renderer as Renderer$1, SvgRendererType, WebGLRendererType, ZoomOptions, d3ForceLayoutType } from "./modules/state/types.js";
5
+ import { CanvasRendererType, CircularLayoutType, CircularOptions, Cluster, ClusterByFn, ClusterId, ClusteringOptions, ForceDirectedLayoutType, ForceDirectedOptions, FreeLayoutType, GridLayoutType, HierarchicalLayoutType, HierarchicalOptions, Layout, LayoutOptions, NvlOptions, NvlState, WebGLRendererType, ZoomOptions, d3ForceLayoutType } from "./modules/state/types.js";
6
6
  import { drawCircleBand } from "./renderers/domrenderer/canvasrenderer/nodeDrawing.js";
7
+ import { NvlWindow } from "./types/nvl-window-functions.js";
7
8
  import { CompatibilityError } from "./utils/errors.js";
8
9
  import { HitTargetCluster, HitTargetNode, HitTargetRelationship, HitTargets, HitTestTarget } from "./utils/hitTest.js";
9
10
  import { nvlResultTransformer } from "./utils/jsDriverResultTransformer.js";
@@ -69,12 +70,10 @@ declare class NVL {
69
70
  * const nvl = new NVL(document.getElementById('frame'), [{ id: '0' }], [])
70
71
  *
71
72
  * const nodes = [
72
- * { id: '1', label: 'Node 1', color: '#e04141' },
73
- * { id: '2', label: 'Node 2', color: '#e09c41' }
74
- * ]
75
- * const relationships = [
76
- * { id: '12', from: '1', to: '2' }
73
+ * { id: '1', caption: 'Node 1', color: '#e04141' },
74
+ * { id: '2', caption: 'Node 2', color: '#e09c41' }
77
75
  * ]
76
+ * const relationships = [{ id: '12', from: '1', to: '2' }]
78
77
  * // Adds new nodes and relationships
79
78
  * nvl.addAndUpdateElementsInGraph(nodes, relationships)
80
79
  * // Updates an existing relationship
@@ -106,14 +105,10 @@ declare class NVL {
106
105
  * ```ts
107
106
  * import { NVL } from '@neo4j-nvl/base'
108
107
  *
109
- * const nodes = [
110
- * { id: '1', label: 'Node 1', color: '#e04141' },
111
- * { id: '2', label: 'Node 2', color: '#e09c41' }
112
- * ]
113
- * const relationships = [
114
- * { id: '12', from: '1', to: '2' }
115
- * ]
108
+ * const nodes = [{ id: '1' }, { id: '2' }]
109
+ * const relationships = [{ id: '12', from: '1', to: '2' }]
116
110
  * const nvl = new NVL(document.getElementById('frame'), nodes, relationships)
111
+ *
117
112
  * // Updates an existing node and relationship
118
113
  * nvl.updateElementsInGraph([{ id: '1', selected: true }], [{ id: '12', color: '#e0df41' }])
119
114
  * ```
@@ -123,6 +118,8 @@ declare class NVL {
123
118
  * Adds nodes and relationships in the current scene.
124
119
  * @param nodes - The nodes to be added.
125
120
  * @param relationships - The relationships to be added.
121
+ * @remarks Elements whose id already exists are skipped silently; use
122
+ * {@link addAndUpdateElementsInGraph} to add and update in one call.
126
123
  */
127
124
  addElementsToGraph(nodes: Node[], relationships: Relationship[]): void;
128
125
  /**
@@ -179,13 +176,24 @@ declare class NVL {
179
176
  deselectAll(): void;
180
177
  /**
181
178
  * Updates pan and zoom to fit the specified nodes in the viewport.
182
- * @param nodeIds - The ids of the nodes to fit on the screen.
179
+ * @param nodeIds - The ids of the nodes to fit on the screen. Unknown ids are ignored;
180
+ * an empty array (or only unknown ids) does nothing. Pass every id to fit the whole graph.
183
181
  * @param zoomOptions - Specific options on how to transition the zoom.
184
182
  *
185
183
  * @remarks
186
184
  * Zoom is limited by {@link ZoomOptions.minZoom} / {@link ZoomOptions.maxZoom} and the
187
185
  * {@link NvlOptions.minZoom minZoom} / {@link NvlOptions.maxZoom maxZoom} /
188
186
  * {@link NvlOptions.allowDynamicMinZoom allowDynamicMinZoom} options. See those for details.
187
+ * @example
188
+ * ```ts
189
+ * import { NVL } from '@neo4j-nvl/base'
190
+ *
191
+ * const nodes = [{ id: '1' }, { id: '2' }]
192
+ * const nvl = new NVL(document.getElementById('frame'), nodes, [])
193
+ *
194
+ * // Fit the whole graph
195
+ * nvl.fit(nodes.map((node) => node.id))
196
+ * ```
189
197
  */
190
198
  fit(nodeIds: string[], zoomOptions?: NvlState['zoomOptions']): void;
191
199
  /**
@@ -209,18 +217,22 @@ declare class NVL {
209
217
  */
210
218
  pinNode(nodeId: string): void;
211
219
  /**
212
- * Un-pins the specified nodes so it is affected by layout forces again.
213
- * @param nodeIds The ids of the nodes to be un-pinned.
220
+ * Un-pins the specified nodes so they are affected by layout forces again.
221
+ * @param nodeIds - The ids of the nodes to be un-pinned.
222
+ * @remarks A settled force-directed layout does not restart on its own after un-pinning.
223
+ * Call {@link setNodePositions} with `updateLayout: true` to wake it up.
214
224
  */
215
225
  unPinNode(nodeIds: string[]): void;
216
226
  /**
217
227
  * Changes the layout type.
218
228
  * @param layout - The {@link Layout} type.
229
+ * @remarks The layout is re-run only when the type actually changes. Calling this with the
230
+ * current layout type is a no-op.
219
231
  */
220
232
  setLayout(layout: Layout): void;
221
233
  /**
222
234
  * Updates the configuration of the current layout.
223
- * @param options - The {@link LayoutOptions} configuration.
235
+ * @param options - The {@link LayoutOptions} configuration. Replaces the previous options.
224
236
  */
225
237
  setLayoutOptions(options: LayoutOptions): void;
226
238
  /**
@@ -246,9 +258,11 @@ declare class NVL {
246
258
  * should update the graph after setting the node positions.
247
259
  *
248
260
  * @remarks
261
+ * Ids that are not in the graph are skipped with a warning.
262
+ * This is the way to position nodes; do not set `x` and `y` on the nodes passed to
263
+ * {@link addAndUpdateElementsInGraph} or {@link updateElementsInGraph}.
249
264
  * For node positions to be unaffected by layout algorithms, use the 'free' layout type
250
265
  * or use {@link pinNode} to pin the nodes that should remain still.
251
- * False by default.
252
266
  */
253
267
  setNodePositions(data: Node[], updateLayout?: boolean): void;
254
268
  /**
@@ -295,10 +309,11 @@ declare class NVL {
295
309
  * @experimental
296
310
  *
297
311
  * @example
298
- * ```typescript
312
+ * ```ts
299
313
  * import { NVL } from '@neo4j-nvl/base'
300
314
  *
301
315
  * const nvl = new NVL(document.getElementById('frame'), [{ id: '0' }], [])
316
+ *
302
317
  * const renderSvg = async () => {
303
318
  * const svgDataUrl = await nvl.getSvgDataUrl({ backgroundColor: '#ffffff' })
304
319
  * const img = document.createElement('img')
@@ -322,8 +337,15 @@ declare class NVL {
322
337
  filename?: string;
323
338
  backgroundColor?: string;
324
339
  }): void;
340
+ /**
341
+ * Returns the effective zoom limits.
342
+ * @returns The current `minZoom` and `maxZoom`. `minZoom` can be lower than the configured
343
+ * option when {@link NvlOptions.allowDynamicMinZoom} let the graph zoom out further.
344
+ */
325
345
  getZoomLimits(): {
346
+ /** The lowest zoom level the graph can currently reach. */
326
347
  minZoom: number;
348
+ /** The highest zoom level the graph can currently reach. */
327
349
  maxZoom: number;
328
350
  };
329
351
  /**
@@ -367,31 +389,44 @@ declare class NVL {
367
389
  /**
368
390
  * Get the current zoom level of the viewport.
369
391
  * @returns The current zoom level.
392
+ * @see {@link NodeWithClientPosition} for the layout-to-screen formula.
370
393
  */
371
394
  getScale(): number;
372
395
  /**
373
- * Returns the current pan of the viewport.
374
- * @returns The current pan of the viewport.
396
+ * Returns the current pan of the viewport, in layout coordinates.
397
+ * @returns The layout-space point shown at the center of the container.
398
+ * @see {@link NodeWithClientPosition} for the layout-to-screen formula.
375
399
  */
376
400
  getPan(): Point;
377
401
  /**
378
402
  * Gets the nodes, relationships, and clusters that have been hit by a pointer event.
379
403
  * @param evt - The mouse event.
380
404
  * @param targets - The graph elements to check for hits. Defaults to ['node', 'relationship', 'cluster'].
381
- * @param hitOptions - Options for the hit test.
405
+ * @param hitOptions - Options for the hit test. `hitNodeMarginWidth` widens the node hit area in layout units.
382
406
  * @returns A {@link NvlMouseEvent} with the {@link HitTargets} property
383
407
  * containing the nodes, relationships, and clusters that have been hit by the pointer event.
384
408
  *
409
+ * @remarks Clusters are hit when the pointer is inside a cluster hull, including over its nodes.
410
+ * This is the way to react to cluster hover; the hover interaction handler only reports nodes and relationships.
411
+ *
385
412
  * @example
386
- * ```js
387
- * const container = document.getElementById('frame')
413
+ * ```ts
414
+ * import { NVL } from '@neo4j-nvl/base'
415
+ *
416
+ * const container = document.createElement('div')
388
417
  * const nvl = new NVL(container, [{ id: '0' }], [])
389
418
  *
390
419
  * // Get the nodes and relationships that have been hit by a pointer event.
391
- * container?.addEventListener('click', (evt) => {
420
+ * container.addEventListener('click', (evt) => {
392
421
  * const { nvlTargets } = nvl.getHits(evt)
393
422
  * console.log('clicked elements:', nvlTargets)
394
423
  * })
424
+ *
425
+ * // Cluster hover
426
+ * container.addEventListener('mousemove', (evt) => {
427
+ * const cluster = nvl.getHits(evt, ['cluster']).nvlTargets.clusters[0]?.data
428
+ * console.log('hovered cluster:', cluster?.id)
429
+ * })
395
430
  * ```
396
431
  */
397
432
  getHits(evt: MouseEvent, targets?: HitTestTarget[], hitOptions?: {
@@ -415,5 +450,5 @@ declare const colorMapperFunctions: {
415
450
  /**
416
451
  * The different types of renderers available
417
452
  */
418
- type Renderer = Exclude<Renderer$1, typeof SvgRendererType>;
419
- export { type CanvasRendererType, CircularLayoutType, type CircularOptions, type Cluster, type ClusterByFn, type ClusterId, type ClusteringOptions, CompatibilityError, type ExternalCallbacks, ForceDirectedLayoutType, type ForceDirectedOptions, FreeLayoutType, GridLayoutType, HierarchicalLayoutType, type HierarchicalOptions, type HitTargetCluster, type HitTargetNode, type HitTargetRelationship, type HitTargets, type HitTestTarget, type Layout, type LayoutOptions, NVL, NVL as default, type Node, type NodeWithClientPosition, type NvlMouseEvent, type NvlOptions, type PartialNode, type PartialRelationship, type Point, type Relationship, type Renderer, type StyledCaption, type WebGLRendererType, type ZoomOptions, colorMapperFunctions, d3ForceLayoutType, drawCircleBand, getZoomTargetForNodePositions, nvlResultTransformer };
453
+ type Renderer = typeof WebGLRendererType | typeof CanvasRendererType;
454
+ export { type CanvasRendererType, CircularLayoutType, type CircularOptions, type Cluster, type ClusterByFn, type ClusterId, type ClusteringOptions, CompatibilityError, type ExternalCallbacks, ForceDirectedLayoutType, type ForceDirectedOptions, FreeLayoutType, GridLayoutType, HierarchicalLayoutType, type HierarchicalOptions, type HitTargetCluster, type HitTargetNode, type HitTargetRelationship, type HitTargets, type HitTestTarget, type Layout, type LayoutOptions, NVL, NVL as default, type Node, type NodeWithClientPosition, type NvlMouseEvent, type NvlOptions, type NvlWindow, type PartialNode, type PartialRelationship, type Point, type Relationship, type Renderer, type StyledCaption, type WebGLRendererType, type ZoomOptions, colorMapperFunctions, d3ForceLayoutType, drawCircleBand, getZoomTargetForNodePositions, nvlResultTransformer };
@@ -3,15 +3,28 @@ import { NodeWithClientPosition } from "../types/graph-element.js";
3
3
  * An object specifying the required callback functions for certain actions
4
4
  */
5
5
  export interface ExternalCallbacks {
6
- /** Triggered when a layout is done moving. */
6
+ /**
7
+ * Triggered when a layout is done moving.
8
+ * Fires again after every change that re-runs the layout (added or removed elements, layout switch).
9
+ */
7
10
  onLayoutDone?: () => void;
8
- /** Triggered on each step of a layout. */
11
+ /**
12
+ * Triggered on each step of a layout with the current node positions.
13
+ * @remarks Can have a large performance footprint. Prefer {@link onLayoutDone} and
14
+ * {@link NVL.getNodes} unless per-frame positions are needed.
15
+ */
9
16
  onLayoutStep?: (p: NodeWithClientPosition[]) => void;
10
- /** Triggered when NVL throws an error after initialization. */
17
+ /**
18
+ * Triggered when NVL throws an error after initialization.
19
+ * @remarks Constructor errors are thrown, not reported here.
20
+ */
11
21
  onError?: (error: Error) => void;
12
22
  /** Triggered when NVL is initialized. */
13
23
  onInitialization?: () => void;
14
- /** Triggered when a asynchronous layout calculation starts/stops. */
24
+ /**
25
+ * Triggered when an asynchronous layout calculation starts (`true`) and stops (`false`).
26
+ * Not triggered by iterative layouts (e.g. force-directed).
27
+ */
15
28
  onLayoutComputing?: (isComputing: boolean) => void;
16
29
  /**
17
30
  * Triggered when the WebGL context is lost.
@@ -2,10 +2,10 @@ import { Point } from "../utils/geometry.js";
2
2
  import { Node, NodeWithClientPosition, PartialNode, PartialRelationship, Relationship } from "../types/graph-element.js";
3
3
  import { ExternalCallbacks } from "./ExternalCallbackHandler.js";
4
4
  import { Layout, LayoutOptions, NvlOptions, NvlState, ZoomOptions } from "./state/types.js";
5
+ import "../types/nvl-window-functions.js";
5
6
  import { ClusterHitRegion } from "../utils/clusterHitRegions.js";
6
7
  import { HitTargetNode, HitTargetRelationship } from "../utils/hitTest.js";
7
8
  import "../index.js";
8
- import "../types/nvl-window-functions.js";
9
9
  type SaveToFileOptions = {
10
10
  filename?: string;
11
11
  backgroundColor?: string;
@@ -55,6 +55,19 @@ export type Cluster = {
55
55
  export type ClusterByFn = (nodeId: string) => ClusterId | undefined;
56
56
  /**
57
57
  * Options that control physical clustering and cluster decorations for the force-directed layout.
58
+ * @remarks
59
+ * Only used by the `'forceDirected'` layout. The hierarchical layout has its own
60
+ * {@link HierarchicalOptions.clusterBy} without decorations.
61
+ * Clusters can be clicked and hit-tested (see {@link NVL.getHits}), but are not hoverable elements.
62
+ * @example
63
+ * ```ts
64
+ * import { NVL } from '@neo4j-nvl/base'
65
+ *
66
+ * const nvl = new NVL(document.getElementById('frame'), [{ id: 'a:1' }, { id: 'a:2' }], [])
67
+ *
68
+ * const clusterBy = (nodeId: string) => nodeId.split(':')[0]
69
+ * nvl.setLayoutOptions({ clustering: { clusterBy, drawOutline: true } })
70
+ * ```
58
71
  */
59
72
  export interface ClusteringOptions {
60
73
  /**
@@ -139,7 +152,8 @@ export interface HierarchicalOptions {
139
152
  * Nodes returning the same string or number will be grouped together in the layout via
140
153
  * dagre compound subgraphs. Nodes returning undefined will be treated as independent.
141
154
  *
142
- * @remarks Ensure this function has a stable reference to avoid evaluation on every render.
155
+ * @remarks No outline or halo is drawn (only present for the `'forceDirected'` layout via {@link ClusteringOptions}).
156
+ * Ensure this function has a stable reference to avoid evaluation on every render.
143
157
  *
144
158
  * @experimental
145
159
  */
@@ -151,7 +165,9 @@ export declare const isHierarchicalLayoutOptions: (options: LayoutOptions) => op
151
165
  */
152
166
  export interface CircularOptions {
153
167
  /**
154
- * Function which should return the sorted nodes.
168
+ * Function which should return the sorted nodes. Nodes are placed around the circle in the returned order.
169
+ * @remarks Changing this via {@link NVL.setLayoutOptions} does not re-run the layout on its own.
170
+ * Switch to another layout and back with {@link NVL.setLayout}, or call {@link NVL.restart}, to re-place nodes.
155
171
  */
156
172
  sortFunction?: (nodes: Node[]) => Node[];
157
173
  }
@@ -343,6 +359,8 @@ export interface NvlOptions {
343
359
  disableTelemetry?: boolean;
344
360
  /**
345
361
  * Disables the use of {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers | web workers} for the layout calculations.
362
+ * @remarks Only the hierarchical layout uses a worker (a `SharedWorker` from `@neo4j-nvl/layout-workers`).
363
+ * If the worker cannot be created, NVL logs a warning and attempts to fall back to synchronous layout automatically.
346
364
  */
347
365
  disableWebWorkers?: boolean;
348
366
  /**
@@ -18,10 +18,12 @@ interface GraphElement {
18
18
  /** Whether or not the current node or relationship is selected.*/
19
19
  selected?: boolean;
20
20
  /**
21
- * The text to display inside on node or relationship.
22
- * @note: If both caption and captions are provided, captions takes precedence.
23
- * @note: To provide multiple captions with custom styles, use the {@link captions} property.
24
- * @note: Captions are only visible when using the 'canvas' renderer.
21
+ * The text to display on the node or relationship.
22
+ * @remarks
23
+ * If both `caption` and {@link captions} are provided, `captions` takes precedence.
24
+ * To provide multiple captions with custom styles, use the {@link captions} property.
25
+ * Captions are only visible when using the 'canvas' renderer.
26
+ * @see {@link Node.html} and {@link Node.icon} for labelling nodes with the WebGL renderer.
25
27
  */
26
28
  caption?: string;
27
29
  /** Whether or not the current node or relationship is disabled.*/
@@ -36,14 +38,14 @@ interface GraphElement {
36
38
  */
37
39
  captionAlign?: 'top' | 'bottom' | 'center';
38
40
  /**
39
- * The caption text and font styles.
40
- * @note: To provide a single caption without custom styles, you can also use the {@link caption} property.
41
- * @note: Captions are only visible when using the 'canvas' renderer.
41
+ * Multiple captions with individual text styles.
42
+ * @remarks
43
+ * Only drawn by the `'canvas'` renderer. For a single unstyled caption use {@link caption}.
42
44
  */
43
45
  captions?: StyledCaption[];
44
46
  /**
45
47
  * An icon to be displayed anywhere on top of the graph element.
46
- * Icons are expected to be square.
48
+ * Icons are expected to be square. Works with both renderers.
47
49
  */
48
50
  overlayIcon?: {
49
51
  /** The url to the icon.*/
@@ -75,34 +77,49 @@ interface Node extends GraphElement {
75
77
  pinned?: boolean;
76
78
  /**
77
79
  * @ignore
78
- * The x-coordinate for the position of the node.
80
+ * Do not set this. Node positions are owned by the layout; move nodes with
81
+ * {@link NVL.setNodePositions} (or the `positions` prop of the React wrappers).
82
+ * Kept for internal use and slated for removal.
79
83
  */
80
84
  x?: number;
81
85
  /**
82
86
  * @ignore
83
- * The y-coordinate for the position of the node.
87
+ * Do not set this. Node positions are owned by the layout; move nodes with
88
+ * {@link NVL.setNodePositions} (or the `positions` prop of the React wrappers).
89
+ * Kept for internal use and slated for removal.
84
90
  */
85
91
  y?: number;
86
92
  /** Whether or not the current node is activated.*/
87
93
  activated?: boolean;
88
94
  /**
89
95
  * The url to an icon to display inside the node.
90
- * Icons are expected to be black. If the node's background color is dark,
91
- * the icon will be inverted to white.
92
- * Icons are expected to be square.
96
+ * Icons are expected to be black and square. If the node's background color is dark,
97
+ * the icon will be inverted to white. Works with both renderers.
98
+ * @remarks
99
+ * The WebGL renderer keeps at most 256 distinct icon images (per url and inverted/not inverted);
100
+ * icons beyond that are not drawn and no warning is logged. The canvas renderer has no such cap.
101
+ * Keep the set of distinct icon urls small.
93
102
  */
94
103
  icon?: string;
95
104
  /**
96
- * The DOM element to display on top of a node.
105
+ * The DOM element to display on top of a node. Positioned by NVL on every frame.
97
106
  * @experimental
107
+ * @remarks
108
+ * Any HTML overlay disables the WebGL renderer's GPU fast path because node positions must be
109
+ * available on the CPU every frame. Prefer {@link icon} or {@link overlayIcon} for many nodes.
98
110
  */
99
111
  html?: HTMLElement;
100
112
  }
101
113
  /**
102
114
  * A node returned by {@link NVL.getNodes} with layout coordinates and screen position.
103
- * `x` and `y` are canvas/layout space; `clientPosition` is relative to the canvas element.
115
+ * `x` and `y` are layout space; `clientPosition` is in CSS pixels relative to the top-left
116
+ * corner of the container.
117
+ * @remarks
118
+ * `clientPosition = ((x, y) - pan) * zoom / devicePixelRatio + containerSize / 2`,
119
+ * with `pan` from {@link NVL.getPan} and `zoom` from {@link NVL.getScale}.
104
120
  */
105
121
  type NodeWithClientPosition = Node & Point & {
122
+ /** Screen position in CSS pixels, relative to the top-left corner of the container. */
106
123
  clientPosition: Point;
107
124
  };
108
125
  /**
@@ -1,12 +1,28 @@
1
1
  import { Node, NodeWithClientPosition, Relationship } from "./graph-element.js";
2
+ /**
3
+ * Read-only debugging hooks that every NVL instance registers on `window`, for tests and tooling
4
+ * that cannot reach the NVL object. Hooks exist from the first instance's construction and stay on
5
+ * `window` after it is destroyed. `instanceId` is the {@link NvlOptions.instanceId} given to NVL
6
+ * (default `'default'`); an unknown id falls back to the most recently created instance.
7
+ */
2
8
  export interface NvlWindow {
9
+ /** Same as {@link NVL.getNodes}: all nodes with layout coordinates and `clientPosition`. */
3
10
  __Nvl_dumpNodes: (instanceId?: string) => NodeWithClientPosition[];
11
+ /** Same as {@link NVL.getRelationships}. */
4
12
  __Nvl_dumpRelationships: (instanceId?: string) => Relationship[];
13
+ /** Same as {@link NVL.getNodesOnScreen}: nodes inside the viewport; `rels` is always empty. */
5
14
  __Nvl_getNodesOnScreen: (instanceId?: string) => {
15
+ /** Nodes whose position is inside the viewport. */
6
16
  nodes: Node[];
17
+ /** Always empty; kept for shape compatibility. */
7
18
  rels: Relationship[];
8
19
  };
20
+ /**
21
+ * Adds a listener for {@link ExternalCallbacks.onLayoutDone}. Called on every layout completion,
22
+ * not just the first; listeners cannot be removed.
23
+ */
9
24
  __Nvl_registerDoneCallback: (cb: () => void, instanceId: string) => void;
25
+ /** Same as {@link NVL.getScale}. */
10
26
  __Nvl_getZoomLevel: (instanceId?: string) => number;
11
27
  }
12
28
  declare global {
@@ -57,6 +57,9 @@ export type HitTargets = {
57
57
  /** The cluster hulls that have been hit by the pointer event. */
58
58
  clusters: HitTargetCluster[];
59
59
  };
60
+ /**
61
+ * The kinds of element {@link NVL.getHits} can test for.
62
+ */
60
63
  export type HitTestTarget = 'node' | 'relationship' | 'cluster';
61
64
  /**
62
65
  * Finds all cluster hulls that contain the given point.
@@ -13,6 +13,16 @@ export declare const recordCollector: (graphElements: NestedGraphElements[]) =>
13
13
  };
14
14
  /**
15
15
  * Result transformer for the Neo4j JavaScript driver results to NVL graph elements.
16
+ *
17
+ * Collects every node, relationship and path (including nested lists) from all record fields and returns
18
+ * - `nodes`: `{ id: elementId }` per node, no labels, properties or captions,
19
+ * - `relationships`: `{ id, from, to }` per relationship using element ids,
20
+ * - `recordObjectMap`: `Map<elementId, driver Node | Relationship>` for looking up labels and properties.
21
+ *
22
+ * @remarks Nodes and relationships returned by several records appear several times in the arrays. NVL
23
+ * deduplicates by id when adding them, so this only matters if the arrays are processed before that.
24
+ * Driver `Integer` values are not converted; use `toNumber()` or `toString()` before putting them in captions.
25
+ *
16
26
  * @example
17
27
  *
18
28
  * ```ts
@@ -47,8 +47,7 @@ declare const createZoomTarget: (zoomX: number, zoomY: number, minZoom?: number,
47
47
  * @param nodePositions - The node positions.
48
48
  * @param containerWidth - The width of the container NVL is displayed in.
49
49
  * @param containerHeight - The height of the container NVL is displayed in.
50
- * @param maxNodeRadius - The maximum node radius, which is added as margin to the scene
51
- * (defaults to 2 * {@link DefaultNodeSize}).
50
+ * @param maxNodeRadius - The maximum node radius, used to pad the scene (defaults to `50`).
52
51
  * @returns The zoom and pan targets.
53
52
  */
54
53
  declare const getZoomTargetForNodePositions: (nodePositions: Point[], containerWidth: number, containerHeight: number, maxNodeRadius?: number) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/base",
3
- "version": "2.0.0-ec6fdba7",
3
+ "version": "2.1.0-307fceac",
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",
@@ -33,7 +33,7 @@
33
33
  "postpack": "rm LICENSE.txt && rm CHANGELOG.md"
34
34
  },
35
35
  "dependencies": {
36
- "@neo4j-nvl/layout-workers": "2.0.0-ec6fdba7",
36
+ "@neo4j-nvl/layout-workers": "2.1.0-307fceac",
37
37
  "@segment/analytics-next": "1.84.3",
38
38
  "color-string": "1.9.1",
39
39
  "d3-force": "3.0.0",
@@ -59,5 +59,5 @@
59
59
  "peerDependencies": {
60
60
  "neo4j-driver": "*"
61
61
  },
62
- "stableVersion": "2.0.0"
62
+ "stableVersion": "2.1.0"
63
63
  }
@@ -2,7 +2,7 @@
2
2
  name: neo4j-nvl-skill
3
3
  metadata:
4
4
  package: '@neo4j-nvl/base'
5
- version: '2.0.0-ec6fdba7'
5
+ version: '2.1.0-307fceac'
6
6
  description: Neo4j Visualization Library (NVL) — framework-agnostic graph rendering for the browser.
7
7
  Covers @neo4j-nvl/base (NVL class, nodes/relationships, Canvas vs WebGL renderer),
8
8
  @neo4j-nvl/interaction-handlers (zoom, pan, drag, click, hover, box/lasso select, keyboard) and
@@ -20,7 +20,7 @@ compatibility: '@neo4j-nvl packages 2.x; React 19 for @neo4j-nvl/react; browsers
20
20
 
21
21
  # Neo4j Visualization Library (@neo4j-nvl/base)
22
22
 
23
- > Shipped with `@neo4j-nvl/base` v2.0.0-ec6fdba7. Once installed into a project this folder is detached from the
23
+ > Shipped with `@neo4j-nvl/base` v2.1.0-307fceac. Once installed into a project this folder is detached from the
24
24
  > package: the installed types in `node_modules/@neo4j-nvl/*` are the source of truth. If the project's
25
25
  > `@neo4j-nvl/base` is a different version and `node_modules/@neo4j-nvl/base/skills/neo4j-nvl-skill/SKILL.md`
26
26
  > exists, read that copy instead.
@@ -55,6 +55,9 @@ NVL for that), Python notebooks (`neo4j/python-graph-visualization`), Cypher, dr
55
55
  8. React: `nvlCallbacks` are captured once; use refs or stable functions. `interactionOptions` replaces
56
56
  the defaults, so pass every option you need.
57
57
  9. Destroy interaction handlers, then `nvl.destroy()`, on teardown. The React wrappers do this for you.
58
+ 10. `updateCallback(name, cb)` on interaction handlers is untyped: `cb` is `(...args: unknown[]) => void`, so
59
+ parameters arrive as `unknown` and a typed callback such as `(node: Node) => …` fails under `strict`. Cast
60
+ inside the callback; the React `mouseEventCallbacks` are fully typed.
58
61
 
59
62
  ## Symptom → cause → fix
60
63
 
@@ -71,11 +74,11 @@ NVL for that), Python notebooks (`neo4j/python-graph-visualization`), Cypher, dr
71
74
  | Pinned nodes move when clustering is on | Cluster forces ignore pins | Do not combine → [clustering](references/clustering.md) |
72
75
  | Changing circle options does nothing | Layout is not re-run on option change | Bounce via `setLayout('free')` → [layouts-and-positions](references/layouts-and-positions.md) |
73
76
  | Un-pinned nodes stay frozen | Settled simulation is not restarted | `setNodePositions(current, true)` → [layouts-and-positions](references/layouts-and-positions.md) |
74
- | Node `x`/`y` props do not move existing nodes | Positions apply on insert only | `setNodePositions` → [layouts-and-positions](references/layouts-and-positions.md) |
77
+ | 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](references/layouts-and-positions.md) |
75
78
  | Callbacks see stale state (React) | `nvlCallbacks` captured at creation | Refs or stable functions → [react-wrappers](references/react-wrappers.md) |
76
79
  | Minimap empty (React) | Container did not exist at creation | Keep the element in state → [react-wrappers](references/react-wrappers.md) |
77
80
  | Hover / shadow defaults lost | `interactionOptions` replaces defaults | Pass every option → [react-wrappers](references/react-wrappers.md) |
78
- | Many icons not drawn | Too many distinct icon images | Fewer distinct icons → [labels-and-overlays](references/labels-and-overlays.md) |
81
+ | Many icons not drawn (WebGL) | More than 256 distinct icon images | Fewer distinct icons, or `'canvas'` → [labels-and-overlays](references/labels-and-overlays.md) |
79
82
  | Layout looks hung in headless Chrome | Software WebGL | Hardware-GL flags → [verifying-nvl-apps](references/verifying-nvl-apps.md) |
80
83
  | Raw `executeQuery` result passed to NVL | Records are not graph elements | `resultTransformer: nvlResultTransformer` → [data-from-neo4j](references/data-from-neo4j.md) |
81
84
 
@@ -122,9 +125,9 @@ const rels = [{ id: '12', from: '1', to: '2', type: 'KNOWS' }]
122
125
  const nvl = new NVL(container, nodes, rels, { layout: 'forceDirected' }, {
123
126
  onLayoutDone: () => nvl.fit(nodes.map((n) => n.id))
124
127
  })
125
- const handlers = [new ZoomInteraction(nvl), new PanInteraction(nvl), new DragNodeInteraction(nvl),
126
- new ClickInteraction(nvl, { selectOnClick: true })]
127
- handlers[3].updateCallback('onNodeClick', (node) => console.log(node.id))
128
+ const click = new ClickInteraction(nvl, { selectOnClick: true })
129
+ click.updateCallback('onNodeClick', (node) => console.log('clicked', node))
130
+ const handlers = [click, new ZoomInteraction(nvl), new PanInteraction(nvl), new DragNodeInteraction(nvl)]
128
131
  // teardown: handlers.forEach((h) => h.destroy()); nvl.destroy()
129
132
  ```
130
133
 
@@ -200,6 +203,7 @@ NVL class, options, callbacks, graph element types, hit testing, nvlResultTransf
200
203
  - [Node](references/api/base/interfaces/Node.md) — A node inside the graph visualization.
201
204
  - [NvlMouseEvent](references/api/base/interfaces/NvlMouseEvent.md) — The result of a NVL.getHits call.
202
205
  - [NvlOptions](references/api/base/interfaces/NvlOptions.md) — Configurations for a NVL instance
206
+ - [NvlWindow](references/api/base/interfaces/NvlWindow.md) — Read-only debugging hooks that every NVL instance registers on `window`, for tests and tooling
203
207
  - [Point](references/api/base/interfaces/Point.md) — An object representing a point in 2D space.
204
208
  - [Relationship](references/api/base/interfaces/Relationship.md) — A relationship inside the graph visualization.
205
209
 
@@ -210,7 +214,7 @@ NVL class, options, callbacks, graph element types, hit testing, nvlResultTransf
210
214
  - [ClusterByFn](references/api/base/type-aliases/ClusterByFn.md) — Function that maps a node id to a ClusterId for force-directed clustering.
211
215
  - [ClusterId](references/api/base/type-aliases/ClusterId.md) — Identifier returned by ClusterByFn to group nodes into physical clusters.
212
216
  - [HitTargets](references/api/base/type-aliases/HitTargets.md) — A collection of nodes, relationships and clusters that have been hit by a pointer event
213
- - [HitTestTarget](references/api/base/type-aliases/HitTestTarget.md)
217
+ - [HitTestTarget](references/api/base/type-aliases/HitTestTarget.md) — The kinds of element NVL.getHits can test for.
214
218
  - [Layout](references/api/base/type-aliases/Layout.md) — The different types of layouts available
215
219
  - [LayoutOptions](references/api/base/type-aliases/LayoutOptions.md) — The options for the layout.
216
220
  - [NodeWithClientPosition](references/api/base/type-aliases/NodeWithClientPosition.md) — A node returned by NVL.getNodes with layout coordinates and screen position.
@@ -281,7 +285,7 @@ InteractiveNvlWrapper, BasicNvlWrapper, StaticPictureWrapper and their props.
281
285
  **Types**
282
286
 
283
287
  - [InteractionOptions](references/api/react/type-aliases/InteractionOptions.md) — Collection of interaction options that can be used with
284
- - [KeyboardEvent](references/api/react/type-aliases/KeyboardEvent.md)
288
+ - [KeyboardEvent](references/api/react/type-aliases/KeyboardEvent.md) — The events that can be passed to the KeyboardEventCallbacks object
285
289
  - [KeyboardEventCallbacks](references/api/react/type-aliases/KeyboardEventCallbacks.md) — Collection of keyboard event callbacks that can be used with
286
290
  - [MouseEvent](references/api/react/type-aliases/MouseEvent.md) — The events that can be passed to the MouseEventCallbacks object
287
291
  - [MouseEventCallbacks](references/api/react/type-aliases/MouseEventCallbacks.md) — Collection of mouse event callbacks that can be used with