@neo4j-nvl/interaction-handlers 0.2.27 → 0.2.29

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.
@@ -1,4 +1,4 @@
1
- import { NVL } from '@neo4j-nvl/core';
1
+ import type { NVL } from '@neo4j-nvl/core';
2
2
  /**
3
3
  * Base class for all interactions.
4
4
  * @abstract
@@ -1,4 +1,4 @@
1
- import { NVL, Node, Relationship } from '@neo4j-nvl/core';
1
+ import type { NVL, Node, Relationship } from '@neo4j-nvl/core';
2
2
  import { BaseInteraction } from './base';
3
3
  /**
4
4
  * @internal
@@ -107,8 +107,7 @@ export class DrawInteraction extends BaseInteraction {
107
107
  to: targetNode ? targetNode.id : newTargetNodeId,
108
108
  captions: [{ value: 'TEST' }]
109
109
  };
110
- let x = pos.x;
111
- let y = pos.y;
110
+ let { x, y } = pos;
112
111
  let size = 25;
113
112
  if (hitNode) {
114
113
  x = hitNode.targetCoordinates.x;
@@ -52,18 +52,18 @@ export class HoverInteraction extends BaseInteraction {
52
52
  value: (event) => {
53
53
  const { nvlTargets } = this.nvlInstance.getHits(event);
54
54
  const { nodes = [], relationships = [] } = nvlTargets;
55
- const mainTarget = nodes[0] || relationships[0];
55
+ const mainTarget = nodes[0] !== undefined ? nodes[0] : relationships[0];
56
56
  const hoveredElement = mainTarget === null || mainTarget === void 0 ? void 0 : mainTarget.data;
57
57
  if (this.currentElementNeedsUnHover(hoveredElement === null || hoveredElement === void 0 ? void 0 : hoveredElement.id)) {
58
58
  this.unHoverCurrentElement();
59
59
  }
60
- const currentHoveredElementIsNode = hoveredElement && nodes[0] !== undefined;
60
+ const currentHoveredElementIsNode = hoveredElement !== undefined && nodes[0] !== undefined;
61
61
  if (currentHoveredElementIsNode) {
62
62
  this.updates.nodes.push({ id: hoveredElement.id, hovered: true });
63
63
  this.currentHoveredElement = hoveredElement;
64
64
  this.currentHoveredElementIsNode = true;
65
65
  }
66
- else if (mainTarget) {
66
+ else if (mainTarget !== undefined) {
67
67
  const { id, from, to } = hoveredElement;
68
68
  this.updates.relationships.push({ id, from, to, hovered: true });
69
69
  this.currentHoveredElement = hoveredElement;
@@ -75,9 +75,12 @@ export class HoverInteraction extends BaseInteraction {
75
75
  }
76
76
  this.callCallbackIfRegistered('onHover', this.currentHoveredElement, nvlTargets, event);
77
77
  // Use pure update API to avoid the previous removed node to be re-added to the scene.
78
- this.options.drawShadowOnHover &&
79
- this.nvlInstance.nodes.length > 0 &&
80
- this.nvlInstance.updateElementsInGraph(this.updates.nodes, this.updates.relationships);
78
+ if (this.options.drawShadowOnHover) {
79
+ const currentNodes = this.nvlInstance.getNodes();
80
+ if (currentNodes.length > 0) {
81
+ this.nvlInstance.updateElementsInGraph(this.updates.nodes, this.updates.relationships);
82
+ }
83
+ }
81
84
  this.clearUpdates();
82
85
  }
83
86
  });
@@ -1,4 +1,4 @@
1
- import { NVL } from '@neo4j-nvl/core';
1
+ import type { NVL } from '@neo4j-nvl/core';
2
2
  import { BaseInteraction } from './base';
3
3
  /**
4
4
  * Options for the click interaction handler to customize its behavior.
@@ -59,7 +59,7 @@ export declare class PanInteraction extends BaseInteraction<PanInteractionCallba
59
59
  * panInteraction.updateTargets([], true)
60
60
  * ```
61
61
  */
62
- updateTargets: (targets: Array<'node' | 'relationship'>, excludeNodeMargin: boolean) => void;
62
+ updateTargets: (targets: ('node' | 'relationship')[], excludeNodeMargin: boolean) => void;
63
63
  private handleMouseDown;
64
64
  private handleMouseMove;
65
65
  private handleMouseUp;
@@ -1,4 +1,4 @@
1
- import { NVL } from '@neo4j-nvl/core';
1
+ import type { NVL } from '@neo4j-nvl/core';
2
2
  import { BaseInteraction } from './base';
3
3
  /**
4
4
  * Callbacks for the zoom interaction handler.
@@ -49,8 +49,8 @@ export class OverlayRenderer {
49
49
  _fixCanvasSize(canvas) {
50
50
  const parent = canvas.parentElement;
51
51
  const rect = parent.getBoundingClientRect();
52
- const width = rect.width;
53
- const height = rect.height;
52
+ const { width } = rect;
53
+ const { height } = rect;
54
54
  const devicePixelRatio = window.devicePixelRatio || 1;
55
55
  canvas.width = width * devicePixelRatio;
56
56
  canvas.height = height * devicePixelRatio;
@@ -75,8 +75,9 @@ export class OverlayRenderer {
75
75
  const localStartY = (startY - rect.top) * devicePixelRatio;
76
76
  const localEndX = (endX - rect.left) * devicePixelRatio;
77
77
  const localEndY = (endY - rect.top) * devicePixelRatio;
78
- if (!this._ctx)
78
+ if (!this._ctx) {
79
79
  return;
80
+ }
80
81
  this._ctx.beginPath();
81
82
  this._ctx.rect(localStartX, localStartY, localEndX - localStartX, localEndY - localStartY);
82
83
  this._ctx.closePath();
@@ -100,8 +101,9 @@ export class OverlayRenderer {
100
101
  clear() {
101
102
  const rect = this.canvas.getBoundingClientRect();
102
103
  const devicePixelRatio = window.devicePixelRatio || 1;
103
- if (!this._ctx)
104
+ if (!this._ctx) {
104
105
  return;
106
+ }
105
107
  this._ctx.clearRect(0, 0, rect.width * devicePixelRatio, rect.height * devicePixelRatio);
106
108
  }
107
109
  destroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/interaction-handlers",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
4
4
  "license": "SEE LICENSE IN 'Neo4j Early Access Agreement - Visualization Library.pdf'",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",