@neo4j-nvl/base 0.3.1-016e1c20

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 (71) hide show
  1. package/LICENSE.txt +49 -0
  2. package/README.md +43 -0
  3. package/dist/base.mjs +2 -0
  4. package/dist/base.mjs.LICENSE.txt +10 -0
  5. package/dist/types/index.d.ts +379 -0
  6. package/dist/types/layouts/animatedlayout/AnimatedLayout.d.ts +25 -0
  7. package/dist/types/layouts/animatedlayout/animationUtils.d.ts +9 -0
  8. package/dist/types/layouts/d3forcelayout/circularLayout.d.ts +5 -0
  9. package/dist/types/layouts/d3forcelayout/constants.d.ts +18 -0
  10. package/dist/types/layouts/d3forcelayout/d3ForceLayout.d.ts +29 -0
  11. package/dist/types/layouts/d3forcelayout/types.d.ts +9 -0
  12. package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +22 -0
  13. package/dist/types/layouts/forcedirectedlayout/cosebilkentlayout/CoseBilkentLayout.d.ts +32 -0
  14. package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +167 -0
  15. package/dist/types/layouts/forcedirectedlayout/physlayout/glwrapper.d.ts +4 -0
  16. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +2 -0
  17. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +2 -0
  18. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-update-fragment.d.ts +2 -0
  19. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/sim-vertex.d.ts +2 -0
  20. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/workaround-fragment.d.ts +2 -0
  21. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +43 -0
  22. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/solar-placer.d.ts +2 -0
  23. package/dist/types/layouts/freeLayout/FreeLayout.d.ts +26 -0
  24. package/dist/types/layouts/gridLayout/GridLayout.d.ts +16 -0
  25. package/dist/types/layouts/hierarchicallayout/HierarchicalLayout.d.ts +26 -0
  26. package/dist/types/layouts/hierarchicallayout/constants.d.ts +11 -0
  27. package/dist/types/modules/CallbackHelper.d.ts +38 -0
  28. package/dist/types/modules/ExternalCallbackHandler.d.ts +26 -0
  29. package/dist/types/modules/NvlController.d.ts +114 -0
  30. package/dist/types/modules/Shader.d.ts +18 -0
  31. package/dist/types/modules/ZoomTransitionHandler.d.ts +27 -0
  32. package/dist/types/modules/dataset.d.ts +37 -0
  33. package/dist/types/modules/logging.d.ts +8 -0
  34. package/dist/types/modules/performance.d.ts +93 -0
  35. package/dist/types/modules/state.d.ts +242 -0
  36. package/dist/types/renderers/canvasrenderer/Animation.d.ts +64 -0
  37. package/dist/types/renderers/canvasrenderer/AnimationHandler.d.ts +72 -0
  38. package/dist/types/renderers/canvasrenderer/CanvasRenderer.d.ts +92 -0
  39. package/dist/types/renderers/canvasrenderer/ImageCache.d.ts +11 -0
  40. package/dist/types/renderers/canvasrenderer/arrows/ArrowBundle.d.ts +79 -0
  41. package/dist/types/renderers/canvasrenderer/arrows/ArrowBundler.d.ts +33 -0
  42. package/dist/types/renderers/canvasrenderer/arrows/arrows.d.ts +52 -0
  43. package/dist/types/renderers/canvasrenderer/arrows/constants.d.ts +41 -0
  44. package/dist/types/renderers/canvasrenderer/nodes/nodes.d.ts +58 -0
  45. package/dist/types/renderers/canvasrenderer/types.d.ts +47 -0
  46. package/dist/types/renderers/canvasrenderer/util.d.ts +69 -0
  47. package/dist/types/renderers/canvasrenderer/vectorUtils.d.ts +21 -0
  48. package/dist/types/renderers/canvasrenderer/wordwrap.d.ts +42 -0
  49. package/dist/types/renderers/webglrenderer/Controller.d.ts +66 -0
  50. package/dist/types/renderers/webglrenderer/Renderer.d.ts +51 -0
  51. package/dist/types/renderers/webglrenderer/node-animation-fragment.d.ts +2 -0
  52. package/dist/types/renderers/webglrenderer/node-animation-vertex.d.ts +2 -0
  53. package/dist/types/renderers/webglrenderer/node-fragment-point.d.ts +2 -0
  54. package/dist/types/renderers/webglrenderer/node-vertex-point.d.ts +2 -0
  55. package/dist/types/renderers/webglrenderer/rel-fragment-line.d.ts +2 -0
  56. package/dist/types/renderers/webglrenderer/rel-vertex-line.d.ts +2 -0
  57. package/dist/types/renderers/webglrenderer/viewport-box-fragment.d.ts +2 -0
  58. package/dist/types/renderers/webglrenderer/viewport-box-vertex.d.ts +2 -0
  59. package/dist/types/types/graph-element.d.ts +117 -0
  60. package/dist/types/types/nvl-window-functions.d.ts +15 -0
  61. package/dist/types/types/utils.d.ts +1 -0
  62. package/dist/types/utils/canvasManagement.d.ts +15 -0
  63. package/dist/types/utils/colorMapperFunctions.d.ts +6 -0
  64. package/dist/types/utils/constants.d.ts +30 -0
  65. package/dist/types/utils/errors.d.ts +11 -0
  66. package/dist/types/utils/geometry.d.ts +122 -0
  67. package/dist/types/utils/graphObjectUtils.d.ts +9 -0
  68. package/dist/types/utils/hittest.d.ts +56 -0
  69. package/dist/types/utils/mouseUtils.d.ts +9 -0
  70. package/dist/types/utils/zoomFunctions.d.ts +20 -0
  71. package/package.json +65 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * A class capable of measuring performance.
3
+ * Usage:
4
+ * When you want to measure a block of code, start by calling
5
+ * performanceTesterInstance.startTest() or
6
+ * performanceTesterInstance.startTest('Some readable name') if you
7
+ * want to control how it prints.
8
+ * After the block of code ends, call performanceTesterInstance.endTest()
9
+ */
10
+ export default class PerformanceTester {
11
+ disabled: boolean;
12
+ tree: PerformanceTree;
13
+ /**
14
+ * Starts a performance measurement. Every call to this method must be followed
15
+ * by a call to endTest(). Tests can be nested.
16
+ * @param {String} name String identifying this measurement. Only used for printing, so
17
+ * keep it human readable.
18
+ */
19
+ startTest(name: string): void;
20
+ /**
21
+ * Ends the last started test, giving it an end time.
22
+ */
23
+ endTest(): void;
24
+ /**
25
+ * Clears all performance measurements
26
+ */
27
+ reset(): void;
28
+ /**
29
+ * Prints all the performance measurements to console by calling
30
+ * print() on the performance tree.
31
+ */
32
+ print(): void;
33
+ }
34
+ /**
35
+ * A tree of PerformanceTreeNodes.
36
+ * @type {PerformanceTree}
37
+ */
38
+ declare class PerformanceTree {
39
+ root: any;
40
+ current: any;
41
+ /**
42
+ * Empties the tree.
43
+ */
44
+ clear(): void;
45
+ /**
46
+ * Adds a new node to the tree at the current open position, containing the
47
+ * data provided. It also sets the newly added node as the currently open one.
48
+ * @param {PerformanceData} data A PerformanceData object.
49
+ */
50
+ add(data: PerformanceData): void;
51
+ /**
52
+ * The tree always maintains a pointer to the currently open node. This
53
+ * method closes that node, closes the data object in contains, and opens
54
+ * the parent node.
55
+ */
56
+ close(): void;
57
+ /**
58
+ * Gets the data object of the currently open node.
59
+ * @return {PerformanceData} The data object of the currently open node.
60
+ */
61
+ getCurrentData(): PerformanceData;
62
+ /**
63
+ * Prints this entire tree to the console.
64
+ */
65
+ print(): void;
66
+ }
67
+ /**
68
+ * Performance measurement data.
69
+ * @type {PerformanceData}
70
+ */
71
+ declare class PerformanceData {
72
+ /**
73
+ * Instantiates a data measurement, giving it the start time when constructor is called.
74
+ * Remember that you also have to call close on this object to make it valid.
75
+ * @param {String} name String identifying this measurement. Only used for printing, so
76
+ * keep it human readable.
77
+ * @return {PerformanceData} The data object
78
+ */
79
+ constructor(name: string);
80
+ name: any;
81
+ startTime: any;
82
+ endTime: any;
83
+ /**
84
+ * Sets the endTime measurement on this data object.
85
+ */
86
+ close(): void;
87
+ /**
88
+ * Gets the time spent on this measurement
89
+ * @return {Number} Time spent in ms
90
+ */
91
+ _timeSpent(): number;
92
+ }
93
+ export {};
@@ -0,0 +1,242 @@
1
+ import type { LogLevelDesc } from 'loglevel';
2
+ import type { WaypointPath } from '../renderers/canvasrenderer/types';
3
+ import type { ExternalCallbacks } from './ExternalCallbackHandler';
4
+ import type { NodeDataSet, RelationshipDataSet } from './dataset';
5
+ type RingStyle = {
6
+ width?: number;
7
+ widthFactor?: number;
8
+ color: string;
9
+ };
10
+ export type ShadowStyle = {
11
+ width: number;
12
+ opacity: number;
13
+ color: string;
14
+ };
15
+ export type BorderStyle = {
16
+ rings?: RingStyle[];
17
+ shadow?: ShadowStyle;
18
+ };
19
+ /**
20
+ * @internal
21
+ */
22
+ export type BorderStyles = {
23
+ selected: BorderStyle;
24
+ default: BorderStyle;
25
+ };
26
+ export declare const RelationshipBorderStyles: BorderStyles;
27
+ /** The default zoom level in a graph when not specified otherwise. */
28
+ export declare const DefaultZoomLevel = 0.75;
29
+ /**
30
+ * The options for the force directed layout
31
+ */
32
+ export interface ForceDirectedOptions {
33
+ /**
34
+ * @internal
35
+ */
36
+ gravity?: number;
37
+ /**
38
+ * @internal
39
+ */
40
+ intelWorkaround?: boolean;
41
+ /**
42
+ * @internal
43
+ */
44
+ isCytoscapeEnabled: boolean;
45
+ /**
46
+ * @internal
47
+ */
48
+ simulationStopVelocity?: number;
49
+ }
50
+ /**
51
+ * The options for the hierarchical layout
52
+ */
53
+ export interface HierarchicalOptions {
54
+ /** The direction in which the layout should be oriented */
55
+ direction?: 'up' | 'down' | 'left' | 'right';
56
+ /** The packing method to be used */
57
+ packing?: 'bin' | 'stack';
58
+ }
59
+ /**
60
+ * The name of the force directed layout
61
+ */
62
+ export declare const ForceDirectedLayoutType = "forceDirected";
63
+ /**
64
+ * The name of the hierarchical layout
65
+ */
66
+ export declare const HierarchicalLayoutType = "hierarchical";
67
+ /**
68
+ * The name of the grid layout
69
+ * @internal
70
+ */
71
+ export declare const GridLayoutType = "grid";
72
+ /**
73
+ * The name of the free layout
74
+ * @internal
75
+ */
76
+ export declare const FreeLayoutType = "free";
77
+ /**
78
+ * The name of the d3 force layout
79
+ * @internal
80
+ */
81
+ export declare const d3ForceLayoutType = "d3Force";
82
+ export declare const WebGLRendererType = "webgl";
83
+ export declare const CanvasRendererType = "canvas";
84
+ /**
85
+ * The different types of layouts available
86
+ */
87
+ export type Layout = typeof ForceDirectedLayoutType | typeof HierarchicalLayoutType | typeof GridLayoutType | typeof FreeLayoutType | typeof d3ForceLayoutType;
88
+ export type LayoutOptions = ForceDirectedOptions & HierarchicalOptions;
89
+ /**
90
+ * The different types of renderers available
91
+ */
92
+ export type Renderer = typeof WebGLRendererType | typeof CanvasRendererType;
93
+ /** Configurations for a NVL instance */
94
+ export interface NvlOptions {
95
+ /**
96
+ * @internal
97
+ * Id for uniquely identifying the instance of Nvl
98
+ */
99
+ instanceId?: string;
100
+ /** The graph layout algorithm to be used */
101
+ layout?: Layout;
102
+ /**
103
+ * The minimum zoom level allowed
104
+ * @default 0.075
105
+ */
106
+ minZoom?: number;
107
+ /**
108
+ * The maximum zoom level allowed
109
+ * @default 10
110
+ */
111
+ maxZoom?: number;
112
+ /**
113
+ * Whether or not to dynamically allow decreasing minimum zoom value
114
+ * if current graph does not fit on screen at minimum zoom.
115
+ * @note When set to true, zoom and fit operations will allow zooming out
116
+ * further than the minimum zoom value if the graph does not fit on screen.
117
+ * When set to false, zoom and fit operations will stop at the minimum zoom value,
118
+ * even if the full graph does not fit on screen at that zoom level.
119
+ * @default true
120
+ */
121
+ allowDynamicMinZoom?: boolean;
122
+ /**
123
+ * @internal
124
+ * @deprecated
125
+ * The DOM element in which to render the graph visualization
126
+ */
127
+ frame?: HTMLElement;
128
+ /** The DOM container in which to render the minimap */
129
+ minimapContainer?: HTMLElement;
130
+ /** Configuration for the current layout */
131
+ layoutOptions?: LayoutOptions;
132
+ /** X-coordinate for panning of the current viewport */
133
+ panX?: number;
134
+ /** Y-coordinate for panning of the current viewport */
135
+ panY?: number;
136
+ /** Zoom value of the current viewport */
137
+ initialZoom?: number;
138
+ /**
139
+ * @deprecated use {@link renderer} instead
140
+ * Whether to user the Canvas or WebGL renderer
141
+ * @note will be ignored when {@link renderer} is set
142
+ */
143
+ useWebGL?: boolean;
144
+ /** What renderer to use */
145
+ renderer?: Renderer;
146
+ /**
147
+ * @internal
148
+ * Whether or not to disable WebGL completely.
149
+ */
150
+ disableWebGL?: boolean;
151
+ /**
152
+ * @internal
153
+ * Specify the log level.
154
+ */
155
+ logging?: {
156
+ level: LogLevelDesc;
157
+ };
158
+ /**
159
+ * @internal
160
+ */
161
+ relationshipThreshold?: number;
162
+ callbacks?: ExternalCallbacks;
163
+ /** The color to use for the default border of nodes */
164
+ nodeDefaultBorderColor?: string;
165
+ /** The color to use for the selected border of nodes */
166
+ selectedBorderColor?: string;
167
+ /**
168
+ * @internal
169
+ * @experimental
170
+ * Defines a time limit for how long layout iterations may run
171
+ */
172
+ layoutTimeLimit?: number;
173
+ }
174
+ /** Options that influence how fit-to-zoom should behave */
175
+ export type ZoomOptions = {
176
+ /** If true, will zoom out to fit the specified nodes without changing the pan of the viewport. */
177
+ noPan?: boolean;
178
+ /** If true, will only zoom out if specified nodes won't fit into viewport but won't zoom in any further. */
179
+ outOnly?: boolean;
180
+ /** The minimum zoom value for the fit-to-zoom operation. */
181
+ minZoom?: number;
182
+ /** The maximum zoom value for the fit-to-zoom operation. */
183
+ maxZoom?: number;
184
+ };
185
+ export interface NvlState {
186
+ zoom: number;
187
+ zoomOptions: ZoomOptions;
188
+ minimapZoom: number;
189
+ defaultZoomLevel: number;
190
+ panX: number;
191
+ panY: number;
192
+ minimapPanX: number;
193
+ minimapPanY: number;
194
+ fitNodeIds: string[];
195
+ resetZoom: boolean;
196
+ forceWebGL: boolean;
197
+ webGLVisible: boolean;
198
+ renderer: Renderer;
199
+ disableWebGL: boolean;
200
+ fitMovement: number;
201
+ layout: Layout;
202
+ layoutOptions: LayoutOptions;
203
+ maxNodeRadius: number;
204
+ maxDistance: number;
205
+ minZoom: number;
206
+ maxZoom: number;
207
+ minMinimapZoom: number;
208
+ maxMinimapZoom: number;
209
+ nodes: NodeDataSet;
210
+ rels: RelationshipDataSet;
211
+ graphUpdates: number;
212
+ waypoints: {
213
+ data: Record<string, WaypointPath>;
214
+ counter: number;
215
+ };
216
+ setGraphUpdated: Function;
217
+ setRenderer: Function;
218
+ setWaypoints: Function;
219
+ setZoomPan: Function;
220
+ setZoom: (zoom: number, rect: HTMLElement) => void;
221
+ setPan: Function;
222
+ setLayout: Function;
223
+ setLayoutOptions: Function;
224
+ fitNodes: Function;
225
+ setZoomReset: Function;
226
+ clearFit: Function;
227
+ clearReset: Function;
228
+ updateZoomToFit: Function;
229
+ updateMinimapZoomToFit: Function;
230
+ autorun: Function;
231
+ reaction: Function;
232
+ nodeBorderStyles: BorderStyles;
233
+ relationshipBorderStyles: BorderStyles;
234
+ }
235
+ /**
236
+ * Create a new NVL state
237
+ *
238
+ * @param {NvlOptions} options - The options for the new state
239
+ * @returns {NvlState} - The state object
240
+ */
241
+ export declare const createState: (options: NvlOptions) => NvlState;
242
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Animation class to animate a value from a start value to an end value
3
+ */
4
+ export declare class Animation {
5
+ /** The id of the element to animate */
6
+ readonly elementId: string;
7
+ /** The current value of the animation */
8
+ currentValue: number;
9
+ /** The start value of the animation */
10
+ private startValue;
11
+ /** The current time of the animation */
12
+ private currentTime;
13
+ /** The duration of the animation */
14
+ private duration;
15
+ /** The status of the animation */
16
+ private status;
17
+ /** The end value of the animation */
18
+ private endValue;
19
+ /** The start time of the animation */
20
+ private startTime;
21
+ /** The end time of the animation */
22
+ private endTime;
23
+ /** Flag to indicate if there is a next animation */
24
+ private hasNextAnimation;
25
+ /**
26
+ * Constructor
27
+ * @param {string} elementId The id of the element to animate.
28
+ * @param {number} startValue The start value of the animation.
29
+ */
30
+ constructor(elementId: string, startValue: number);
31
+ /**
32
+ * Sets the duration of the animation
33
+ * @param {number} duration The duration of the animation.
34
+ * @returns {void}
35
+ * @public
36
+ */
37
+ setDuration(duration: number): void;
38
+ /**
39
+ * Returns the status of the animation
40
+ * @returns {number} The status of the animation.
41
+ * @public
42
+ */
43
+ getStatus(): number;
44
+ /**
45
+ * Advances the animation to the next frame
46
+ * @returns {boolean} True if there is a next animation, false otherwise.
47
+ * @public
48
+ */
49
+ advance(): boolean;
50
+ /**
51
+ * Sets the end value of the animation
52
+ * @param {number} targetValue The end value of the animation.
53
+ * @returns {void}
54
+ * @public
55
+ */
56
+ setEndValue(targetValue: number): void;
57
+ /**
58
+ * Sets the end time of the animation
59
+ * @param {number} newEndTime The end time of the animation.
60
+ * @returns {void}
61
+ * @private
62
+ */
63
+ private setEndTime;
64
+ }
@@ -0,0 +1,72 @@
1
+ import { Animation } from './Animation';
2
+ /**
3
+ * A small animation running engine that lets elements do any transitions and
4
+ * ask the rendered to redraw as long as needed.
5
+ * The object is owned by the canvas renderer
6
+ */
7
+ export default class AnimationHandler {
8
+ /** A map of all animations */
9
+ private readonly animations;
10
+ /** A map of all durations */
11
+ private readonly durations;
12
+ /** The default duration */
13
+ private readonly defaultDuration;
14
+ /** Flag to indicate if a rerun is needed */
15
+ private hasNextAnimation;
16
+ /** Flag to indicate if animations should be ignored */
17
+ private ignoreAnimationsFlag;
18
+ constructor();
19
+ /**
20
+ * Main function run once per frame to advance all animations
21
+ * @returns {boolean} true if any animation is still running
22
+ */
23
+ advance(): boolean;
24
+ /**
25
+ * Sets a flag if animations should be ignored.
26
+ * If set to true all animations always return their end value.
27
+ * @param {boolean} shouldIgnore
28
+ */
29
+ ignoreAnimations(shouldIgnore: boolean): void;
30
+ /**
31
+ * Sets the duration for all animations
32
+ * @param {Object} options - An object containing animation durations for fade and size
33
+ */
34
+ setOptions(options: {
35
+ fadeDuration: number;
36
+ sizeDuration: number;
37
+ }): void;
38
+ /**
39
+ * Returns whether any animation is running
40
+ * @returns {boolean}
41
+ */
42
+ needsToRun(): boolean;
43
+ /**
44
+ * Returns the current value of an animation
45
+ * @param {string} elementId - The id of the element the animation is running on
46
+ * @param {string} name - The name of the animation
47
+ * @returns {number} The current value of the animation
48
+ */
49
+ getValueForAnimationName(elementId: string, name: string, target: number, type?: number): number;
50
+ private createAnimation;
51
+ getById(id: string): Record<string, Animation> | undefined;
52
+ /**
53
+ * Creates a new size animation for the given element and name.
54
+ * If an animation already exists for the given element and name, it will be returned.
55
+ * If not, a new animation will be created.
56
+ * @param {number} currentValue - The current value of the animation
57
+ * @param {string} elementId - The id of the element to animate
58
+ * @param {string} name - The name of the animation
59
+ * @returns {Animation} The animation
60
+ */
61
+ private createFadeAnimation;
62
+ /**
63
+ * Creates a new fade animation for the given element and name.
64
+ * If an animation already exists for the given element and name, it will be returned.
65
+ * If not, a new animation will be created.
66
+ * @param {number} currentValue - The current value of the animation
67
+ * @param {string} elementId - The id of the element to animate
68
+ * @param {string} name - The name of the animation
69
+ * @returns {Animation} The animation
70
+ */
71
+ private createSizeAnimation;
72
+ }
@@ -0,0 +1,92 @@
1
+ import type { NvlState } from '../../modules/state';
2
+ import type { Node } from '../../types/graph-element';
3
+ import type { Point } from '../../utils/geometry';
4
+ import type { HitTargetNode, HitTargetRelationship } from '../../utils/hittest';
5
+ import ArrowBundler from './arrows/ArrowBundler';
6
+ export default class CanvasRenderer {
7
+ arrowBundler: ArrowBundler;
8
+ private activeNodes;
9
+ private canvas;
10
+ private context;
11
+ private state;
12
+ private stateDisposers;
13
+ private relationshipThreshold;
14
+ private animationHandler;
15
+ private imageCache;
16
+ private needsRun;
17
+ private nodeVersion;
18
+ private relVersion;
19
+ private waypointVersion;
20
+ /**
21
+ * Creates a new CanvasRenderer.
22
+ * @param canvas {HTMLCanvasElement} - The canvas to render on.
23
+ * @param context {CanvasRenderingContext2D} - The canvas context.
24
+ * @param state {NvlState} - The state.
25
+ * @param options {{ relationshipThreshold: number }} - The visualization options.
26
+ */
27
+ constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D | null, state: NvlState, { relationshipThreshold }?: {
28
+ relationshipThreshold?: number;
29
+ });
30
+ /**
31
+ * Checks if the renderer needs to run.
32
+ * @returns {boolean} - Whether the renderer needs to run
33
+ */
34
+ needsToRun(): boolean;
35
+ /**
36
+ * Processes the updates in nodes and relationships.
37
+ */
38
+ processUpdates(): void;
39
+ /**
40
+ * Draws the nodes and relationships to their positions on the canvas.
41
+ * @param positionArray {Node[]} - The array of nodes to draw
42
+ * @param options {any} - The options for the render
43
+ */
44
+ render(positionArray: Node[], options?: {
45
+ canvas?: HTMLCanvasElement;
46
+ context?: CanvasRenderingContext2D;
47
+ backgroundColor?: string;
48
+ ignoreAnimations?: boolean;
49
+ showCaptions?: boolean;
50
+ }): void;
51
+ private getRelationshipsToRender;
52
+ private getNodesToRender;
53
+ private renderNodes;
54
+ private renderRelationships;
55
+ /**
56
+ * Returns the nodes at the pointer position
57
+ * @param {Point} pointer - the position of the pointer
58
+ * @returns {HitTargetNode[]} - the nodes at the pointer position
59
+ * @todo Sort nodes by distance descending
60
+ */
61
+ getNodesAt(pointer: Point, hitNodeMarginWidth?: number): HitTargetNode[];
62
+ /**
63
+ * Returns the relationships at the pointer position
64
+ * @param {Point} pointer - the position of the pointer
65
+ * @returns {HitTargetRelationship[]} - the relationships at the pointer position
66
+ * @todo: sort relationships by distance descending
67
+ */
68
+ getRelsAt(pointer: Point): HitTargetRelationship[];
69
+ destroy(): void;
70
+ /**
71
+ * Checks if the bounding box is outside of the screen.
72
+ * @param boundingBox - The bounding box to check
73
+ * @param clientWidth - The client width of the canvas
74
+ * @param clientHeight - The client height of the canvas
75
+ * @returns Whether the bounding box is off screen
76
+ * @note This check doesn't catch all items that are off screen but its simple and removes many of them
77
+ */
78
+ private isBoundingBoxOffScreen;
79
+ /**
80
+ * Handles the channel's additions, removals and updates and adds or removes the id from the active nodes.
81
+ * @param channel {Channel<Node>} - The channel to process
82
+ * @param fullData {DataSet<Node>} - The full data
83
+ * @param processUpdates {boolean} - Whether to process channel updates as well
84
+ */
85
+ private handleChannelUpdate;
86
+ /**
87
+ * Handles zoom and pan on the canvas.
88
+ * @param context {CanvasRenderingContext2D} - The canvas context
89
+ * @param canvas {HTMLCanvasElement} - The canvas
90
+ */
91
+ private zoomAndPan;
92
+ }
@@ -0,0 +1,11 @@
1
+ import type { Cache, CacheInfo, CacheItem } from './types';
2
+ declare class ImageCache {
3
+ cache: Cache;
4
+ constructor();
5
+ getOrCreateEntry(src: string): CacheItem;
6
+ invertCanvas(ctx: CanvasRenderingContext2D): void;
7
+ loadImage(src: string): CacheInfo;
8
+ drawIfNeeded(info: CacheInfo, inverted: boolean): void;
9
+ getImage(src: string, inverted?: boolean): HTMLCanvasElement;
10
+ }
11
+ export default ImageCache;
@@ -0,0 +1,79 @@
1
+ import type { Relationship } from '../../../types/graph-element';
2
+ import type { Point } from '../../../utils/geometry';
3
+ import type { WaypointPath } from '../types';
4
+ export interface LabelGeometry {
5
+ position: Point;
6
+ rotation: number;
7
+ width: number;
8
+ height: number;
9
+ }
10
+ /**
11
+ * Class representing a bundle of arrows
12
+ */
13
+ export default class ArrowBundle {
14
+ key: string;
15
+ rels: {
16
+ rel: Relationship;
17
+ }[];
18
+ waypointPath: WaypointPath;
19
+ readonly selfReferring: boolean;
20
+ fromId: string;
21
+ toId: string;
22
+ angles: number[];
23
+ labelInfo: Record<string, LabelGeometry>;
24
+ /**
25
+ * @param {string} key - The key of the arrow bundle
26
+ * @param {string} fromId - The source node of the arrow bundle
27
+ * @param {string} toId - The target node of the arrow bundle
28
+ */
29
+ constructor(key: string, fromId: string, toId: string);
30
+ /**
31
+ * Insert a new arrow to the bundle
32
+ * @param {Relationship} rel - The relationship to insert
33
+ */
34
+ insert(rel: Relationship): void;
35
+ setLabelInfo(relId: string, labelInfo: LabelGeometry): void;
36
+ /**
37
+ * Remove an arrow from the bundle
38
+ * @param {Relationship} rel - The arrow to remove
39
+ */
40
+ remove({ id }: Relationship): void;
41
+ /**
42
+ * Get the size of the arrow bundle
43
+ * @returns {number} The size of the arrow bundle
44
+ */
45
+ size(): number;
46
+ /**
47
+ * Get the maximum font size of the arrows in the bundle
48
+ * @returns {number} The maximum font size of the arrows in the bundle
49
+ */
50
+ maxFontSize(): number;
51
+ /**
52
+ * Check if relationship is in opposite direction to the bundle.
53
+ * @param {Relationship} rel - The relationship to check
54
+ * @returns {boolean} True if the relationship is in opposite direction to the bundle
55
+ */
56
+ relIsOppositeDirection({ from, to }: Relationship): boolean;
57
+ /**
58
+ * Get the index of a given arrow in the bundle
59
+ * @param {Relationship} rel - The arrow to look for
60
+ * @returns {number} The index of the arrow in the bundle, or -1 if not found
61
+ */
62
+ indexOf({ id }: Relationship): number;
63
+ /**
64
+ * Get the arrow at a given index in the bundle
65
+ * @param {number} index - The index of the arrow to get
66
+ * @returns {Relationship | null} The arrow at the given index
67
+ */
68
+ getRel(index: number): Relationship | null;
69
+ /**
70
+ * Set the waypoints for the arrow bundle
71
+ * @param {WaypointPath} waypoints - The waypoints for the arrow bundle
72
+ */
73
+ setWaypoints(waypoints: WaypointPath): void;
74
+ /**
75
+ * Set the angles for the arrow bundle
76
+ * @param {number[]} angles - The angles for the arrow bundle
77
+ */
78
+ setAngles(angles: number[]): void;
79
+ }
@@ -0,0 +1,33 @@
1
+ import type { Node, Relationship } from '../../../types/graph-element';
2
+ import type { WaypointPath } from '../types';
3
+ import ArrowBundle from './ArrowBundle';
4
+ export default class ArrowBundler {
5
+ bundles: Record<string, ArrowBundle>;
6
+ nodeToBundles: Record<string, ArrowBundle[]>;
7
+ constructor(rels: Relationship[], waypoints: Record<string, WaypointPath>);
8
+ /**
9
+ * Get the arrow bundle for a given relation
10
+ * @param {Relationship} rel - The relationship
11
+ * @returns {ArrowBundle} The arrow bundle
12
+ */
13
+ getBundle(rel: Relationship): ArrowBundle;
14
+ /**
15
+ * Update the data
16
+ * @param {Record<string, Relationship>} addedRels - The added relations
17
+ * @param {Record<string, Relationship>} removedRels - The removed relations
18
+ * @param {Record<string, WaypointPath>} waypoints - The waypoints
19
+ */
20
+ updateData(addedRels: Record<string, Relationship>, removedRels: Record<string, Relationship>, waypoints: Record<string, WaypointPath>): void;
21
+ /**
22
+ * Updates the positions of the arrow bundles based on the provided `positionMap`.
23
+ * @param positionMap A map of node IDs to positions.
24
+ */
25
+ updatePositions(positionMap: Record<string, Node>): void;
26
+ /**
27
+ * Get a unique ID for a pair of IDs
28
+ * @param {string} id1 - The first ID
29
+ * @param {string} id2 - The second ID
30
+ * @returns {string} A unique ID for the pair of IDs
31
+ */
32
+ private generatePairId;
33
+ }