@neo4j-nvl/base 0.3.5 → 0.3.6-379b7fef

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,5 +1,16 @@
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <https://feross.org>
5
+ * @license MIT
6
+ */
7
+
8
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
9
+
1
10
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2
11
 
12
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
13
+
3
14
  /**
4
15
  * @license
5
16
  * Lodash <https://lodash.com/>
@@ -7,6 +7,8 @@ import type { Node, PartialNode, PartialRelationship, Relationship } from './typ
7
7
  import { CompatibilityError } from './utils/errors';
8
8
  import type { Point } from './utils/geometry';
9
9
  import type { HitTargetNode, HitTargetRelationship, HitTargets } from './utils/hittest';
10
+ import { nvlResultTransformer } from './utils/jsDriverResultTransformer';
11
+ import { getZoomTargetForNodePositions } from './utils/zoomFunctions';
10
12
  /**
11
13
  * Extends the MouseEvent interface with the {@link HitTargets} property.
12
14
  * The result of a _.{@link NVL.getHits} call.
@@ -185,7 +187,7 @@ declare class NVL {
185
187
  * the zoom level will be set to the closest valid zoom level,
186
188
  * even if the given nodes do not fit the viewport yet.
187
189
  */
188
- fit(nodeIds: string[], zoomOptions: NvlState['zoomOptions']): void;
190
+ fit(nodeIds: string[], zoomOptions?: NvlState['zoomOptions']): void;
189
191
  /**
190
192
  * Resets the zoom of the viewport back to the default zoom level of 0.75
191
193
  */
@@ -363,4 +365,4 @@ declare const colorMapperFunctions: {
363
365
  };
364
366
  export default NVL;
365
367
  export type { NvlOptions, Renderer, Node, Relationship, PartialNode, PartialRelationship, Layout, LayoutOptions, ForceDirectedOptions, HierarchicalOptions, ExternalCallbacks, HitTargets, HitTargetNode, HitTargetRelationship, Point, NvlMouseEvent, ZoomOptions, StyledCaption, WebGLRendererType, CanvasRendererType };
366
- export { NVL, colorMapperFunctions, CompatibilityError, ForceDirectedLayoutType, HierarchicalLayoutType, GridLayoutType, FreeLayoutType, d3ForceLayoutType, drawCircleBand };
368
+ export { NVL, colorMapperFunctions, CompatibilityError, ForceDirectedLayoutType, HierarchicalLayoutType, GridLayoutType, FreeLayoutType, d3ForceLayoutType, drawCircleBand, nvlResultTransformer, getZoomTargetForNodePositions };
@@ -15,13 +15,13 @@ export declare class CoseBilkentLayout extends AnimatedLayout {
15
15
  cytoCompleteCallback: () => void;
16
16
  computing: boolean;
17
17
  pendingLayoutData: LayoutData;
18
- worker: SharedWorker | any;
18
+ worker: SharedWorker;
19
19
  constructor(config: {
20
20
  state: NvlState;
21
21
  cytoCompleteCallback?: () => void;
22
22
  animationCompleteCallback?: () => void;
23
23
  });
24
- setupWorker(): Promise<unknown>;
24
+ setupWorker(): Promise<SharedWorker>;
25
25
  setOptions(): void;
26
26
  update(refreshPositions?: boolean, updateMobXNodes?: Node[], updateMobXRelationships?: Relationship[]): void;
27
27
  getShouldUpdate(): boolean;
@@ -19,7 +19,7 @@ export default class SolarMerger {
19
19
  idToRel: {};
20
20
  };
21
21
  nodeSortMap: {};
22
- coarsenBy(level: any): {
22
+ coarsenBy(levelToCoarsenBy: any): {
23
23
  nodes: any[];
24
24
  relationships: any[];
25
25
  idToRel: {};
@@ -7,7 +7,7 @@ export class GridLayout {
7
7
  setOptions(options: any): void;
8
8
  updateNodes(positionList: any): void;
9
9
  update(refreshPositions?: boolean): void;
10
- layout(nodes: any, nodeIds: any, idToPosition: any, rels: any): void;
10
+ layout(mobxNodes: any, nodeIds: any, idToPosition: any, rels: any): void;
11
11
  getNodePositions(nodeList: any): any[];
12
12
  getShouldUpdate(): boolean;
13
13
  getComputing(): boolean;
@@ -15,7 +15,7 @@ export declare class HierarchicalLayout extends AnimatedLayout {
15
15
  private directionChanged;
16
16
  private packingChanged;
17
17
  constructor(config: HierarchicalLayoutConfig);
18
- setupWorker(): Promise<unknown>;
18
+ setupWorker(): Promise<SharedWorker>;
19
19
  setOptions(options: LayoutOptions): void;
20
20
  update(refreshPositions?: boolean): void;
21
21
  getShouldUpdate(): boolean;
@@ -12,12 +12,15 @@ export interface ExternalCallbacks {
12
12
  /** Triggered when a asynchronous layout calculation starts/stops. */
13
13
  onLayoutComputing?: (isComputing: boolean) => void;
14
14
  onWebGLContextLost?: (webGLContextEvent: WebGLContextEvent) => void;
15
+ /** Triggered when a zoom transition (e.g. {@link NVL.fit} or {@link NVL.resetZoom}) function is done. */
16
+ onZoomTransitionDone?: () => void;
15
17
  restart?: () => void;
16
18
  }
17
19
  export declare const isExternalCallback: (callback: unknown) => callback is keyof ExternalCallbacks;
18
20
  export default class ExternalCallbackHandler {
19
21
  callbacks: ExternalCallbacks;
20
22
  constructor(externalCallbacks?: ExternalCallbacks);
23
+ onZoomTransitionDone(): void;
21
24
  onLayoutDone(): void;
22
25
  onLayoutStep(p: Node[]): void;
23
26
  onLayoutComputing(isComputing: boolean): void;
@@ -8,6 +8,7 @@ type SaveToFileOptions = {
8
8
  backgroundColor?: string;
9
9
  };
10
10
  export declare const EVENT_ERROR = "onError";
11
+ export declare const EVENT_ZOOM_TRANSITION_DONE = "onZoomTransitionDone";
11
12
  export declare const EVENT_LAYOUT_DONE = "onLayoutDone";
12
13
  export declare const EVENT_LAYOUT_STEP = "onLayoutStep";
13
14
  export declare const EVENT_LAYOUT_COMPUTING = "onLayoutComputing";
@@ -95,7 +96,7 @@ export default class NvlController {
95
96
  setZoomLevel(_newLevel: number): void;
96
97
  setPanCoordinates(panX: number, panY: number): void;
97
98
  setZoomAndPan(zoom: number, panX: number, panY: number): void;
98
- fit(nodeIds: string[], zoomOptions: ZoomOptions): void;
99
+ fit(nodeIds: string[], zoomOptions?: ZoomOptions): void;
99
100
  resetZoom(): void;
100
101
  setRenderer(renderer: string): void;
101
102
  on(name: keyof ExternalCallbacks, callback: (args: unknown) => void): void;
@@ -9,16 +9,14 @@ export default class ZoomTransitionHandler {
9
9
  private firstUpdate;
10
10
  private readonly state;
11
11
  private readonly canvas;
12
- private readonly defaultZoomLevel;
13
12
  private readonly stateDisposers;
14
- constructor({ state, getNodePositions, canvas, defaultZoomLevel }: {
13
+ constructor({ state, getNodePositions, canvas }: {
15
14
  state: NvlState;
16
15
  getNodePositions: (data: Node[]) => Node[];
17
16
  canvas: HTMLCanvasElement;
18
- defaultZoomLevel: number;
19
17
  });
20
18
  needsToRun(): boolean;
21
- update(layoutActive: boolean): void;
19
+ update(layoutActive: boolean, onTransitionCompleted?: () => void): void;
22
20
  destroy(): void;
23
21
  private recalculateTarget;
24
22
  private allNodesAreVisible;
@@ -13,10 +13,10 @@ export default class PerformanceTester {
13
13
  /**
14
14
  * Starts a performance measurement. Every call to this method must be followed
15
15
  * by a call to endTest(). Tests can be nested.
16
- * @param {String} name String identifying this measurement. Only used for printing, so
16
+ * @param {String} measurement String identifying this measurement. Only used for printing, so
17
17
  * keep it human readable.
18
18
  */
19
- startTest(name: string): void;
19
+ startTest(measurement: string): void;
20
20
  /**
21
21
  * Ends the last started test, giving it an end time.
22
22
  */
@@ -130,7 +130,12 @@ export interface NvlOptions {
130
130
  * The DOM element in which to render the graph visualization
131
131
  */
132
132
  frame?: HTMLElement;
133
- /** The DOM container in which to render the minimap */
133
+ /**
134
+ * The DOM container in which to render the minimap.
135
+ *
136
+ * @note When using a React ref, make sure the attached element is rendered before the NVL instance is created.
137
+ * Otherwise, the minimap will not be displayed.
138
+ */
134
139
  minimapContainer?: HTMLElement;
135
140
  /** Configuration for the current layout */
136
141
  layoutOptions?: LayoutOptions;
@@ -196,6 +201,8 @@ export type ZoomOptions = {
196
201
  minZoom?: number;
197
202
  /** The maximum zoom value for the fit-to-zoom operation. */
198
203
  maxZoom?: number;
204
+ /** If true, will not animate the zoom/pan transition. */
205
+ animated?: boolean;
199
206
  };
200
207
  export interface NvlState {
201
208
  zoom: number;
@@ -65,9 +65,15 @@ interface Node extends GraphElement {
65
65
  size?: number;
66
66
  /** Whether or not the current node is pinned.*/
67
67
  pinned?: boolean;
68
- /** The x-coordinate for the position of the node.*/
68
+ /**
69
+ * @ignore
70
+ * The x-coordinate for the position of the node.
71
+ */
69
72
  x?: number;
70
- /** The y-coordinate for the position of the node.*/
73
+ /**
74
+ * @ignore
75
+ * The y-coordinate for the position of the node.
76
+ */
71
77
  y?: number;
72
78
  /** Whether or not the current node is activated.*/
73
79
  activated?: boolean;
@@ -0,0 +1,32 @@
1
+ import type { Node as DriverNode, Relationship as DriverRelationship, Path, Record } from 'neo4j-driver';
2
+ export declare const recordMapper: (record: Record) => any[];
3
+ export declare const recordCollector: (graphElements: (DriverNode | DriverRelationship | Path)[][]) => {
4
+ recordObjectMap: Map<any, any>;
5
+ nodes: any[];
6
+ relationships: any[];
7
+ };
8
+ /**
9
+ * Result transformer for the Neo4j JavaScript driver results to NVL graph elements.
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * import neo4j from "neo4j-driver";
14
+ * import { nvlResultTransformer, NVL } from "@neo4j-nvl/base";
15
+ *
16
+ * const driver = neo4j.driver("{uri}", neo4j.auth.basic("{user}", "{password}"));
17
+ * const nvlGraph = await driver.executeQuery(
18
+ * "MATCH (a)-[r]-(b) RETURN a,r,b LIMIT 25",
19
+ * {},
20
+ * { resultTransformer: nvlResultTransformer }
21
+ * );
22
+ *
23
+ * const nvl = new NVL(document.getElementById('viz'), nvlGraph.nodes, nvlGraph.relationships);
24
+ * ```
25
+ *
26
+ * @see {@link https://neo4j.com/docs/api/javascript-driver/current/class/lib6/result-transformers.js~ResultTransformers.html|ResultTransformers on Neo4j JS Driver API Docs}
27
+ */
28
+ export declare const nvlResultTransformer: import("neo4j-driver-core/types/result-transformers").ResultTransformer<{
29
+ recordObjectMap: Map<any, any>;
30
+ nodes: any[];
31
+ relationships: any[];
32
+ }>;
@@ -2,19 +2,50 @@ import type { Node } from '../index';
2
2
  import type { Point } from './geometry';
3
3
  declare const getExtremeLimits: (nodePositions: Point[]) => Point[];
4
4
  declare const getMaxDistance: (extremeLimits?: Point[]) => number;
5
+ /**
6
+ * Gets the center choordinates and the width and height for the given node positions
7
+ * @param {Point[] | Node[]} nodePositions - The node positions
8
+ * @param {number} maxNodeRadius - The maximum node radius
9
+ * @returns An object with the center x and y coordinates and the width and height
10
+ */
5
11
  declare const getPositionBoundaries: (nodePositions?: Point[] | Node[], maxNodeRadius?: number) => {
6
12
  centerX: number;
7
13
  centerY: number;
8
14
  nodesWidth: number;
9
15
  nodesHeight: number;
10
16
  };
17
+ /**
18
+ * Gets the required zoom level for the given view and scene dimensions to fit the scene into the view
19
+ * @param {number} viewWidth - The width of the required view
20
+ * @param {number} viewHeight - The height of the required view
21
+ * @param {number} sceneWidth - The width of the canvas scene
22
+ * @param {number} sceneHeight - The height of the canvas scene
23
+ * @returns An object with the zoom level for the x and y axis
24
+ */
11
25
  declare const getZoomLevel: (viewWidth: number, viewHeight: number, sceneWidth: number, sceneHeight: number) => {
12
26
  zoomX: number;
13
27
  zoomY: number;
14
28
  };
29
+ /**
30
+ * Creates a zoom target based on the given zoom levels and the min and max zoom level
31
+ * @param {number} zoomX - The zoom level for the x axis
32
+ * @param {number} zoomY - The zoom level for the y axis
33
+ * @param {number} minZoom - The minimum zoom level
34
+ * @param {number} maxZoom - The maximum zoom level
35
+ * @returns The zoom target
36
+ */
15
37
  declare const createZoomTarget: (zoomX: number, zoomY: number, minZoom?: number, maxZoom?: number) => number;
38
+ /**
39
+ * Gets the zoom target to fit the given node positions into the scene
40
+ * @param {Point[]} nodePositions - The node positions
41
+ * @param {number} containerWidth - The width of the container NVL is displayed in
42
+ * @param {number} containerHeight - The height of the container NVL is displayed in
43
+ * @param {number} maxNodeRadius - The maximum node radius, which is added as margin to the scene (defaults to `50`)
44
+ * @returns
45
+ */
46
+ declare const getZoomTargetForNodePositions: (nodePositions: Point[], containerWidth: number, containerHeight: number, maxNodeRadius?: number) => number;
16
47
  declare const getFlexibleZoomLimit: (nodePositions: Point[], rect: HTMLCanvasElement, maxNodeRadius: number) => number;
17
48
  declare const getNewZoomWithinLimits: (newZoom: number, oldZoom: number, minZoom: number, maxZoom: number) => number;
18
49
  declare const isZoomOutAtLimit: (newZoom: number, oldZoom: number, zoomOutLimit: number) => boolean;
19
50
  declare const getDynamicZoom: (nodePositions: Point[] & Node[], minZoom: number, maxZoom: number, rect: HTMLCanvasElement, newZoom: number, currentZoom: number) => number;
20
- export { getFlexibleZoomLimit, isZoomOutAtLimit, getNewZoomWithinLimits, getExtremeLimits, getMaxDistance, getPositionBoundaries, getZoomLevel, createZoomTarget, getDynamicZoom };
51
+ export { getFlexibleZoomLimit, getZoomTargetForNodePositions, isZoomOutAtLimit, getNewZoomWithinLimits, getExtremeLimits, getMaxDistance, getPositionBoundaries, getZoomLevel, createZoomTarget, getDynamicZoom };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/base",
3
- "version": "0.3.5",
3
+ "version": "0.3.6-379b7fef",
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",
@@ -22,13 +22,13 @@
22
22
  "build": "yarn global:tsc && webpack",
23
23
  "watch": "concurrently 'tsc -w' 'webpack -w' -k -n 'tsc,webpack' -c 'cyan,magenta'",
24
24
  "test": "yarn global:jest",
25
- "eslint": "yarn global:eslint ./src/ --plugin only-warn",
25
+ "eslint": "yarn global:eslint ./src/",
26
26
  "coverage": "yarn test --coverage --silent",
27
27
  "prepack": "cp ../../LICENSE.txt ./",
28
28
  "postpack": "rm LICENSE.txt"
29
29
  },
30
30
  "dependencies": {
31
- "@neo4j-nvl/layout-workers": "0.3.5",
31
+ "@neo4j-nvl/layout-workers": "0.3.6-379b7fef",
32
32
  "@segment/analytics-next": "^1.70.0",
33
33
  "color-string": "^1.9.1",
34
34
  "d3-force": "^3.0.0",
@@ -50,8 +50,13 @@
50
50
  "@types/tinycolor2": "^1.4.6",
51
51
  "babel-loader": "^8.2.5",
52
52
  "copy-webpack-plugin": "^11.0.0",
53
+ "neo4j-driver": "^5.26.0",
53
54
  "typedoc": "^0.23.15",
54
55
  "webpack": "^5.75.0",
55
56
  "webpack-cli": "^5.0.0"
56
- }
57
+ },
58
+ "peerDependencies": {
59
+ "neo4j-driver": "*"
60
+ },
61
+ "stableVersion": "0.3.6"
57
62
  }