@neo4j-nvl/react 1.0.0-b6554465 → 1.0.0-bb8a655f

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/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
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
+ ## [1.1.0] - 2026-02-16
6
+
7
+ This 1.1.0 release introduces new rendering capabilities with the addition of a new SVG export method, alongside a new Circular Layout algorithm and touchpad gestures for zooming. It also includes performance improvements for the renderer and physics engine, as well as various fixes for the React wrappers and Minimap.
8
+
9
+ ### Added
10
+
11
+ - new SVG export functionality.
12
+ - new circular layout option.
13
+ - two-finger pinch gesture to zoom with touchpads.
14
+ - onCanvasDoubleClick callback to the interactive NVL React wrapper.
15
+
16
+ ### Changed
17
+
18
+ - improved minimap handling for React components.
19
+ - rendering performance improvements.
20
+ - physics layout performance and gravity improvements.
21
+
22
+ ### Fixed
23
+
24
+ - seed radius calculation in D3 layout for large graphs.
25
+ - forceDirected layout unnecessarily reheating on switch without changes.
26
+ - ensure drag operations are always correctly ended on mouse up.
27
+ - minimap positioning issues.
28
+ - background color for the 'os' theme in api documentation.
29
+
5
30
  ## [1.0.0] - 2025-09-30
6
31
  This 1.0.0 release is our first major release, with NVL's release strategy fully adopting semantic versioning going forward. Updates in this release include React 19 support for the React wrappers, a UI overhaul of the [examples app](https://neo4j.com/docs/api/nvl/current/examples.html).
7
32
 
@@ -7,6 +7,17 @@ import { BasicNvlWrapper } from '../basic-wrapper/BasicNvlWrapper';
7
7
  jest.mock('@neo4j-nvl/base');
8
8
  jest.mock('@neo4j-nvl/layout-workers');
9
9
  describe('BasicNvlWrapper', () => {
10
+ let setZoom;
11
+ let setPan;
12
+ let setZoomAndPan;
13
+ beforeEach(() => {
14
+ setZoom = jest.fn();
15
+ setPan = jest.fn();
16
+ setZoomAndPan = jest.fn();
17
+ jest.spyOn(NVL.prototype, 'setZoom').mockImplementation(setZoom);
18
+ jest.spyOn(NVL.prototype, 'setPan').mockImplementation(setPan);
19
+ jest.spyOn(NVL.prototype, 'setZoomAndPan').mockImplementation(setZoomAndPan);
20
+ });
10
21
  afterEach(() => {
11
22
  jest.clearAllMocks();
12
23
  });
@@ -37,33 +48,78 @@ describe('BasicNvlWrapper', () => {
37
48
  expect(destroy).toHaveBeenCalledTimes(1);
38
49
  });
39
50
  test('calls setZoom when zoom property is provided', () => {
40
- const setZoom = jest.fn();
41
- jest.spyOn(NVL.prototype, 'setZoom').mockImplementation(setZoom);
42
51
  render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5 }) }));
43
52
  expect(setZoom).toHaveBeenCalledWith(1.5);
53
+ expect(setZoom).toHaveBeenCalledTimes(1);
44
54
  });
45
55
  test('calls setPan when pan property is provided', () => {
46
- const setPan = jest.fn();
47
- jest.spyOn(NVL.prototype, 'setPan').mockImplementation(setPan);
48
56
  render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], pan: { x: 10, y: 20 } }) }));
49
57
  expect(setPan).toHaveBeenCalledWith(10, 20);
58
+ expect(setPan).toHaveBeenCalledTimes(1);
50
59
  });
51
60
  test('calls setZoomAndPan when both zoom and pan properties are provided', () => {
52
- const setZoomAndPan = jest.fn();
53
- jest.spyOn(NVL.prototype, 'setZoomAndPan').mockImplementation(setZoomAndPan);
54
61
  render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5, pan: { x: 10, y: 20 } }) }));
55
62
  expect(setZoomAndPan).toHaveBeenCalledWith(1.5, 10, 20);
63
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
56
64
  });
57
65
  test('does not call zoom/pan methods when properties are undefined', () => {
58
- const setZoom = jest.fn();
59
- jest.spyOn(NVL.prototype, 'setZoom').mockImplementation(setZoom);
60
- const setPan = jest.fn();
61
- jest.spyOn(NVL.prototype, 'setPan').mockImplementation(setPan);
62
- const setZoomAndPan = jest.fn();
63
- jest.spyOn(NVL.prototype, 'setZoomAndPan').mockImplementation(setZoomAndPan);
64
66
  render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [] }) }));
65
67
  expect(setZoom).not.toHaveBeenCalled();
66
68
  expect(setPan).not.toHaveBeenCalled();
67
69
  expect(setZoomAndPan).not.toHaveBeenCalled();
68
70
  });
71
+ test('only calls setZoom when zoom changes', () => {
72
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5 }) }));
73
+ expect(setZoom).toHaveBeenCalledTimes(1);
74
+ expect(setZoom).toHaveBeenCalledWith(1.5);
75
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5 }) }));
76
+ expect(setZoom).toHaveBeenCalledTimes(1);
77
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 2.0 }) }));
78
+ expect(setZoom).toHaveBeenCalledTimes(2);
79
+ expect(setZoom).toHaveBeenCalledWith(2.0);
80
+ expect(setPan).not.toHaveBeenCalled();
81
+ expect(setZoomAndPan).not.toHaveBeenCalled();
82
+ });
83
+ test('only calls setPan when pan changes', () => {
84
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], pan: { x: 10, y: 20 } }) }));
85
+ expect(setPan).toHaveBeenCalledTimes(1);
86
+ expect(setPan).toHaveBeenCalledWith(10, 20);
87
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], pan: { x: 10, y: 20 } }) }));
88
+ expect(setPan).toHaveBeenCalledTimes(1);
89
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], pan: { x: 30, y: 40 } }) }));
90
+ expect(setPan).toHaveBeenCalledTimes(2);
91
+ expect(setPan).toHaveBeenCalledWith(30, 40);
92
+ expect(setZoom).not.toHaveBeenCalled();
93
+ expect(setZoomAndPan).not.toHaveBeenCalled();
94
+ });
95
+ test('calls setZoomAndPan when both zoom and pan change', () => {
96
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5, pan: { x: 10, y: 20 } }) }));
97
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
98
+ expect(setZoomAndPan).toHaveBeenCalledWith(1.5, 10, 20);
99
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5, pan: { x: 10, y: 20 } }) }));
100
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
101
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 2.0, pan: { x: 30, y: 40 } }) }));
102
+ expect(setZoomAndPan).toHaveBeenCalledTimes(2);
103
+ expect(setZoomAndPan).toHaveBeenCalledWith(2.0, 30, 40);
104
+ expect(setZoom).not.toHaveBeenCalled();
105
+ expect(setPan).not.toHaveBeenCalled();
106
+ });
107
+ test('calls appropriate methods when only zoom changes while both are set', () => {
108
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5, pan: { x: 10, y: 20 } }) }));
109
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
110
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 2.0, pan: { x: 10, y: 20 } }) }));
111
+ expect(setZoom).toHaveBeenCalledTimes(1);
112
+ expect(setZoom).toHaveBeenCalledWith(2.0);
113
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
114
+ expect(setPan).not.toHaveBeenCalled();
115
+ });
116
+ test('calls appropriate methods when only pan changes while both are set', () => {
117
+ const { rerender } = render(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5, pan: { x: 10, y: 20 } }) }));
118
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
119
+ rerender(_jsx("div", { children: _jsx(BasicNvlWrapper, { nodes: [], rels: [], zoom: 1.5, pan: { x: 30, y: 40 } }) }));
120
+ expect(setPan).toHaveBeenCalledTimes(1);
121
+ expect(setPan).toHaveBeenCalledWith(30, 40);
122
+ expect(setZoomAndPan).toHaveBeenCalledTimes(1);
123
+ expect(setZoom).not.toHaveBeenCalled();
124
+ });
69
125
  });
@@ -45,4 +45,4 @@ export interface BasicReactWrapperProps {
45
45
  *
46
46
  * For examples, head to the {@link https://neo4j.com/docs/nvl/current/react-wrappers/#_basic_react_wrapper Basic React wrapper documentation page}.
47
47
  */
48
- export declare const BasicNvlWrapper: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<BasicReactWrapperProps & HTMLProps<HTMLDivElement>, "ref"> & import("react").RefAttributes<Partial<Pick<NVL, "restart" | "destroy" | "addAndUpdateElementsInGraph" | "getSelectedNodes" | "getSelectedRelationships" | "removeNodesWithIds" | "removeRelationshipsWithIds" | "getNodes" | "getRelationships" | "getNodeById" | "getRelationshipById" | "getPositionById" | "getCurrentOptions" | "deselectAll" | "fit" | "resetZoom" | "setRenderer" | "setDisableWebGL" | "pinNode" | "unPinNode" | "setLayout" | "setLayoutOptions" | "getNodesOnScreen" | "getNodePositions" | "setNodePositions" | "isLayoutMoving" | "saveToFile" | "saveToSvg" | "getImageDataUrl" | "saveFullGraphToLargeFile" | "setZoom" | "getScale" | "getPan" | "getHits" | "getContainer">>>>>;
48
+ export declare const BasicNvlWrapper: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<BasicReactWrapperProps & HTMLProps<HTMLDivElement>, "ref"> & import("react").RefAttributes<Partial<Pick<NVL, "restart" | "destroy" | "addAndUpdateElementsInGraph" | "getSelectedNodes" | "getSelectedRelationships" | "removeNodesWithIds" | "removeRelationshipsWithIds" | "getNodes" | "getRelationships" | "getNodeById" | "getRelationshipById" | "getPositionById" | "getCurrentOptions" | "deselectAll" | "fit" | "resetZoom" | "setRenderer" | "setDisableWebGL" | "pinNode" | "unPinNode" | "setLayout" | "setLayoutOptions" | "getNodesOnScreen" | "getNodePositions" | "setNodePositions" | "isLayoutMoving" | "saveToFile" | "saveToSvg" | "getImageDataUrl" | "saveFullGraphToLargeFile" | "getZoomLimits" | "setZoom" | "getScale" | "getPan" | "getHits" | "getContainer">>>>>;
@@ -14,6 +14,8 @@ import { useDeepCompareEffect } from '../utils/hooks';
14
14
  */
15
15
  export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOptions, nvlCallbacks = {}, nvlOptions = {}, positions = [], zoom, pan, onInitializationError, ...nvlEvents }, ref) => {
16
16
  const nvlRef = useRef(null);
17
+ const prevZoomRef = useRef(undefined);
18
+ const prevPanRef = useRef(undefined);
17
19
  useImperativeHandle(ref, () => {
18
20
  const nvlMethods = Object.getOwnPropertyNames(NVL.prototype);
19
21
  return nvlMethods.reduce((current, method) => ({
@@ -127,15 +129,21 @@ export const BasicNvlWrapper = memo(forwardRef(({ nodes, rels, layout, layoutOpt
127
129
  if (nvlRef.current === null) {
128
130
  return;
129
131
  }
130
- if (zoom !== undefined && pan !== undefined) {
132
+ const currentZoom = prevZoomRef.current;
133
+ const currentPan = prevPanRef.current;
134
+ const zoomHasChanged = zoom !== undefined && zoom !== currentZoom;
135
+ const panHasChanged = pan !== undefined && (pan.x !== currentPan?.x || pan.y !== currentPan.y);
136
+ if (zoomHasChanged && panHasChanged) {
131
137
  nvlRef.current.setZoomAndPan(zoom, pan.x, pan.y);
132
138
  }
133
- else if (zoom !== undefined) {
139
+ else if (zoomHasChanged) {
134
140
  nvlRef.current.setZoom(zoom);
135
141
  }
136
- else if (pan !== undefined) {
142
+ else if (panHasChanged) {
137
143
  nvlRef.current.setPan(pan.x, pan.y);
138
144
  }
145
+ prevZoomRef.current = zoom;
146
+ prevPanRef.current = pan;
139
147
  }, [zoom, pan]);
140
148
  return _jsx("div", { id: BASIC_WRAPPER_ID, ref: containerRef, style: { height: '100%', outline: '0' }, ...nvlEvents });
141
149
  }));
@@ -22,6 +22,7 @@ export const InteractionHandlers = ({ nvlRef, mouseEventCallbacks, interactionOp
22
22
  useInteraction(ClickInteraction, clickInteraction, mouseEventCallbacks.onCanvasRightClick, 'onCanvasRightClick', nvlRef, interactionOptions);
23
23
  useInteraction(PanInteraction, panInteraction, mouseEventCallbacks.onPan, 'onPan', nvlRef, interactionOptions);
24
24
  useInteraction(ZoomInteraction, zoomInteraction, mouseEventCallbacks.onZoom, 'onZoom', nvlRef, interactionOptions);
25
+ useInteraction(ZoomInteraction, zoomInteraction, mouseEventCallbacks.onZoomAndPan, 'onZoomAndPan', nvlRef, interactionOptions);
25
26
  useInteraction(DragNodeInteraction, dragNodeInteraction, mouseEventCallbacks.onDrag, 'onDrag', nvlRef, interactionOptions);
26
27
  useInteraction(DragNodeInteraction, dragNodeInteraction, mouseEventCallbacks.onDragStart, 'onDragStart', nvlRef, interactionOptions);
27
28
  useInteraction(DragNodeInteraction, dragNodeInteraction, mouseEventCallbacks.onDragEnd, 'onDragEnd', nvlRef, interactionOptions);
@@ -1,4 +1,4 @@
1
- import type { BoxSelectInteraction, BoxSelectInteractionCallbacks, BoxSelectInteractionOptions, ClickInteraction, ClickInteractionCallbacks, ClickInteractionOptions, DragNodeInteraction, DragNodeInteractionCallbacks, DrawInteraction, DrawInteractionCallbacks, DrawInteractionOptions, HoverInteraction, HoverInteractionCallbacks, HoverInteractionOptions, LassoInteraction, LassoInteractionCallbacks, LassoInteractionOptions, PanInteraction, PanInteractionCallbacks, PanInteractionOptions, ZoomInteraction, ZoomInteractionCallbacks } from '@neo4j-nvl/interaction-handlers';
1
+ import type { BoxSelectInteraction, BoxSelectInteractionCallbacks, BoxSelectInteractionOptions, ClickInteraction, ClickInteractionCallbacks, ClickInteractionOptions, DragNodeInteraction, DragNodeInteractionCallbacks, DrawInteraction, DrawInteractionCallbacks, DrawInteractionOptions, HoverInteraction, HoverInteractionCallbacks, HoverInteractionOptions, LassoInteraction, LassoInteractionCallbacks, LassoInteractionOptions, PanInteraction, PanInteractionCallbacks, PanInteractionOptions, ZoomInteraction, ZoomInteractionCallbacks, ZoomInteractionOptions } from '@neo4j-nvl/interaction-handlers';
2
2
  import type { BasicReactWrapperProps } from '../basic-wrapper/BasicNvlWrapper';
3
3
  export type MouseInteractionModule = typeof HoverInteraction | typeof ClickInteraction | typeof PanInteraction | typeof ZoomInteraction | typeof DragNodeInteraction | typeof DrawInteraction | typeof BoxSelectInteraction | typeof LassoInteraction;
4
4
  export type MouseInteraction = HoverInteraction | ClickInteraction | PanInteraction | ZoomInteraction | DragNodeInteraction | DrawInteraction | BoxSelectInteraction | LassoInteraction;
@@ -11,7 +11,7 @@ export type MouseEventCallbacks = ClickInteractionCallbacks & DragNodeInteractio
11
11
  * Collection of interaction options that can be used with
12
12
  * the {@link InteractiveNvlWrapper} component.
13
13
  */
14
- export type InteractionOptions = ClickInteractionOptions & BoxSelectInteractionOptions & HoverInteractionOptions & PanInteractionOptions & LassoInteractionOptions & DrawInteractionOptions;
14
+ export type InteractionOptions = ClickInteractionOptions & BoxSelectInteractionOptions & HoverInteractionOptions & PanInteractionOptions & ZoomInteractionOptions & LassoInteractionOptions & DrawInteractionOptions;
15
15
  /**
16
16
  * The events that can be passed to the {@link MouseEventCallbacks} object
17
17
  * to turn on/off certain events for the {@link InteractiveNvlWrapper} component.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/react",
3
- "version": "1.0.0-b6554465",
3
+ "version": "1.0.0-bb8a655f",
4
4
  "main": "lib/index.js",
5
5
  "homepage": "https://neo4j.com/docs/nvl/current/",
6
6
  "license": "SEE LICENSE IN 'LICENSE.txt'",
@@ -36,8 +36,8 @@
36
36
  "react-dom": "19.2.1"
37
37
  },
38
38
  "dependencies": {
39
- "@neo4j-nvl/base": "1.0.0-b6554465",
40
- "@neo4j-nvl/interaction-handlers": "1.0.0-b6554465",
39
+ "@neo4j-nvl/base": "1.0.0-bb8a655f",
40
+ "@neo4j-nvl/interaction-handlers": "1.0.0-bb8a655f",
41
41
  "lodash": "4.17.23"
42
42
  },
43
43
  "peerDependencies": {