@neo4j-nvl/base 0.3.1-3ce43a8b
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/LICENSE.txt +49 -0
- package/README.md +43 -0
- package/dist/base.mjs +2 -0
- package/dist/base.mjs.LICENSE.txt +10 -0
- package/dist/types/index.d.ts +379 -0
- package/dist/types/layouts/animatedlayout/AnimatedLayout.d.ts +25 -0
- package/dist/types/layouts/animatedlayout/animationUtils.d.ts +9 -0
- package/dist/types/layouts/d3forcelayout/circularLayout.d.ts +5 -0
- package/dist/types/layouts/d3forcelayout/constants.d.ts +18 -0
- package/dist/types/layouts/d3forcelayout/d3ForceLayout.d.ts +29 -0
- package/dist/types/layouts/d3forcelayout/types.d.ts +9 -0
- package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +24 -0
- package/dist/types/layouts/forcedirectedlayout/cosebilkentlayout/CoseBilkentLayout.d.ts +32 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +167 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/glwrapper.d.ts +4 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +2 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +2 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-update-fragment.d.ts +2 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/sim-vertex.d.ts +2 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/workaround-fragment.d.ts +2 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +43 -0
- package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/solar-placer.d.ts +4 -0
- package/dist/types/layouts/freeLayout/FreeLayout.d.ts +26 -0
- package/dist/types/layouts/gridLayout/GridLayout.d.ts +16 -0
- package/dist/types/layouts/hierarchicallayout/HierarchicalLayout.d.ts +26 -0
- package/dist/types/layouts/hierarchicallayout/constants.d.ts +11 -0
- package/dist/types/modules/CallbackHelper.d.ts +38 -0
- package/dist/types/modules/ExternalCallbackHandler.d.ts +25 -0
- package/dist/types/modules/NvlController.d.ts +119 -0
- package/dist/types/modules/Shader.d.ts +18 -0
- package/dist/types/modules/ZoomTransitionHandler.d.ts +27 -0
- package/dist/types/modules/dataset.d.ts +37 -0
- package/dist/types/modules/logging.d.ts +5 -0
- package/dist/types/modules/performance.d.ts +93 -0
- package/dist/types/modules/state.d.ts +232 -0
- package/dist/types/renderers/canvasrenderer/Animation.d.ts +64 -0
- package/dist/types/renderers/canvasrenderer/AnimationHandler.d.ts +72 -0
- package/dist/types/renderers/canvasrenderer/CanvasRenderer.d.ts +92 -0
- package/dist/types/renderers/canvasrenderer/ImageCache.d.ts +11 -0
- package/dist/types/renderers/canvasrenderer/arrows/ArrowBundle.d.ts +79 -0
- package/dist/types/renderers/canvasrenderer/arrows/ArrowBundler.d.ts +33 -0
- package/dist/types/renderers/canvasrenderer/arrows/arrows.d.ts +50 -0
- package/dist/types/renderers/canvasrenderer/arrows/constants.d.ts +54 -0
- package/dist/types/renderers/canvasrenderer/nodes/nodes.d.ts +58 -0
- package/dist/types/renderers/canvasrenderer/types.d.ts +47 -0
- package/dist/types/renderers/canvasrenderer/util.d.ts +69 -0
- package/dist/types/renderers/canvasrenderer/vectorUtils.d.ts +21 -0
- package/dist/types/renderers/canvasrenderer/wordwrap.d.ts +42 -0
- package/dist/types/renderers/webglrenderer/Controller.d.ts +66 -0
- package/dist/types/renderers/webglrenderer/Renderer.d.ts +52 -0
- package/dist/types/renderers/webglrenderer/node-animation-fragment.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/node-animation-vertex.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/node-fragment-point.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/node-vertex-point.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/rel-fragment-line.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/rel-vertex-line.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/viewport-box-fragment.d.ts +2 -0
- package/dist/types/renderers/webglrenderer/viewport-box-vertex.d.ts +2 -0
- package/dist/types/types/graph-element.d.ts +88 -0
- package/dist/types/utils/canvasManagement.d.ts +15 -0
- package/dist/types/utils/colorMapperFunctions.d.ts +6 -0
- package/dist/types/utils/constants.d.ts +30 -0
- package/dist/types/utils/errors.d.ts +11 -0
- package/dist/types/utils/geometry.d.ts +122 -0
- package/dist/types/utils/graphObjectUtils.d.ts +9 -0
- package/dist/types/utils/hittest.d.ts +56 -0
- package/dist/types/utils/mouseUtils.d.ts +9 -0
- package/dist/types/utils/zoomFunctions.d.ts +20 -0
- package/package.json +63 -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,232 @@
|
|
|
1
|
+
import type { WaypointPath } from '../renderers/canvasrenderer/types';
|
|
2
|
+
import type { ExternalCallbacks } from './ExternalCallbackHandler';
|
|
3
|
+
import type { NodeDataSet, RelationshipDataSet } from './dataset';
|
|
4
|
+
type RingStyle = {
|
|
5
|
+
widthFactor: number;
|
|
6
|
+
color: string;
|
|
7
|
+
};
|
|
8
|
+
type ShadowStyle = {
|
|
9
|
+
width: number;
|
|
10
|
+
opacity: number;
|
|
11
|
+
color: string;
|
|
12
|
+
};
|
|
13
|
+
type BorderStyle = {
|
|
14
|
+
rings?: RingStyle[];
|
|
15
|
+
shadow?: ShadowStyle;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type NodeBorderStyles = {
|
|
21
|
+
selected?: BorderStyle;
|
|
22
|
+
default?: BorderStyle;
|
|
23
|
+
};
|
|
24
|
+
/** The default zoom level in a graph when not specified otherwise. */
|
|
25
|
+
export declare const DefaultZoomLevel = 0.75;
|
|
26
|
+
/**
|
|
27
|
+
* The options for the force directed layout
|
|
28
|
+
*/
|
|
29
|
+
export interface ForceDirectedOptions {
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
gravity?: number;
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
intelWorkaround?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
isCytoscapeEnabled: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
simulationStopVelocity?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The options for the hierarchical layout
|
|
49
|
+
*/
|
|
50
|
+
export interface HierarchicalOptions {
|
|
51
|
+
/** The direction in which the layout should be oriented */
|
|
52
|
+
direction?: 'up' | 'down' | 'left' | 'right';
|
|
53
|
+
/** The packing method to be used */
|
|
54
|
+
packing?: 'bin' | 'stack';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The name of the force directed layout
|
|
58
|
+
*/
|
|
59
|
+
export declare const ForceDirectedLayoutType = "forceDirected";
|
|
60
|
+
/**
|
|
61
|
+
* The name of the hierarchical layout
|
|
62
|
+
*/
|
|
63
|
+
export declare const HierarchicalLayoutType = "hierarchical";
|
|
64
|
+
/**
|
|
65
|
+
* The name of the grid layout
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export declare const GridLayoutType = "grid";
|
|
69
|
+
/**
|
|
70
|
+
* The name of the free layout
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export declare const FreeLayoutType = "free";
|
|
74
|
+
/**
|
|
75
|
+
* The name of the d3 force layout
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
export declare const d3ForceLayoutType = "d3Force";
|
|
79
|
+
export declare const WebGLRendererType = "webgl";
|
|
80
|
+
export declare const CanvasRendererType = "canvas";
|
|
81
|
+
/**
|
|
82
|
+
* The different types of layouts available
|
|
83
|
+
*/
|
|
84
|
+
export type Layout = typeof ForceDirectedLayoutType | typeof HierarchicalLayoutType | typeof GridLayoutType | typeof FreeLayoutType | typeof d3ForceLayoutType;
|
|
85
|
+
export type LayoutOptions = ForceDirectedOptions | HierarchicalOptions;
|
|
86
|
+
/**
|
|
87
|
+
* The different types of renderers available
|
|
88
|
+
*/
|
|
89
|
+
export type Renderer = typeof WebGLRendererType | typeof CanvasRendererType;
|
|
90
|
+
/** Configurations for a NVL instance */
|
|
91
|
+
export interface NvlOptions {
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
* Id for uniquely identifying the instance of Nvl
|
|
95
|
+
*/
|
|
96
|
+
instanceId?: string;
|
|
97
|
+
/** The graph layout algorithm to be used */
|
|
98
|
+
layout?: Layout;
|
|
99
|
+
/**
|
|
100
|
+
* The minimum zoom level allowed
|
|
101
|
+
* @default 0.075
|
|
102
|
+
*/
|
|
103
|
+
minZoom?: number;
|
|
104
|
+
/**
|
|
105
|
+
* The maximum zoom level allowed
|
|
106
|
+
* @default 10
|
|
107
|
+
*/
|
|
108
|
+
maxZoom?: number;
|
|
109
|
+
/**
|
|
110
|
+
* Whether or not to dynamically allow decreasing minimum zoom value
|
|
111
|
+
* if current graph does not fit on screen at minimum zoom.
|
|
112
|
+
* @note When set to true, zoom and fit operations will allow zooming out
|
|
113
|
+
* further than the minimum zoom value if the graph does not fit on screen.
|
|
114
|
+
* When set to false, zoom and fit operations will stop at the minimum zoom value,
|
|
115
|
+
* even if the full graph does not fit on screen at that zoom level.
|
|
116
|
+
* @default true
|
|
117
|
+
*/
|
|
118
|
+
allowDynamicMinZoom?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* @internal
|
|
121
|
+
* @deprecated
|
|
122
|
+
* The DOM element in which to render the graph visualization
|
|
123
|
+
*/
|
|
124
|
+
frame?: HTMLElement;
|
|
125
|
+
/** The DOM container in which to render the minimap */
|
|
126
|
+
minimapContainer?: HTMLElement;
|
|
127
|
+
/** Configuration for the current layout */
|
|
128
|
+
layoutOptions?: LayoutOptions;
|
|
129
|
+
/** X-coordinate for panning of the current viewport */
|
|
130
|
+
panX?: number;
|
|
131
|
+
/** Y-coordinate for panning of the current viewport */
|
|
132
|
+
panY?: number;
|
|
133
|
+
/** Zoom value of the current viewport */
|
|
134
|
+
initialZoom?: number;
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated use {@link renderer} instead
|
|
137
|
+
* Whether to user the Canvas or WebGL renderer
|
|
138
|
+
* @note will be ignored when {@link renderer} is set
|
|
139
|
+
*/
|
|
140
|
+
useWebGL?: boolean;
|
|
141
|
+
/** What renderer to use */
|
|
142
|
+
renderer?: Renderer;
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
* Whether or not to disable WebGL completely.
|
|
146
|
+
*/
|
|
147
|
+
disableWebGL?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* @internal
|
|
150
|
+
* Specify the log level.
|
|
151
|
+
*/
|
|
152
|
+
logging?: {
|
|
153
|
+
level?: any;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
relationshipThreshold?: number;
|
|
159
|
+
callbacks?: ExternalCallbacks;
|
|
160
|
+
/** The color to use for the default border of nodes */
|
|
161
|
+
nodeDefaultBorderColor?: string;
|
|
162
|
+
/** The color to use for the selected border of nodes */
|
|
163
|
+
nodeSelectedBorderColor?: string;
|
|
164
|
+
}
|
|
165
|
+
/** Options that influence how fit-to-zoom should behave */
|
|
166
|
+
export type ZoomOptions = {
|
|
167
|
+
/** If true, will zoom out to fit the specified nodes without changing the pan of the viewport. */
|
|
168
|
+
noPan?: boolean;
|
|
169
|
+
/** If true, will only zoom out if specified nodes won't fit into viewport but won't zoom in any further. */
|
|
170
|
+
outOnly?: boolean;
|
|
171
|
+
/** The minimum zoom value for the fit-to-zoom operation. */
|
|
172
|
+
minZoom?: number;
|
|
173
|
+
/** The maximum zoom value for the fit-to-zoom operation. */
|
|
174
|
+
maxZoom?: number;
|
|
175
|
+
};
|
|
176
|
+
export interface NvlState {
|
|
177
|
+
zoom: number;
|
|
178
|
+
zoomOptions: ZoomOptions;
|
|
179
|
+
minimapZoom: number;
|
|
180
|
+
defaultZoomLevel: number;
|
|
181
|
+
panX: number;
|
|
182
|
+
panY: number;
|
|
183
|
+
minimapPanX: number;
|
|
184
|
+
minimapPanY: number;
|
|
185
|
+
fitNodeIds: string[];
|
|
186
|
+
resetZoom: boolean;
|
|
187
|
+
forceWebGL: boolean;
|
|
188
|
+
webGLVisible: boolean;
|
|
189
|
+
renderer: Renderer;
|
|
190
|
+
disableWebGL: boolean;
|
|
191
|
+
fitMovement: number;
|
|
192
|
+
layout: Layout;
|
|
193
|
+
layoutOptions: LayoutOptions;
|
|
194
|
+
maxNodeRadius: number;
|
|
195
|
+
maxDistance: number;
|
|
196
|
+
minZoom: number;
|
|
197
|
+
maxZoom: number;
|
|
198
|
+
minMinimapZoom: number;
|
|
199
|
+
maxMinimapZoom: number;
|
|
200
|
+
nodes: NodeDataSet;
|
|
201
|
+
rels: RelationshipDataSet;
|
|
202
|
+
graphUpdates: number;
|
|
203
|
+
waypoints: {
|
|
204
|
+
data: Record<string, WaypointPath>;
|
|
205
|
+
counter: number;
|
|
206
|
+
};
|
|
207
|
+
setGraphUpdated: Function;
|
|
208
|
+
setRenderer: Function;
|
|
209
|
+
setWaypoints: Function;
|
|
210
|
+
setZoomPan: Function;
|
|
211
|
+
setZoom: (zoom: number, rect: HTMLElement) => void;
|
|
212
|
+
setPan: Function;
|
|
213
|
+
setLayout: Function;
|
|
214
|
+
setLayoutOptions: Function;
|
|
215
|
+
fitNodes: Function;
|
|
216
|
+
setZoomReset: Function;
|
|
217
|
+
clearFit: Function;
|
|
218
|
+
clearReset: Function;
|
|
219
|
+
updateZoomToFit: Function;
|
|
220
|
+
updateMinimapZoomToFit: Function;
|
|
221
|
+
autorun: Function;
|
|
222
|
+
reaction: Function;
|
|
223
|
+
nodeBorderStyles: NodeBorderStyles;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Create a new NVL state
|
|
227
|
+
*
|
|
228
|
+
* @param {NvlOptions} options - The options for the new state
|
|
229
|
+
* @returns {NvlState} - The state object
|
|
230
|
+
*/
|
|
231
|
+
export declare const createState: (options: NvlOptions) => NvlState;
|
|
232
|
+
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
|
+
}
|