@neo4j-nvl/interaction-handlers 0.3.9 → 1.0.0-92efb3d5
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 +20 -0
- package/lib/interaction-handlers/base.d.ts +18 -5
- package/lib/interaction-handlers/base.js +17 -5
- package/lib/interaction-handlers/box-select-interaction.d.ts +8 -5
- package/lib/interaction-handlers/box-select-interaction.js +2 -2
- package/lib/interaction-handlers/click-interaction.d.ts +23 -23
- package/lib/interaction-handlers/click-interaction.js +2 -2
- package/lib/interaction-handlers/drag-node-interaction.d.ts +7 -7
- package/lib/interaction-handlers/drag-node-interaction.js +1 -1
- package/lib/interaction-handlers/draw-interaction.d.ts +8 -0
- package/lib/interaction-handlers/draw-interaction.js +1 -0
- package/lib/interaction-handlers/hover-interaction.d.ts +4 -4
- package/lib/interaction-handlers/hover-interaction.js +1 -1
- package/lib/interaction-handlers/lasso-interaction.d.ts +12 -5
- package/lib/interaction-handlers/lasso-interaction.js +5 -2
- package/lib/interaction-handlers/pan-interaction.d.ts +5 -5
- package/lib/interaction-handlers/pan-interaction.js +3 -3
- package/lib/interaction-handlers/zoom-interaction.d.ts +8 -6
- package/lib/interaction-handlers/zoom-interaction.js +6 -4
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
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.0.0] - 2025-09-30
|
|
6
|
+
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
|
+
|
|
8
|
+
### Added
|
|
9
|
+
* support for React 19 in Nvl React wrappers.
|
|
10
|
+
* new prop to the React components to provde zoom and pan values.
|
|
11
|
+
* extend return object of `.getZoomTargetForNodePositions` function to include pan values.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
* updated example application UI.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
* display remaining captions when one of the values in the caption array is null or undefined.
|
|
18
|
+
* ensure the computing state for the d3 layout is set correctly.
|
|
19
|
+
* correctly process Right-to-Left (RTL) text for node captions.
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
* `useWebGL` / `setUseWebGLRenderer`, please use [renderer](https://neo4j.com/docs/api/nvl/current/interfaces/_neo4j_nvl_base.NvlOptions.html#renderer) & [setRenderer](https://neo4j.com/docs/api/nvl/current/classes/_neo4j_nvl_base.NVL.html#setRenderer) instead going forward.
|
|
23
|
+
* `NvlOption.nodeDefaultBorderColor`, `NvlOption.selectedBorderColor`, `NvlOption.disabledItemColor`, `NvlOption.disabledItemFontColor`, please use properties with the same name in [NvlOptions.styling](https://neo4j.com/docs/api/nvl/current/interfaces/_neo4j_nvl_base.NvlOptions.html#styling) object going forward.
|
|
24
|
+
|
|
5
25
|
## [0.3.9] - 2025-07-23
|
|
6
26
|
|
|
7
27
|
The 0.3.9 release contains several fixes for NVL's interaction handler and adds a new method to NVL to directly extract image data from an NVL instance:
|
|
@@ -3,6 +3,7 @@ import type { NVL } from '@neo4j-nvl/base';
|
|
|
3
3
|
* Base class for all interactions.
|
|
4
4
|
* @abstract
|
|
5
5
|
* @internal
|
|
6
|
+
* @hidden
|
|
6
7
|
*/
|
|
7
8
|
declare abstract class BaseInteraction<T extends Record<string, ((...args: unknown[]) => void) | boolean>, P extends Record<string, unknown>> {
|
|
8
9
|
private readonly nvl;
|
|
@@ -10,52 +11,64 @@ declare abstract class BaseInteraction<T extends Record<string, ((...args: unkno
|
|
|
10
11
|
private readonly container;
|
|
11
12
|
/**
|
|
12
13
|
* @internal
|
|
14
|
+
* @hidden
|
|
13
15
|
*/
|
|
14
16
|
callbackMap: Map<keyof T, T[keyof T]>;
|
|
15
17
|
/**
|
|
16
18
|
* @internal
|
|
19
|
+
* @hidden
|
|
17
20
|
*/
|
|
18
21
|
constructor(nvl: NVL, options: P);
|
|
19
22
|
/**
|
|
20
23
|
* @internal
|
|
24
|
+
* @hidden
|
|
21
25
|
*/
|
|
22
26
|
get nvlInstance(): NVL;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the current options of the interaction.
|
|
29
|
+
* @returns The current options of the interaction.
|
|
30
|
+
*/
|
|
23
31
|
get currentOptions(): P;
|
|
24
32
|
/**
|
|
25
33
|
* @internal
|
|
34
|
+
* @hidden
|
|
26
35
|
*/
|
|
27
36
|
get containerInstance(): HTMLElement;
|
|
28
37
|
/**
|
|
29
38
|
* @internal
|
|
39
|
+
* @hidden
|
|
30
40
|
*/
|
|
31
41
|
addEventListener: (type: keyof HTMLElementEventMap, listener: (event: Event) => void, options?: boolean | AddEventListenerOptions) => void;
|
|
32
42
|
/**
|
|
33
43
|
* @internal
|
|
44
|
+
* @hidden
|
|
34
45
|
*/
|
|
35
46
|
removeEventListener: (type: keyof HTMLElementEventMap, listener: (event: Event) => void, options?: boolean | EventListenerOptions) => void;
|
|
36
47
|
/**
|
|
37
48
|
* @internal
|
|
49
|
+
* @hidden
|
|
38
50
|
*/
|
|
39
51
|
callCallbackIfRegistered: (name: keyof T, ...args: unknown[]) => void;
|
|
40
52
|
/**
|
|
41
53
|
* Add or update a callback for a given event of type.
|
|
42
|
-
* @param name - The name of the event
|
|
43
|
-
* @param callback - The callback to be called when the event is triggered
|
|
54
|
+
* @param name - The name of the event.
|
|
55
|
+
* @param callback - The callback to be called when the event is triggered.
|
|
44
56
|
*/
|
|
45
57
|
updateCallback: (name: keyof T | string, callback: T[keyof T]) => void;
|
|
46
58
|
/**
|
|
47
59
|
* Remove a callback for a given event of type.
|
|
48
|
-
* @param name - The name of the event
|
|
60
|
+
* @param name - The name of the event.
|
|
49
61
|
*/
|
|
50
62
|
removeCallback: (name: keyof T | string) => void;
|
|
51
63
|
/**
|
|
52
64
|
* Enables or disables global text selection during a drag or pan operation.
|
|
53
|
-
* @param enable - Whether to enable or disable global text selection
|
|
54
|
-
* @param eventFunction - The event function to be added/removed when text selection is disabled/enabled
|
|
65
|
+
* @param enable - Whether to enable or disable global text selection.
|
|
66
|
+
* @param eventFunction - The event function to be added/removed when text selection is disabled/enabled.
|
|
55
67
|
*/
|
|
56
68
|
toggleGlobalTextSelection: (enable: boolean, eventFunction?: ((this: HTMLElement, ev: MouseEvent) => void) | undefined) => void;
|
|
57
69
|
/**
|
|
58
70
|
* @internal
|
|
71
|
+
* @hidden
|
|
59
72
|
*/
|
|
60
73
|
abstract destroy(): void;
|
|
61
74
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Base class for all interactions.
|
|
3
3
|
* @abstract
|
|
4
4
|
* @internal
|
|
5
|
+
* @hidden
|
|
5
6
|
*/
|
|
6
7
|
class BaseInteraction {
|
|
7
8
|
nvl;
|
|
@@ -9,10 +10,12 @@ class BaseInteraction {
|
|
|
9
10
|
container;
|
|
10
11
|
/**
|
|
11
12
|
* @internal
|
|
13
|
+
* @hidden
|
|
12
14
|
*/
|
|
13
15
|
callbackMap;
|
|
14
16
|
/**
|
|
15
17
|
* @internal
|
|
18
|
+
* @hidden
|
|
16
19
|
*/
|
|
17
20
|
constructor(nvl, options) {
|
|
18
21
|
this.nvl = nvl;
|
|
@@ -22,33 +25,42 @@ class BaseInteraction {
|
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
27
|
* @internal
|
|
28
|
+
* @hidden
|
|
25
29
|
*/
|
|
26
30
|
get nvlInstance() {
|
|
27
31
|
return this.nvl;
|
|
28
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the current options of the interaction.
|
|
35
|
+
* @returns The current options of the interaction.
|
|
36
|
+
*/
|
|
29
37
|
get currentOptions() {
|
|
30
38
|
return this.options;
|
|
31
39
|
}
|
|
32
40
|
/**
|
|
33
41
|
* @internal
|
|
42
|
+
* @hidden
|
|
34
43
|
*/
|
|
35
44
|
get containerInstance() {
|
|
36
45
|
return this.container;
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* @internal
|
|
49
|
+
* @hidden
|
|
40
50
|
*/
|
|
41
51
|
addEventListener = (type, listener, options) => {
|
|
42
52
|
this.container?.addEventListener(type, listener, options);
|
|
43
53
|
};
|
|
44
54
|
/**
|
|
45
55
|
* @internal
|
|
56
|
+
* @hidden
|
|
46
57
|
*/
|
|
47
58
|
removeEventListener = (type, listener, options) => {
|
|
48
59
|
this.container?.removeEventListener(type, listener, options);
|
|
49
60
|
};
|
|
50
61
|
/**
|
|
51
62
|
* @internal
|
|
63
|
+
* @hidden
|
|
52
64
|
*/
|
|
53
65
|
callCallbackIfRegistered = (name, ...args) => {
|
|
54
66
|
const callback = this.callbackMap.get(name);
|
|
@@ -58,23 +70,23 @@ class BaseInteraction {
|
|
|
58
70
|
};
|
|
59
71
|
/**
|
|
60
72
|
* Add or update a callback for a given event of type.
|
|
61
|
-
* @param name - The name of the event
|
|
62
|
-
* @param callback - The callback to be called when the event is triggered
|
|
73
|
+
* @param name - The name of the event.
|
|
74
|
+
* @param callback - The callback to be called when the event is triggered.
|
|
63
75
|
*/
|
|
64
76
|
updateCallback = (name, callback) => {
|
|
65
77
|
this.callbackMap.set(name, callback);
|
|
66
78
|
};
|
|
67
79
|
/**
|
|
68
80
|
* Remove a callback for a given event of type.
|
|
69
|
-
* @param name - The name of the event
|
|
81
|
+
* @param name - The name of the event.
|
|
70
82
|
*/
|
|
71
83
|
removeCallback = (name) => {
|
|
72
84
|
this.callbackMap.delete(name);
|
|
73
85
|
};
|
|
74
86
|
/**
|
|
75
87
|
* Enables or disables global text selection during a drag or pan operation.
|
|
76
|
-
* @param enable - Whether to enable or disable global text selection
|
|
77
|
-
* @param eventFunction - The event function to be added/removed when text selection is disabled/enabled
|
|
88
|
+
* @param enable - Whether to enable or disable global text selection.
|
|
89
|
+
* @param eventFunction - The event function to be added/removed when text selection is disabled/enabled.
|
|
78
90
|
*/
|
|
79
91
|
toggleGlobalTextSelection = (enable, eventFunction) => {
|
|
80
92
|
if (enable) {
|
|
@@ -10,16 +10,19 @@ export type BoxSelectInteractionOptions = {
|
|
|
10
10
|
*/
|
|
11
11
|
selectOnRelease?: boolean;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Callbacks for the box select interaction handler.
|
|
15
|
+
*/
|
|
13
16
|
export type BoxSelectInteractionCallbacks = {
|
|
14
17
|
/**
|
|
15
18
|
* Called once when the user presses the mouse on the canvas, starting the box selection.
|
|
16
|
-
* @param event - The original mouse event
|
|
19
|
+
* @param event - The original mouse event.
|
|
17
20
|
*/
|
|
18
21
|
onBoxStarted?: ((event: MouseEvent) => void) | boolean;
|
|
19
22
|
/**
|
|
20
23
|
* Called after once the user releases the mouse after multi-selecting.
|
|
21
|
-
* @param selectionObject - The selected nodes and relationships
|
|
22
|
-
* @param event - The original mouse event
|
|
24
|
+
* @param selectionObject - The selected nodes and relationships.
|
|
25
|
+
* @param event - The original mouse event.
|
|
23
26
|
*/
|
|
24
27
|
onBoxSelect?: (({ nodes, rels }: {
|
|
25
28
|
nodes: Node[];
|
|
@@ -39,8 +42,8 @@ export declare class BoxSelectInteraction extends BaseInteraction<BoxSelectInter
|
|
|
39
42
|
private isBoxSelecting;
|
|
40
43
|
/**
|
|
41
44
|
* Creates a new instance of the multi-select interaction handler.
|
|
42
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
43
|
-
* @param options - Options for the multi-select interaction handler to customize its behavior
|
|
45
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
46
|
+
* @param options - Options for the multi-select interaction handler to customize its behavior.
|
|
44
47
|
*/
|
|
45
48
|
constructor(nvl: NVL, options?: BoxSelectInteractionOptions);
|
|
46
49
|
private handleMouseDown;
|
|
@@ -15,8 +15,8 @@ export class BoxSelectInteraction extends BaseInteraction {
|
|
|
15
15
|
isBoxSelecting = false;
|
|
16
16
|
/**
|
|
17
17
|
* Creates a new instance of the multi-select interaction handler.
|
|
18
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
19
|
-
* @param options - Options for the multi-select interaction handler to customize its behavior
|
|
18
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
19
|
+
* @param options - Options for the multi-select interaction handler to customize its behavior.
|
|
20
20
|
*/
|
|
21
21
|
constructor(nvl, options = { selectOnRelease: false }) {
|
|
22
22
|
super(nvl, options);
|
|
@@ -16,59 +16,59 @@ export type ClickInteractionOptions = {
|
|
|
16
16
|
export type ClickInteractionCallbacks = {
|
|
17
17
|
/**
|
|
18
18
|
* Called when a node is clicked
|
|
19
|
-
* @param nodes - The node that was clicked
|
|
20
|
-
* @param hitElements - All elements that were hit by the click
|
|
21
|
-
* @param event - The original mouse event
|
|
19
|
+
* @param nodes - The node that was clicked.
|
|
20
|
+
* @param hitElements - All elements that were hit by the click.
|
|
21
|
+
* @param event - The original mouse event.
|
|
22
22
|
*/
|
|
23
23
|
onNodeClick?: ((nodes: Node, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
|
|
24
24
|
/**
|
|
25
25
|
* Called when a relationship is clicked
|
|
26
|
-
* @param relationship - The relationship that was clicked
|
|
27
|
-
* @param hitElements - All elements that were hit by the click
|
|
28
|
-
* @param event - The original mouse event
|
|
26
|
+
* @param relationship - The relationship that was clicked.
|
|
27
|
+
* @param hitElements - All elements that were hit by the click.
|
|
28
|
+
* @param event - The original mouse event.
|
|
29
29
|
*/
|
|
30
30
|
onRelationshipClick?: ((relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
|
|
31
31
|
/**
|
|
32
32
|
* Called when the canvas is clicked
|
|
33
|
-
* @param event - The original mouse event
|
|
33
|
+
* @param event - The original mouse event.
|
|
34
34
|
*/
|
|
35
35
|
onCanvasClick?: ((event: MouseEvent) => void) | boolean;
|
|
36
36
|
/**
|
|
37
37
|
* Called when a node is double clicked
|
|
38
|
-
* @param event - The original mouse event
|
|
38
|
+
* @param event - The original mouse event.
|
|
39
39
|
*/
|
|
40
40
|
onCanvasDoubleClick?: ((event: MouseEvent) => void) | boolean;
|
|
41
41
|
/**
|
|
42
42
|
* Called when a relationship is right-clicked
|
|
43
|
-
* @param event - The original mouse event
|
|
43
|
+
* @param event - The original mouse event.
|
|
44
44
|
*/
|
|
45
45
|
onCanvasRightClick?: ((event: MouseEvent) => void) | boolean;
|
|
46
46
|
/**
|
|
47
47
|
* Called when a node is double-clicked
|
|
48
|
-
* @param nodes - The node that was double-clicked
|
|
49
|
-
* @param hitElements - All elements that were hit by the double-click
|
|
50
|
-
* @param event - The original mouse event
|
|
48
|
+
* @param nodes - The node that was double-clicked.
|
|
49
|
+
* @param hitElements - All elements that were hit by the double-click.
|
|
50
|
+
* @param event - The original mouse event.
|
|
51
51
|
*/
|
|
52
52
|
onNodeDoubleClick?: ((node: Node, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
|
|
53
53
|
/**
|
|
54
54
|
* Called when a node is right-clicked
|
|
55
|
-
* @param nodes - The node that was right-clicked
|
|
56
|
-
* @param hitElements - All elements that were hit by the right-click
|
|
57
|
-
* @param event - The original mouse event
|
|
55
|
+
* @param nodes - The node that was right-clicked.
|
|
56
|
+
* @param hitElements - All elements that were hit by the right-click.
|
|
57
|
+
* @param event - The original mouse event.
|
|
58
58
|
*/
|
|
59
59
|
onNodeRightClick?: ((node: Node, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
|
|
60
60
|
/**
|
|
61
61
|
* Called when a relationship is double-clicked
|
|
62
|
-
* @param relationship - The relationship that was double-clicked
|
|
63
|
-
* @param hitElements - All elements that were hit by the double-click
|
|
64
|
-
* @param event - The original mouse event
|
|
62
|
+
* @param relationship - The relationship that was double-clicked.
|
|
63
|
+
* @param hitElements - All elements that were hit by the double-click.
|
|
64
|
+
* @param event - The original mouse event.
|
|
65
65
|
*/
|
|
66
66
|
onRelationshipDoubleClick?: ((relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
|
|
67
67
|
/**
|
|
68
68
|
* Called when a relationship is right-clicked
|
|
69
|
-
* @param relationship - The relationship that was right-clicked
|
|
70
|
-
* @param hitElements - All elements that were hit by the right-click
|
|
71
|
-
* @param event - The original mouse event
|
|
69
|
+
* @param relationship - The relationship that was right-clicked.
|
|
70
|
+
* @param hitElements - All elements that were hit by the right-click.
|
|
71
|
+
* @param event - The original mouse event.
|
|
72
72
|
*/
|
|
73
73
|
onRelationshipRightClick?: ((relationship: Relationship, hitElements: HitTargets, event: MouseEvent) => void) | boolean;
|
|
74
74
|
};
|
|
@@ -83,8 +83,8 @@ export declare class ClickInteraction extends BaseInteraction<ClickInteractionCa
|
|
|
83
83
|
private mousePosition;
|
|
84
84
|
/**
|
|
85
85
|
* Creates a new click interaction handler.
|
|
86
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
87
|
-
* @param options - Options for the click interaction handler
|
|
86
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
87
|
+
* @param options - Options for the click interaction handler.
|
|
88
88
|
*/
|
|
89
89
|
constructor(nvl: NVL, options?: ClickInteractionOptions);
|
|
90
90
|
private handleMouseDown;
|
|
@@ -11,8 +11,8 @@ export class ClickInteraction extends BaseInteraction {
|
|
|
11
11
|
mousePosition = { x: 0, y: 0 };
|
|
12
12
|
/**
|
|
13
13
|
* Creates a new click interaction handler.
|
|
14
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
15
|
-
* @param options - Options for the click interaction handler
|
|
14
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
15
|
+
* @param options - Options for the click interaction handler.
|
|
16
16
|
*/
|
|
17
17
|
constructor(nvl, options = { selectOnClick: false }) {
|
|
18
18
|
super(nvl, options);
|
|
@@ -6,20 +6,20 @@ import { BaseInteraction } from './base';
|
|
|
6
6
|
export type DragNodeInteractionCallbacks = {
|
|
7
7
|
/**
|
|
8
8
|
* Called when node(s) are dragged
|
|
9
|
-
* @param nodes - The node(s) being dragged
|
|
10
|
-
* @param event - The original mouse event
|
|
9
|
+
* @param nodes - The node(s) being dragged.
|
|
10
|
+
* @param event - The original mouse event.
|
|
11
11
|
*/
|
|
12
12
|
onDrag?: ((nodes: Node[], evt: MouseEvent) => void) | boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Called once when node(s) are started to being dragged
|
|
15
|
-
* @param nodes - The node(s) being dragged
|
|
16
|
-
* @param event - The original mouse event
|
|
15
|
+
* @param nodes - The node(s) being dragged.
|
|
16
|
+
* @param event - The original mouse event.
|
|
17
17
|
*/
|
|
18
18
|
onDragStart?: ((nodes: Node[], evt: MouseEvent) => void) | boolean;
|
|
19
19
|
/**
|
|
20
20
|
* Called once when node(s) are finished being dragged
|
|
21
|
-
* @param nodes - The node(s) being dragged
|
|
22
|
-
* @param event - The original mouse event
|
|
21
|
+
* @param nodes - The node(s) being dragged.
|
|
22
|
+
* @param event - The original mouse event.
|
|
23
23
|
*/
|
|
24
24
|
onDragEnd?: ((nodes: Node[], evt: MouseEvent) => void) | boolean;
|
|
25
25
|
};
|
|
@@ -39,7 +39,7 @@ export declare class DragNodeInteraction extends BaseInteraction<DragNodeInterac
|
|
|
39
39
|
private moveSelectedNodes;
|
|
40
40
|
/**
|
|
41
41
|
* Creates a new instance of the drag node interaction handler.
|
|
42
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
42
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
43
43
|
*/
|
|
44
44
|
constructor(nvl: NVL, options?: {});
|
|
45
45
|
private handleMouseDown;
|
|
@@ -17,7 +17,7 @@ export class DragNodeInteraction extends BaseInteraction {
|
|
|
17
17
|
moveSelectedNodes = false;
|
|
18
18
|
/**
|
|
19
19
|
* Creates a new instance of the drag node interaction handler.
|
|
20
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
20
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
21
21
|
*/
|
|
22
22
|
constructor(nvl, options = {}) {
|
|
23
23
|
super(nvl, options);
|
|
@@ -2,20 +2,28 @@ import type { NVL, Node, Relationship } from '@neo4j-nvl/base';
|
|
|
2
2
|
import { BaseInteraction } from './base';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
|
+
* @hidden
|
|
5
6
|
*/
|
|
6
7
|
export type DrawInteractionCallbacks = {
|
|
7
8
|
onHoverNodeMargin?: ((hoveredNode: Node | null, evt: MouseEvent) => void) | boolean;
|
|
8
9
|
onDrawEnded?: ((newRelationshipToAdd: Relationship | null, newTargetNodeToAdd: Node | null, event: MouseEvent) => void) | boolean;
|
|
9
10
|
onDrawStarted?: ((event: MouseEvent) => void) | boolean;
|
|
10
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Options for the draw interaction handler.
|
|
14
|
+
*/
|
|
11
15
|
export type DrawInteractionOptions = {
|
|
16
|
+
/** Styling for the ghost graph that is shown when drawing. */
|
|
12
17
|
ghostGraphStyling?: {
|
|
18
|
+
/** Styling for the ghost node. */
|
|
13
19
|
node?: Pick<Node, 'color' | 'size'>;
|
|
20
|
+
/** Styling for the ghost relationship. */
|
|
14
21
|
relationship?: Pick<Relationship, 'color' | 'width'>;
|
|
15
22
|
};
|
|
16
23
|
};
|
|
17
24
|
/**
|
|
18
25
|
* @internal
|
|
26
|
+
* @hidden
|
|
19
27
|
*/
|
|
20
28
|
export declare class DrawInteraction extends BaseInteraction<DrawInteractionCallbacks, DrawInteractionOptions> {
|
|
21
29
|
private isMoved;
|
|
@@ -16,9 +16,9 @@ export type HoverInteractionOptions = {
|
|
|
16
16
|
export type HoverInteractionCallbacks = {
|
|
17
17
|
/**
|
|
18
18
|
* Called when a node or relationship is hovered
|
|
19
|
-
* @param element - The node or relationship that was hovered
|
|
20
|
-
* @param hitElements - All elements that were hit by the hover
|
|
21
|
-
* @param event - The original mouse event
|
|
19
|
+
* @param element - The node or relationship that was hovered.
|
|
20
|
+
* @param hitElements - All elements that were hit by the hover.
|
|
21
|
+
* @param event - The original mouse event.
|
|
22
22
|
* This callback is called every time the mouse moves,
|
|
23
23
|
* even when no element is hovered or the current element is already hovered.
|
|
24
24
|
*/
|
|
@@ -36,7 +36,7 @@ export declare class HoverInteraction extends BaseInteraction<HoverInteractionCa
|
|
|
36
36
|
constructor(nvl: NVL, options?: HoverInteractionOptions);
|
|
37
37
|
/**
|
|
38
38
|
* Handle mouse hover events
|
|
39
|
-
* @param
|
|
39
|
+
* @param event - The mouse event.
|
|
40
40
|
*/
|
|
41
41
|
handleHover: (event: MouseEvent) => void;
|
|
42
42
|
private updateElementsInNVL;
|
|
@@ -17,7 +17,7 @@ export class HoverInteraction extends BaseInteraction {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Handle mouse hover events
|
|
20
|
-
* @param
|
|
20
|
+
* @param event - The mouse event.
|
|
21
21
|
*/
|
|
22
22
|
handleHover = (event) => {
|
|
23
23
|
const { nvlTargets } = this.nvlInstance.getHits(event);
|
|
@@ -10,16 +10,19 @@ export type LassoInteractionOptions = {
|
|
|
10
10
|
*/
|
|
11
11
|
selectOnRelease?: boolean;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Callbacks for the lasso interaction handler.
|
|
15
|
+
*/
|
|
13
16
|
export type LassoInteractionCallbacks = {
|
|
14
17
|
/**
|
|
15
18
|
* Called once when the user presses the mouse on the canvas, starting the lasso.
|
|
16
|
-
* @param event - The original mouse event
|
|
19
|
+
* @param event - The original mouse event.
|
|
17
20
|
*/
|
|
18
21
|
onLassoStarted?: ((event: MouseEvent) => void) | boolean;
|
|
19
22
|
/**
|
|
20
23
|
* Called once when the user releases the mouse after lasso selecting.
|
|
21
|
-
* @param selectionObject - The selected node and relationship ids
|
|
22
|
-
* @param event - The original mouse event
|
|
24
|
+
* @param selectionObject - The selected node and relationship ids.
|
|
25
|
+
* @param event - The original mouse event.
|
|
23
26
|
*/
|
|
24
27
|
onLassoSelect?: (({ nodes, rels }: {
|
|
25
28
|
nodes: Node[];
|
|
@@ -28,21 +31,25 @@ export type LassoInteractionCallbacks = {
|
|
|
28
31
|
};
|
|
29
32
|
/**
|
|
30
33
|
* @internal
|
|
34
|
+
* @hidden
|
|
31
35
|
*/
|
|
32
36
|
export type Coords = [number, number];
|
|
33
37
|
/**
|
|
34
38
|
* Checks if two lines defined by p1->p2 and p3->p4 are crossing.
|
|
35
39
|
* @internal
|
|
40
|
+
* @hidden
|
|
36
41
|
*/
|
|
37
42
|
export declare const checkLinesCrossing: (p1: Coords, p2: Coords, p3: Coords, p4: Coords) => boolean;
|
|
38
43
|
/**
|
|
39
44
|
* Checks if any line segments in the polygon intersect.
|
|
40
45
|
* @internal
|
|
46
|
+
* @hidden
|
|
41
47
|
*/
|
|
42
48
|
export declare const checkIntersection: (polygon: Coords[]) => boolean;
|
|
43
49
|
/**
|
|
44
50
|
* Checks if the point (x, y) is inside the polygon defined by vs.
|
|
45
51
|
* @internal
|
|
52
|
+
* @hidden
|
|
46
53
|
*/
|
|
47
54
|
export declare const checkPointInside: (x: number, y: number, vs: Point[]) => boolean;
|
|
48
55
|
/**
|
|
@@ -57,8 +64,8 @@ export declare class LassoInteraction extends BaseInteraction<LassoInteractionCa
|
|
|
57
64
|
private overlayRenderer;
|
|
58
65
|
/**
|
|
59
66
|
* Creates a new instance of the lasso interaction handler.
|
|
60
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
61
|
-
* @param options - Options for the lasso interaction handler to customize its behavior
|
|
67
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
68
|
+
* @param options - Options for the lasso interaction handler to customize its behavior.
|
|
62
69
|
*/
|
|
63
70
|
constructor(nvl: NVL, options?: LassoInteractionOptions);
|
|
64
71
|
private startLasso;
|
|
@@ -8,6 +8,7 @@ const shapeShowTime = 500;
|
|
|
8
8
|
/**
|
|
9
9
|
* Checks if two lines defined by p1->p2 and p3->p4 are crossing.
|
|
10
10
|
* @internal
|
|
11
|
+
* @hidden
|
|
11
12
|
*/
|
|
12
13
|
export const checkLinesCrossing = (p1, p2, p3, p4) => {
|
|
13
14
|
const denom = (p4[1] - p3[1]) * (p2[0] - p1[0]) - (p4[0] - p3[0]) * (p2[1] - p1[1]);
|
|
@@ -22,6 +23,7 @@ export const checkLinesCrossing = (p1, p2, p3, p4) => {
|
|
|
22
23
|
/**
|
|
23
24
|
* Checks if any line segments in the polygon intersect.
|
|
24
25
|
* @internal
|
|
26
|
+
* @hidden
|
|
25
27
|
*/
|
|
26
28
|
export const checkIntersection = (polygon) => {
|
|
27
29
|
for (let i = 0; i < polygon.length - 1; i++) {
|
|
@@ -42,6 +44,7 @@ export const checkIntersection = (polygon) => {
|
|
|
42
44
|
/**
|
|
43
45
|
* Checks if the point (x, y) is inside the polygon defined by vs.
|
|
44
46
|
* @internal
|
|
47
|
+
* @hidden
|
|
45
48
|
*/
|
|
46
49
|
export const checkPointInside = (x, y, vs) => {
|
|
47
50
|
// ray-casting algorithm based on
|
|
@@ -74,8 +77,8 @@ export class LassoInteraction extends BaseInteraction {
|
|
|
74
77
|
overlayRenderer;
|
|
75
78
|
/**
|
|
76
79
|
* Creates a new instance of the lasso interaction handler.
|
|
77
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
78
|
-
* @param options - Options for the lasso interaction handler to customize its behavior
|
|
80
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
81
|
+
* @param options - Options for the lasso interaction handler to customize its behavior.
|
|
79
82
|
*/
|
|
80
83
|
constructor(nvl, options = { selectOnRelease: false }) {
|
|
81
84
|
super(nvl, options);
|
|
@@ -16,8 +16,8 @@ export type PanInteractionOptions = {
|
|
|
16
16
|
export type PanInteractionCallbacks = {
|
|
17
17
|
/**
|
|
18
18
|
* Called when the canvas is panned.
|
|
19
|
-
* @param panning - The panning coordinates
|
|
20
|
-
* @param event - The original mouse event
|
|
19
|
+
* @param panning - The panning coordinates.
|
|
20
|
+
* @param event - The original mouse event.
|
|
21
21
|
*/
|
|
22
22
|
onPan?: ((panning: {
|
|
23
23
|
x: number;
|
|
@@ -36,13 +36,13 @@ export declare class PanInteraction extends BaseInteraction<PanInteractionCallba
|
|
|
36
36
|
private isPanning;
|
|
37
37
|
/**
|
|
38
38
|
* Creates a new instance of the pan interaction handler.
|
|
39
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
39
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
40
40
|
*/
|
|
41
41
|
constructor(nvl: NVL, options?: PanInteractionOptions);
|
|
42
42
|
/**
|
|
43
43
|
* Updates which type of graph elements should hinder panning.
|
|
44
|
-
* @param targets - The graph elements that should hinder panning
|
|
45
|
-
* @param excludeNodeMargin - If true, the node margin will not hinder panning
|
|
44
|
+
* @param targets - The graph elements that should hinder panning.
|
|
45
|
+
* @param excludeNodeMargin - If true, the node margin will not hinder panning.
|
|
46
46
|
* By default, panning is hindered by nodes and relationships.
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
@@ -13,7 +13,7 @@ export class PanInteraction extends BaseInteraction {
|
|
|
13
13
|
isPanning = false;
|
|
14
14
|
/**
|
|
15
15
|
* Creates a new instance of the pan interaction handler.
|
|
16
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
16
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
17
17
|
*/
|
|
18
18
|
constructor(nvl, options = { excludeNodeMargin: false }) {
|
|
19
19
|
super(nvl, options);
|
|
@@ -23,8 +23,8 @@ export class PanInteraction extends BaseInteraction {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Updates which type of graph elements should hinder panning.
|
|
26
|
-
* @param targets - The graph elements that should hinder panning
|
|
27
|
-
* @param excludeNodeMargin - If true, the node margin will not hinder panning
|
|
26
|
+
* @param targets - The graph elements that should hinder panning.
|
|
27
|
+
* @param excludeNodeMargin - If true, the node margin will not hinder panning.
|
|
28
28
|
* By default, panning is hindered by nodes and relationships.
|
|
29
29
|
*
|
|
30
30
|
* @example
|
|
@@ -6,8 +6,8 @@ import { BaseInteraction } from './base';
|
|
|
6
6
|
export type ZoomInteractionCallbacks = {
|
|
7
7
|
/**
|
|
8
8
|
* Called when the canvas is zoomed.
|
|
9
|
-
* @param zoomLevel - The zoom level
|
|
10
|
-
* @param event - The original mouse wheel event
|
|
9
|
+
* @param zoomLevel - The zoom level.
|
|
10
|
+
* @param event - The original mouse wheel event.
|
|
11
11
|
*/
|
|
12
12
|
onZoom?: ((zoomLevel: number, event: WheelEvent) => void) | boolean;
|
|
13
13
|
};
|
|
@@ -19,12 +19,14 @@ export type ZoomInteractionCallbacks = {
|
|
|
19
19
|
export declare class ZoomInteraction extends BaseInteraction<ZoomInteractionCallbacks, Record<string, never>> {
|
|
20
20
|
/**
|
|
21
21
|
* Creates a new instance of the zoom interaction handler.
|
|
22
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
22
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
23
23
|
*/
|
|
24
24
|
constructor(nvl: NVL, options?: {});
|
|
25
25
|
/**
|
|
26
26
|
* Throttled zoom function to avoid events happening too fast.
|
|
27
|
-
* @param event - The original mouse wheel event
|
|
27
|
+
* @param event - The original mouse wheel event.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
28
30
|
* "Wheel" with a touchpad, the wheel is triggered event a lot,
|
|
29
31
|
* especially a lot of very small values.
|
|
30
32
|
* However, updating values in NVL instance takes time.
|
|
@@ -36,8 +38,8 @@ export declare class ZoomInteraction extends BaseInteraction<ZoomInteractionCall
|
|
|
36
38
|
private throttledZoom;
|
|
37
39
|
/**
|
|
38
40
|
* The function to be called on mouse wheel event on the canvas.
|
|
39
|
-
* @param evt - The mouse wheel event
|
|
40
|
-
* @
|
|
41
|
+
* @param evt - The mouse wheel event.
|
|
42
|
+
* @remarks If the ctrl key or meta key is pressed, it does not zoom to avoid conflicts with default browser behavior.
|
|
41
43
|
*/
|
|
42
44
|
private handleWheel;
|
|
43
45
|
/**
|
|
@@ -9,7 +9,7 @@ import { getCanvasCenterOffset } from './utils';
|
|
|
9
9
|
export class ZoomInteraction extends BaseInteraction {
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new instance of the zoom interaction handler.
|
|
12
|
-
* @param nvl - The NVL instance to attach the interaction handler to
|
|
12
|
+
* @param nvl - The NVL instance to attach the interaction handler to.
|
|
13
13
|
*/
|
|
14
14
|
constructor(nvl, options = {}) {
|
|
15
15
|
super(nvl, options);
|
|
@@ -17,7 +17,9 @@ export class ZoomInteraction extends BaseInteraction {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Throttled zoom function to avoid events happening too fast.
|
|
20
|
-
* @param event - The original mouse wheel event
|
|
20
|
+
* @param event - The original mouse wheel event.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
21
23
|
* "Wheel" with a touchpad, the wheel is triggered event a lot,
|
|
22
24
|
* especially a lot of very small values.
|
|
23
25
|
* However, updating values in NVL instance takes time.
|
|
@@ -40,8 +42,8 @@ export class ZoomInteraction extends BaseInteraction {
|
|
|
40
42
|
}, 25, { leading: true });
|
|
41
43
|
/**
|
|
42
44
|
* The function to be called on mouse wheel event on the canvas.
|
|
43
|
-
* @param evt - The mouse wheel event
|
|
44
|
-
* @
|
|
45
|
+
* @param evt - The mouse wheel event.
|
|
46
|
+
* @remarks If the ctrl key or meta key is pressed, it does not zoom to avoid conflicts with default browser behavior.
|
|
45
47
|
*/
|
|
46
48
|
handleWheel = (evt) => {
|
|
47
49
|
if (evt.ctrlKey || evt.metaKey) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neo4j-nvl/interaction-handlers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-92efb3d5",
|
|
4
4
|
"license": "SEE LICENSE IN 'LICENSE.txt'",
|
|
5
5
|
"homepage": "https://neo4j.com/docs/nvl/current/",
|
|
6
6
|
"description": "Interaction handlers for the Neo4j Visualization Library",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"eslint": "yarn global:eslint ./src/"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@neo4j-nvl/base": "0.
|
|
30
|
+
"@neo4j-nvl/base": "1.0.0-92efb3d5",
|
|
31
31
|
"concaveman": "^1.2.1",
|
|
32
32
|
"lodash": "4.17.21"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@testing-library/jest-dom": "^5.16.5",
|
|
36
|
-
"@testing-library/react": "^13.4.0",
|
|
37
36
|
"@types/concaveman": "1.1.6",
|
|
38
37
|
"@types/lodash": "4.14.202"
|
|
39
|
-
}
|
|
38
|
+
},
|
|
39
|
+
"stableVersion": "1.0.0"
|
|
40
40
|
}
|