@neo4j-nvl/interaction-handlers 2.0.0 → 2.1.0

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 (49) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +8 -0
  3. package/lib/constants.d.ts +1 -1
  4. package/lib/constants.js +4 -2
  5. package/lib/index.d.ts +10 -20
  6. package/lib/index.js +10 -10
  7. package/lib/interaction-handlers/base.d.ts +67 -67
  8. package/lib/interaction-handlers/base.js +98 -104
  9. package/lib/interaction-handlers/box-select-interaction.d.ts +44 -44
  10. package/lib/interaction-handlers/box-select-interaction.js +133 -127
  11. package/lib/interaction-handlers/click-interaction.d.ts +111 -111
  12. package/lib/interaction-handlers/click-interaction.js +116 -131
  13. package/lib/interaction-handlers/drag-node-interaction.d.ts +40 -40
  14. package/lib/interaction-handlers/drag-node-interaction.js +102 -111
  15. package/lib/interaction-handlers/draw-interaction.d.ts +37 -37
  16. package/lib/interaction-handlers/draw-interaction.js +245 -278
  17. package/lib/interaction-handlers/hover-interaction.d.ts +34 -30
  18. package/lib/interaction-handlers/hover-interaction.js +83 -89
  19. package/lib/interaction-handlers/keyboard-interaction.d.ts +149 -97
  20. package/lib/interaction-handlers/keyboard-interaction.js +255 -201
  21. package/lib/interaction-handlers/lasso-interaction.d.ts +45 -45
  22. package/lib/interaction-handlers/lasso-interaction.js +174 -196
  23. package/lib/interaction-handlers/pan-interaction.d.ts +62 -61
  24. package/lib/interaction-handlers/pan-interaction.js +111 -100
  25. package/lib/interaction-handlers/utils.d.ts +2 -2
  26. package/lib/interaction-handlers/utils.js +39 -38
  27. package/lib/interaction-handlers/zoom-interaction.d.ts +52 -48
  28. package/lib/interaction-handlers/zoom-interaction.js +73 -71
  29. package/lib/overlay-renderer/overlay-renderer.d.ts +13 -13
  30. package/lib/overlay-renderer/overlay-renderer.js +96 -111
  31. package/package.json +19 -6
  32. package/lib/__tests__/box-select-interaction.test.d.ts +0 -1
  33. package/lib/__tests__/box-select-interaction.test.js +0 -149
  34. package/lib/__tests__/click-interaction.test.d.ts +0 -1
  35. package/lib/__tests__/click-interaction.test.js +0 -505
  36. package/lib/__tests__/drag-node-interaction.test.d.ts +0 -1
  37. package/lib/__tests__/drag-node-interaction.test.js +0 -247
  38. package/lib/__tests__/hover-interaction.test.d.ts +0 -1
  39. package/lib/__tests__/hover-interaction.test.js +0 -374
  40. package/lib/__tests__/keyboard-interaction.test.d.ts +0 -1
  41. package/lib/__tests__/keyboard-interaction.test.js +0 -322
  42. package/lib/__tests__/lasso-interaction.test.d.ts +0 -1
  43. package/lib/__tests__/lasso-interaction.test.js +0 -219
  44. package/lib/__tests__/pan-interaction.test.d.ts +0 -1
  45. package/lib/__tests__/pan-interaction.test.js +0 -223
  46. package/lib/__tests__/utils.test.d.ts +0 -1
  47. package/lib/__tests__/utils.test.js +0 -19
  48. package/lib/__tests__/zoom-interaction.test.d.ts +0 -1
  49. package/lib/__tests__/zoom-interaction.test.js +0 -185
@@ -1,205 +1,183 @@
1
- import concaveman from 'concaveman';
2
- import { NODE_EDGE_WIDTH } from '../constants';
3
- import { OverlayRenderer } from '../overlay-renderer/overlay-renderer';
4
- import { BaseInteraction } from './base';
5
- import { getCanvasPosition, getWorldPosition, isDraggingMovement } from './utils';
1
+ import "../constants.js";
2
+ import { OverlayRenderer } from "../overlay-renderer/overlay-renderer.js";
3
+ import { BaseInteraction } from "./base.js";
4
+ import { getCanvasPosition, getWorldPosition, isDraggingMovement } from "./utils.js";
5
+ import concaveman from "concaveman";
6
+ // src/interaction-handlers/lasso-interaction.ts
6
7
  const pointDist = 10;
7
8
  const shapeShowTime = 500;
8
9
  /**
9
- * Checks if two lines defined by p1->p2 and p3->p4 are crossing.
10
- * @internal
11
- * @hidden
12
- */
13
- export const checkLinesCrossing = (p1, p2, p3, p4) => {
14
- const denom = (p4[1] - p3[1]) * (p2[0] - p1[0]) - (p4[0] - p3[0]) * (p2[1] - p1[1]);
15
- if (denom === 0) {
16
- // This means lines are parallell
17
- return false;
18
- }
19
- const t1 = ((p1[1] - p3[1]) * (p4[0] - p3[0]) - (p1[0] - p3[0]) * (p4[1] - p3[1])) / denom;
20
- const t2 = ((p3[0] - p1[0]) * (p2[1] - p1[1]) - (p3[1] - p1[1]) * (p2[0] - p1[0])) / denom;
21
- return t1 > 0 && t1 < 1 && t2 > 0 && t2 < 1;
10
+ * Checks if two lines defined by p1->p2 and p3->p4 are crossing.
11
+ * @internal
12
+ * @hidden
13
+ */
14
+ const checkLinesCrossing = (p1, p2, p3, p4) => {
15
+ const denom = (p4[1] - p3[1]) * (p2[0] - p1[0]) - (p4[0] - p3[0]) * (p2[1] - p1[1]);
16
+ if (denom === 0) return false;
17
+ const t1 = ((p1[1] - p3[1]) * (p4[0] - p3[0]) - (p1[0] - p3[0]) * (p4[1] - p3[1])) / denom;
18
+ const t2 = ((p3[0] - p1[0]) * (p2[1] - p1[1]) - (p3[1] - p1[1]) * (p2[0] - p1[0])) / denom;
19
+ return t1 > 0 && t1 < 1 && t2 > 0 && t2 < 1;
22
20
  };
23
21
  /**
24
- * Checks if any line segments in the polygon intersect.
25
- * @internal
26
- * @hidden
27
- */
28
- export const checkIntersection = (polygon) => {
29
- for (let i = 0; i < polygon.length - 1; i++) {
30
- for (let j = i + 2; j < polygon.length; j++) {
31
- const line1p1 = polygon[i] ?? [0, 0];
32
- const line1p2 = polygon[i + 1] ?? [0, 0];
33
- const line2p1 = polygon[j] ?? [0, 0];
34
- // Handle segment from first to last point
35
- const jNext = j < polygon.length - 1 ? j + 1 : 0;
36
- const line2p2 = polygon[jNext] ?? [0, 0];
37
- if (checkLinesCrossing(line1p1, line1p2, line2p1, line2p2)) {
38
- return true;
39
- }
40
- }
41
- }
42
- return false;
22
+ * Checks if any line segments in the polygon intersect.
23
+ * @internal
24
+ * @hidden
25
+ */
26
+ const checkIntersection = (polygon) => {
27
+ for (let i = 0; i < polygon.length - 1; i++) for (let j = i + 2; j < polygon.length; j++) {
28
+ const line1p1 = polygon[i] ?? [0, 0];
29
+ const line1p2 = polygon[i + 1] ?? [0, 0];
30
+ const line2p1 = polygon[j] ?? [0, 0];
31
+ const line2p2 = polygon[j < polygon.length - 1 ? j + 1 : 0] ?? [0, 0];
32
+ if (checkLinesCrossing(line1p1, line1p2, line2p1, line2p2)) return true;
33
+ }
34
+ return false;
43
35
  };
44
36
  /**
45
- * Checks if the point (x, y) is inside the polygon defined by vs.
46
- * @internal
47
- * @hidden
48
- */
49
- export const checkPointInside = (x, y, vs) => {
50
- // ray-casting algorithm based on
51
- // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
52
- let isInside = false;
53
- for (let i = 0, j = vs.length - 1; i < vs.length; j = i, i += 1) {
54
- const vsI = vs[i];
55
- const vsJ = vs[j];
56
- if (vsI === undefined || vsJ === undefined) {
57
- continue;
58
- }
59
- const { x: xi, y: yi } = vsI;
60
- const { x: xj, y: yj } = vsJ;
61
- const intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
62
- if (intersect) {
63
- isInside = !isInside;
64
- }
65
- }
66
- return isInside;
37
+ * Checks if the point (x, y) is inside the polygon defined by vs.
38
+ * @internal
39
+ * @hidden
40
+ */
41
+ const checkPointInside = (x, y, vs) => {
42
+ let isInside = false;
43
+ for (let i = 0, j = vs.length - 1; i < vs.length; j = i, i += 1) {
44
+ const vsI = vs[i];
45
+ const vsJ = vs[j];
46
+ if (vsI === void 0 || vsJ === void 0) continue;
47
+ const { x: xi, y: yi } = vsI;
48
+ const { x: xj, y: yj } = vsJ;
49
+ if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) isInside = !isInside;
50
+ }
51
+ return isInside;
67
52
  };
68
53
  /**
69
- * An interaction handler that lets you select nodes and relationships by drawing a lasso around them.
70
- * When dragging, a line is drawn on the scene and all elements inside are selected.
71
- *
72
- * For examples, head to the {@link https://neo4j.com/docs/nvl/current/interaction-handlers/#_lassointeraction Lasso Interaction documentation page}.
73
- */
74
- export class LassoInteraction extends BaseInteraction {
75
- active = false;
76
- lassoPending = false;
77
- startClientPosition = { x: 0, y: 0 };
78
- pendingPointerCanvas = { x: 0, y: 0 };
79
- points = [];
80
- overlayRenderer;
81
- /**
82
- * Creates a new instance of the lasso interaction handler.
83
- * @param nvl - The NVL instance to attach the interaction handler to.
84
- * @param options - Options for the lasso interaction handler to customize its behavior.
85
- */
86
- constructor(nvl, options = { selectOnRelease: false }) {
87
- super(nvl, options);
88
- this.overlayRenderer = new OverlayRenderer(this.containerInstance);
89
- this.addEventListener('mousedown', this.handleMouseDown, true);
90
- this.addEventListener('mousemove', this.handleDrag, true);
91
- this.addEventListener('mouseup', this.handleMouseUp, true);
92
- }
93
- startLasso = (event) => {
94
- const hits = this.nvlInstance.getHits(event, ['node'], { hitNodeMarginWidth: NODE_EDGE_WIDTH });
95
- if (hits.nvlTargets.nodes.length > 0) {
96
- this.active = false;
97
- this.lassoPending = false;
98
- }
99
- else {
100
- this.lassoPending = true;
101
- this.startClientPosition = { x: event.clientX, y: event.clientY };
102
- this.pendingPointerCanvas = getCanvasPosition(this.containerInstance, event);
103
- }
104
- };
105
- handleMouseDown = (event) => {
106
- if (event.button === 0 && !this.active && !this.lassoPending) {
107
- this.startLasso(event);
108
- }
109
- };
110
- handleDrag = (event) => {
111
- if (this.active) {
112
- const lastPoint = this.points[this.points.length - 1];
113
- if (lastPoint === undefined) {
114
- return;
115
- }
116
- const pos = getCanvasPosition(this.containerInstance, event);
117
- const dx = Math.abs(lastPoint.x - pos.x);
118
- const dy = Math.abs(lastPoint.y - pos.y);
119
- if (dx > pointDist || dy > pointDist) {
120
- this.points.push(pos);
121
- this.overlayRenderer.drawLasso(this.points, true, false);
122
- }
123
- return;
124
- }
125
- if (this.lassoPending && event.buttons === 1) {
126
- if (isDraggingMovement(event, this.startClientPosition)) {
127
- this.activateLasso(event);
128
- }
129
- }
130
- };
131
- activateLasso = (event) => {
132
- this.lassoPending = false;
133
- this.active = true;
134
- const pos = getCanvasPosition(this.containerInstance, event);
135
- this.points = [this.pendingPointerCanvas, pos];
136
- this.toggleGlobalTextSelection(false, this.endLasso);
137
- this.callCallbackIfRegistered('onLassoStarted', event);
138
- if (this.currentOptions.selectOnRelease === true) {
139
- this.nvlInstance.deselectAll();
140
- }
141
- this.overlayRenderer.drawLasso(this.points, true, false);
142
- };
143
- handleMouseUp = (event) => {
144
- if (!this.active) {
145
- this.lassoPending = false;
146
- return;
147
- }
148
- this.points.push(getCanvasPosition(this.containerInstance, event));
149
- this.endLasso(event);
150
- };
151
- getLassoItems = (points) => {
152
- const worldPoints = points.map((p) => getWorldPosition(this.nvlInstance, p));
153
- const nodePositions = this.nvlInstance.getNodePositions();
154
- const hitNodes = new Set();
155
- for (const pos of nodePositions) {
156
- if (pos.x === undefined || pos.y === undefined || pos.id === undefined) {
157
- continue;
158
- }
159
- if (checkPointInside(pos.x, pos.y, worldPoints)) {
160
- hitNodes.add(pos.id);
161
- }
162
- }
163
- const rels = this.nvlInstance.getRelationships();
164
- const hitRels = [];
165
- for (const rel of rels) {
166
- if (hitNodes.has(rel.from) && hitNodes.has(rel.to)) {
167
- hitRels.push(rel);
168
- }
169
- }
170
- const hitNodeArray = Array.from(hitNodes).map((id) => this.nvlInstance.getNodeById(id));
171
- return {
172
- nodes: hitNodeArray,
173
- rels: hitRels
174
- };
175
- };
176
- endLasso = (event) => {
177
- if (!this.active) {
178
- return;
179
- }
180
- this.active = false;
181
- this.toggleGlobalTextSelection(true, this.endLasso);
182
- const pointArrays = this.points.map((p) => [p.x, p.y]);
183
- const hasCrossings = checkIntersection(pointArrays);
184
- const hull = (hasCrossings ? concaveman(pointArrays, 2) : pointArrays)
185
- .map((p) => ({ x: p[0], y: p[1] }))
186
- .filter((point) => point.x !== undefined && point.y !== undefined);
187
- this.overlayRenderer.drawLasso(hull, false, true);
188
- setTimeout(() => this.overlayRenderer.clear(), shapeShowTime);
189
- const hitItems = this.getLassoItems(hull);
190
- if (this.currentOptions.selectOnRelease === true) {
191
- this.nvlInstance.updateElementsInGraph(hitItems.nodes.map((node) => ({ id: node.id, selected: true })), hitItems.rels.map((rel) => ({ id: rel.id, selected: true })));
192
- }
193
- this.callCallbackIfRegistered('onLassoSelect', hitItems, event);
194
- };
195
- /**
196
- * Removes all related event listeners and the overlay renderer for the box.
197
- */
198
- destroy() {
199
- this.toggleGlobalTextSelection(true, this.endLasso);
200
- this.removeEventListener('mousedown', this.handleMouseDown, true);
201
- this.removeEventListener('mousemove', this.handleDrag, true);
202
- this.removeEventListener('mouseup', this.handleMouseUp, true);
203
- this.overlayRenderer.destroy();
204
- }
205
- }
54
+ * An interaction handler that lets you select nodes and relationships by drawing a lasso around them.
55
+ * When dragging, a line is drawn on the scene and all elements inside are selected.
56
+ *
57
+ * For examples, head to the {@link https://neo4j.com/docs/nvl/current/interaction-handlers/#_lassointeraction Lasso Interaction documentation page}.
58
+ */
59
+ var LassoInteraction = class extends BaseInteraction {
60
+ active = false;
61
+ lassoPending = false;
62
+ startClientPosition = {
63
+ x: 0,
64
+ y: 0
65
+ };
66
+ pendingPointerCanvas = {
67
+ x: 0,
68
+ y: 0
69
+ };
70
+ points = [];
71
+ overlayRenderer;
72
+ /**
73
+ * Creates a new instance of the lasso interaction handler.
74
+ * @param nvl - The NVL instance to attach the interaction handler to.
75
+ * @param options - Options for the lasso interaction handler to customize its behavior.
76
+ */
77
+ constructor(nvl, options = { selectOnRelease: false }) {
78
+ super(nvl, options);
79
+ this.overlayRenderer = new OverlayRenderer(this.containerInstance);
80
+ this.addEventListener("mousedown", this.handleMouseDown, true);
81
+ this.addEventListener("mousemove", this.handleDrag, true);
82
+ this.addEventListener("mouseup", this.handleMouseUp, true);
83
+ }
84
+ startLasso = (event) => {
85
+ if (this.nvlInstance.getHits(event, ["node"], { hitNodeMarginWidth: 10 }).nvlTargets.nodes.length > 0) {
86
+ this.active = false;
87
+ this.lassoPending = false;
88
+ } else {
89
+ this.lassoPending = true;
90
+ this.startClientPosition = {
91
+ x: event.clientX,
92
+ y: event.clientY
93
+ };
94
+ this.pendingPointerCanvas = getCanvasPosition(this.containerInstance, event);
95
+ }
96
+ };
97
+ handleMouseDown = (event) => {
98
+ if (event.button === 0 && !this.active && !this.lassoPending) this.startLasso(event);
99
+ };
100
+ handleDrag = (event) => {
101
+ if (this.active) {
102
+ const lastPoint = this.points[this.points.length - 1];
103
+ if (lastPoint === void 0) return;
104
+ const pos = getCanvasPosition(this.containerInstance, event);
105
+ const dx = Math.abs(lastPoint.x - pos.x);
106
+ const dy = Math.abs(lastPoint.y - pos.y);
107
+ if (dx > pointDist || dy > pointDist) {
108
+ this.points.push(pos);
109
+ this.overlayRenderer.drawLasso(this.points, true, false);
110
+ }
111
+ return;
112
+ }
113
+ if (this.lassoPending && event.buttons === 1) {
114
+ if (isDraggingMovement(event, this.startClientPosition)) this.activateLasso(event);
115
+ }
116
+ };
117
+ activateLasso = (event) => {
118
+ this.lassoPending = false;
119
+ this.active = true;
120
+ const pos = getCanvasPosition(this.containerInstance, event);
121
+ this.points = [this.pendingPointerCanvas, pos];
122
+ this.toggleGlobalTextSelection(false, this.endLasso);
123
+ this.callCallbackIfRegistered("onLassoStarted", event);
124
+ if (this.currentOptions.selectOnRelease === true) this.nvlInstance.deselectAll();
125
+ this.overlayRenderer.drawLasso(this.points, true, false);
126
+ };
127
+ handleMouseUp = (event) => {
128
+ if (!this.active) {
129
+ this.lassoPending = false;
130
+ return;
131
+ }
132
+ this.points.push(getCanvasPosition(this.containerInstance, event));
133
+ this.endLasso(event);
134
+ };
135
+ getLassoItems = (points) => {
136
+ const worldPoints = points.map((p) => getWorldPosition(this.nvlInstance, p));
137
+ const nodePositions = this.nvlInstance.getNodePositions();
138
+ const hitNodes = /* @__PURE__ */ new Set();
139
+ for (const pos of nodePositions) {
140
+ if (pos.x === void 0 || pos.y === void 0 || pos.id === void 0) continue;
141
+ if (checkPointInside(pos.x, pos.y, worldPoints)) hitNodes.add(pos.id);
142
+ }
143
+ const rels = this.nvlInstance.getRelationships();
144
+ const hitRels = [];
145
+ for (const rel of rels) if (hitNodes.has(rel.from) && hitNodes.has(rel.to)) hitRels.push(rel);
146
+ return {
147
+ nodes: Array.from(hitNodes).map((id) => this.nvlInstance.getNodeById(id)),
148
+ rels: hitRels
149
+ };
150
+ };
151
+ endLasso = (event) => {
152
+ if (!this.active) return;
153
+ this.active = false;
154
+ this.toggleGlobalTextSelection(true, this.endLasso);
155
+ const pointArrays = this.points.map((p) => [p.x, p.y]);
156
+ const hull = (checkIntersection(pointArrays) ? concaveman(pointArrays, 2) : pointArrays).map((p) => ({
157
+ x: p[0],
158
+ y: p[1]
159
+ })).filter((point) => point.x !== void 0 && point.y !== void 0);
160
+ this.overlayRenderer.drawLasso(hull, false, true);
161
+ setTimeout(() => this.overlayRenderer.clear(), shapeShowTime);
162
+ const hitItems = this.getLassoItems(hull);
163
+ if (this.currentOptions.selectOnRelease === true) this.nvlInstance.updateElementsInGraph(hitItems.nodes.map((node) => ({
164
+ id: node.id,
165
+ selected: true
166
+ })), hitItems.rels.map((rel) => ({
167
+ id: rel.id,
168
+ selected: true
169
+ })));
170
+ this.callCallbackIfRegistered("onLassoSelect", hitItems, event);
171
+ };
172
+ /**
173
+ * Removes all related event listeners and the overlay renderer for the box.
174
+ */
175
+ destroy() {
176
+ this.toggleGlobalTextSelection(true, this.endLasso);
177
+ this.removeEventListener("mousedown", this.handleMouseDown, true);
178
+ this.removeEventListener("mousemove", this.handleDrag, true);
179
+ this.removeEventListener("mouseup", this.handleMouseUp, true);
180
+ this.overlayRenderer.destroy();
181
+ }
182
+ };
183
+ export { LassoInteraction, checkIntersection, checkLinesCrossing, checkPointInside };
@@ -1,35 +1,35 @@
1
- import type { NVL } from '@neo4j-nvl/base';
2
- import { BaseInteraction } from './base';
1
+ import { BaseInteraction } from "./base.js";
2
+ import { NVL } from "@neo4j-nvl/base";
3
3
  /**
4
4
  * Options for the pan interaction handler to customize its behavior.
5
5
  */
6
6
  export type PanInteractionOptions = {
7
- /**
8
- * Whether to not pan when dragging within a certain margin of a node
9
- * @defaultValue false
10
- */
11
- excludeNodeMargin?: boolean;
12
- /**
13
- * If true, the interaction handler will not update the NVL instance directly.
14
- * Instead, it will only call the onPan callback with the calculated values,
15
- * allowing the parent application to control when and how to apply the pan update.
16
- * @defaultValue false
17
- */
18
- controlledPan?: boolean;
7
+ /**
8
+ * Whether to not pan when dragging within a certain margin of a node
9
+ * @defaultValue false
10
+ */
11
+ excludeNodeMargin?: boolean;
12
+ /**
13
+ * If true, the interaction handler will not update the NVL instance directly.
14
+ * Instead, it will only call the onPan callback with the calculated values,
15
+ * allowing the parent application to control when and how to apply the pan update.
16
+ * @defaultValue false
17
+ */
18
+ controlledPan?: boolean;
19
19
  };
20
20
  /**
21
21
  * Callbacks for the pan interaction handler.
22
22
  */
23
23
  export type PanInteractionCallbacks = {
24
- /**
25
- * Called when the canvas is panned.
26
- * @param panning - The panning coordinates.
27
- * @param event - The original mouse event.
28
- */
29
- onPan?: ((panning: {
30
- x: number;
31
- y: number;
32
- }, event: MouseEvent) => void) | boolean;
24
+ /**
25
+ * Called when the canvas is panned.
26
+ * @param panning - The panning coordinates.
27
+ * @param event - The original mouse event.
28
+ */
29
+ onPan?: ((panning: {
30
+ x: number;
31
+ y: number;
32
+ }, event: MouseEvent) => void) | boolean;
33
33
  };
34
34
  /**
35
35
  * Interaction handler for panning the scene, which is achieved by clicking and moving the scene.
@@ -37,41 +37,42 @@ export type PanInteractionCallbacks = {
37
37
  * For examples, head to the {@link https://neo4j.com/docs/nvl/current/interaction-handlers/#_paninteraction Pan Interaction documentation page}.
38
38
  */
39
39
  export declare class PanInteraction extends BaseInteraction<PanInteractionOptions> {
40
- private initialMousePosition;
41
- private initialPan;
42
- private targets;
43
- private shouldPan;
44
- private isPanning;
45
- /**
46
- * Creates a new instance of the pan interaction handler.
47
- * @param nvl - The NVL instance to attach the interaction handler to.
48
- */
49
- constructor(nvl: NVL, options?: PanInteractionOptions);
50
- /**
51
- * Updates which type of graph elements should hinder panning.
52
- * @param targets - The graph elements that should hinder panning.
53
- * @param excludeNodeMargin - If true, the node margin will not hinder panning.
54
- * By default, panning is hindered by nodes and relationships.
55
- *
56
- * @example
57
- * ```js
58
- * import { NVL } from '@neo4j-nvl/base'
59
- * import { PanInteraction } from '@neo4j-nvl/interaction-handlers'
60
- *
61
- * const nvl = new NVL(document.createElement('div'), [{ id: '0' }], [])
62
- * const panInteraction = new PanInteraction(nvl)
63
- *
64
- * // Pan canvas even when dragging on nodes and relationships
65
- * panInteraction.updateTargets([], true)
66
- * ```
67
- */
68
- updateTargets: (targets: ("node" | "relationship")[], excludeNodeMargin: boolean) => void;
69
- private handleMouseDown;
70
- private handleMouseMove;
71
- private handleMouseUp;
72
- private resetPanState;
73
- /**
74
- * Removes the related event listeners from the canvas.
75
- */
76
- destroy(): void;
77
- }
40
+ private initialMousePosition;
41
+ private initialPan;
42
+ private targets;
43
+ private shouldPan;
44
+ private isPanning;
45
+ /**
46
+ * Creates a new instance of the pan interaction handler.
47
+ * @param nvl - The NVL instance to attach the interaction handler to.
48
+ */
49
+ constructor(nvl: NVL, options?: PanInteractionOptions);
50
+ /**
51
+ * Updates which type of graph elements should hinder panning.
52
+ * @param targets - The graph elements that should hinder panning.
53
+ * @param excludeNodeMargin - If true, the node margin will not hinder panning.
54
+ * By default, panning is hindered by nodes and relationships.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { NVL } from '@neo4j-nvl/base'
59
+ * import { PanInteraction } from '@neo4j-nvl/interaction-handlers'
60
+ *
61
+ * const nvl = new NVL(document.createElement('div'), [{ id: '0' }], [])
62
+ *
63
+ * const panInteraction = new PanInteraction(nvl)
64
+ *
65
+ * // Pan canvas even when dragging on nodes and relationships
66
+ * panInteraction.updateTargets([], true)
67
+ * ```
68
+ */
69
+ updateTargets: (targets: ("node" | "relationship")[], excludeNodeMargin: boolean) => void;
70
+ private handleMouseDown;
71
+ private handleMouseMove;
72
+ private handleMouseUp;
73
+ private resetPanState;
74
+ /**
75
+ * Removes the related event listeners from the canvas.
76
+ */
77
+ destroy(): void;
78
+ }