@neo4j-nvl/base 1.0.0 → 1.1.0-01fc2de1
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/CHANGELOG.md +25 -0
- package/dist/base.mjs +1 -1
- package/dist/types/index.d.ts +44 -11
- package/dist/types/layouts/circularLayout/CircularLayout.d.ts +18 -0
- package/dist/types/layouts/d3forcelayout/d3ForceLayout.d.ts +20 -20
- package/dist/types/layouts/d3forcelayout/types.d.ts +5 -6
- package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +1 -1
- package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +8 -4
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +1 -1
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +1 -1
- package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +17 -39
- package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/types.d.ts +49 -0
- package/dist/types/layouts/gridLayout/GridLayout.d.ts +25 -9
- package/dist/types/modules/NvlController.d.ts +20 -4
- package/dist/types/modules/state/types.d.ts +32 -15
- package/dist/types/modules/state/utils.d.ts +2 -2
- package/dist/types/renderers/domrenderer/BaseRenderer.d.ts +75 -0
- package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/CanvasRenderer.d.ts +33 -40
- package/dist/types/renderers/domrenderer/canvasrenderer/arrowDrawing.d.ts +168 -0
- package/dist/types/renderers/domrenderer/canvasrenderer/nodeDrawing.d.ts +109 -0
- package/dist/types/renderers/domrenderer/shared/ImageCache.d.ts +16 -0
- package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/ArrowBundle.d.ts +20 -4
- package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/ArrowBundler.d.ts +11 -1
- package/dist/types/renderers/domrenderer/shared/arrows/ArrowBundler.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/shared/arrows/arrows.d.ts +175 -0
- package/dist/types/renderers/domrenderer/shared/arrows/arrows.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/shared/nodes/nodes.d.ts +103 -0
- package/dist/types/renderers/domrenderer/shared/nodes/nodes.test.d.ts +1 -0
- package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/types.d.ts +2 -2
- package/dist/types/renderers/domrenderer/shared/util.d.ts +16 -0
- package/dist/types/renderers/domrenderer/shared/util.test.d.ts +1 -0
- package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/vectorUtils.d.ts +1 -1
- package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/wordwrap.d.ts +10 -0
- package/dist/types/renderers/domrenderer/shared/wordwrap.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/svgrenderer/SvgRenderer.d.ts +20 -0
- package/dist/types/renderers/domrenderer/svgrenderer/SvgRenderer.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/svgrenderer/arrowDrawing.d.ts +59 -0
- package/dist/types/renderers/domrenderer/svgrenderer/arrowDrawing.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/svgrenderer/nodeDrawing.d.ts +16 -0
- package/dist/types/renderers/domrenderer/svgrenderer/nodeDrawing.test.d.ts +1 -0
- package/dist/types/renderers/domrenderer/svgrenderer/svgUtils.d.ts +78 -0
- package/dist/types/renderers/domrenderer/svgrenderer/svgUtils.test.d.ts +1 -0
- package/dist/types/renderers/webglrenderer/Renderer.d.ts +5 -1
- package/dist/types/renderers/webglrenderer/Renderer.test.d.ts +1 -0
- package/dist/types/types/graph-element.d.ts +1 -1
- package/dist/types/utils/canvasManagement.d.ts +16 -1
- package/dist/types/utils/circularUtils.d.ts +3 -0
- package/dist/types/utils/circularUtils.test.d.ts +1 -0
- package/dist/types/utils/constants.d.ts +7 -3
- package/dist/types/utils/geometry.d.ts +2 -1
- package/dist/types/utils/graphObjectUtils.d.ts +2 -2
- package/dist/types/utils/jsDriverResultTransformer.d.ts +1 -1
- package/dist/types/utils/segmentAnalytics.d.ts +2 -2
- package/package.json +25 -24
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment-verlet.d.ts +0 -2
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment-verlet.d.ts +0 -2
- package/dist/types/modules/performance.d.ts +0 -93
- package/dist/types/renderers/canvasrenderer/ImageCache.d.ts +0 -11
- package/dist/types/renderers/canvasrenderer/arrows/arrows.d.ts +0 -55
- package/dist/types/renderers/canvasrenderer/nodes/nodes.d.ts +0 -59
- package/dist/types/renderers/canvasrenderer/util.d.ts +0 -68
- /package/dist/types/{renderers/canvasrenderer/Animation.test.d.ts → layouts/d3forcelayout/circularLayout.test.d.ts} +0 -0
- /package/dist/types/{renderers/canvasrenderer/CanvasRenderer.test.d.ts → layouts/d3forcelayout/d3ForceLayout.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/ImageCache.test.d.ts → domrenderer/BaseRenderer.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/Animation.d.ts +0 -0
- /package/dist/types/renderers/{canvasrenderer/arrows/ArrowBundle.test.d.ts → domrenderer/canvasrenderer/Animation.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/AnimationHandler.d.ts +0 -0
- /package/dist/types/renderers/{canvasrenderer/arrows/ArrowBundler.test.d.ts → domrenderer/canvasrenderer/CanvasRenderer.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/arrows/arrows.test.d.ts → domrenderer/canvasrenderer/arrowDrawing.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/nodes/nodes.test.d.ts → domrenderer/canvasrenderer/nodeDrawing.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/util.test.d.ts → domrenderer/shared/ImageCache.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/wordwrap.test.d.ts → domrenderer/shared/arrows/ArrowBundle.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/constants.d.ts +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Channel, DataSet } from '../../modules/dataset';
|
|
2
|
+
import type { NvlState } from '../../modules/state/types';
|
|
3
|
+
import type { Node } from '../../types/graph-element';
|
|
4
|
+
import ImageCache from './shared/ImageCache';
|
|
5
|
+
import ArrowBundler from './shared/arrows/ArrowBundler';
|
|
6
|
+
import type { RelationshipToRender } from './shared/types';
|
|
7
|
+
export type RendererOptions = {
|
|
8
|
+
relationshipThreshold?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Base class for renderers (Canvas and SVG) that provides common functionality
|
|
12
|
+
*/
|
|
13
|
+
export default abstract class BaseRenderer {
|
|
14
|
+
arrowBundler: ArrowBundler;
|
|
15
|
+
protected state: NvlState;
|
|
16
|
+
protected relationshipThreshold: number;
|
|
17
|
+
protected stateDisposers: NvlState['reaction'][];
|
|
18
|
+
protected needsRun: boolean;
|
|
19
|
+
protected imageCache: ImageCache;
|
|
20
|
+
protected nodeVersion: number;
|
|
21
|
+
protected relVersion: number;
|
|
22
|
+
protected waypointVersion: number;
|
|
23
|
+
protected channelId: string;
|
|
24
|
+
protected activeNodes: Set<string>;
|
|
25
|
+
constructor(state: NvlState, channelId: string, options?: RendererOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Gets relationships to render, sorted by their rendering order
|
|
28
|
+
* @param showCaptions - Whether to show relationship captions
|
|
29
|
+
* @param zoom - Current zoom level (optional, used for threshold checking)
|
|
30
|
+
* @param clientWidth - Width of the rendering area
|
|
31
|
+
* @param clientHeight - Height of the rendering area
|
|
32
|
+
* @returns Array of relationships to render, sorted (disabled, normal, selected)
|
|
33
|
+
*/
|
|
34
|
+
protected getRelationshipsToRender(showCaptions?: boolean, zoom?: number, clientWidth?: number, clientHeight?: number): RelationshipToRender[];
|
|
35
|
+
/**
|
|
36
|
+
* Gets nodes to render, sorted by their rendering order
|
|
37
|
+
* @param positionArray - Array of nodes with positions
|
|
38
|
+
* @param clientWidth - Width of the rendering area
|
|
39
|
+
* @param clientHeight - Height of the rendering area
|
|
40
|
+
* @returns Array of nodes to render, sorted (disabled, normal, selected)
|
|
41
|
+
*/
|
|
42
|
+
protected getNodesToRender(positionArray: Node[], clientWidth?: number, clientHeight?: number): Node[];
|
|
43
|
+
/**
|
|
44
|
+
* Processes updates in nodes and relationships.
|
|
45
|
+
*/
|
|
46
|
+
processUpdates(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Processes node channel updates to track activated nodes.
|
|
49
|
+
* Adds or removes node IDs from the activeNodes set based on their activated state.
|
|
50
|
+
* @param channel - The node channel with adds, removes, and updates
|
|
51
|
+
* @param fullData - The full node dataset
|
|
52
|
+
*/
|
|
53
|
+
protected processNodeChannelUpdates(channel: Channel<Node>, fullData: DataSet<Node>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a bounding box is off screen
|
|
56
|
+
* @param boundingBox - The bounding box to check
|
|
57
|
+
* @param clientWidth - Width of the rendering area
|
|
58
|
+
* @param clientHeight - Height of the rendering area
|
|
59
|
+
* @returns Whether the bounding box is off screen
|
|
60
|
+
*/
|
|
61
|
+
protected isBoundingBoxOffScreen(boundingBox: DOMRect, clientWidth: number, clientHeight: number): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the renderer needs to run.
|
|
64
|
+
* @returns Whether the renderer needs to run.
|
|
65
|
+
*/
|
|
66
|
+
needsToRun(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a promise that resolves when all images in the cache have finished loading.
|
|
69
|
+
*/
|
|
70
|
+
waitForImages(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Cleans up the renderer by disposing state reactions and removing channels.
|
|
73
|
+
*/
|
|
74
|
+
destroy(): void;
|
|
75
|
+
}
|
package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/CanvasRenderer.d.ts
RENAMED
|
@@ -1,42 +1,54 @@
|
|
|
1
|
-
import type { NvlState } from '
|
|
2
|
-
import type { Node } from '
|
|
3
|
-
import type { Point } from '
|
|
4
|
-
import type { HitTargetNode, HitTargetRelationship } from '
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private activeNodes;
|
|
1
|
+
import type { NvlState } from '../../../modules/state/types';
|
|
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 type { RendererOptions } from '../BaseRenderer';
|
|
6
|
+
import BaseRenderer from '../BaseRenderer';
|
|
7
|
+
export default class CanvasRenderer extends BaseRenderer {
|
|
9
8
|
private canvas;
|
|
10
9
|
private context;
|
|
11
|
-
private state;
|
|
12
|
-
private stateDisposers;
|
|
13
|
-
private relationshipThreshold;
|
|
14
10
|
private animationHandler;
|
|
15
|
-
private imageCache;
|
|
16
|
-
private needsRun;
|
|
17
|
-
private nodeVersion;
|
|
18
|
-
private relVersion;
|
|
19
|
-
private waypointVersion;
|
|
20
11
|
private ellipsisWidth;
|
|
12
|
+
private disableArrowShadow;
|
|
21
13
|
/**
|
|
22
14
|
* Creates a new CanvasRenderer.
|
|
23
15
|
* @param canvas {HTMLCanvasElement} - The canvas to render on.
|
|
24
16
|
* @param context {CanvasRenderingContext2D} - The canvas context.
|
|
25
17
|
* @param state {NvlState} - The state.
|
|
26
|
-
* @param options {
|
|
18
|
+
* @param options {RendererOptions} - The visualization options.
|
|
27
19
|
*/
|
|
28
|
-
constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D | null, state: NvlState,
|
|
29
|
-
relationshipThreshold?: number;
|
|
30
|
-
});
|
|
20
|
+
constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D | null, state: NvlState, options?: RendererOptions);
|
|
31
21
|
/**
|
|
32
22
|
* Checks if the renderer needs to run.
|
|
33
23
|
* @returns Whether the renderer needs to run.
|
|
34
24
|
*/
|
|
35
25
|
needsToRun(): boolean;
|
|
36
26
|
/**
|
|
37
|
-
*
|
|
27
|
+
* Override processUpdates to add Canvas-specific shadow handling
|
|
38
28
|
*/
|
|
39
29
|
processUpdates(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Draws a single node on the canvas with all its visual elements (circle, icons, captions, etc.)
|
|
32
|
+
* @param ctx - The canvas rendering context
|
|
33
|
+
* @param node - The node to draw
|
|
34
|
+
*/
|
|
35
|
+
private drawNode;
|
|
36
|
+
/**
|
|
37
|
+
* Helper method to enable shadow on canvas context
|
|
38
|
+
*/
|
|
39
|
+
private enableShadow;
|
|
40
|
+
/**
|
|
41
|
+
* Helper method to disable shadow on canvas context
|
|
42
|
+
*/
|
|
43
|
+
private disableShadow;
|
|
44
|
+
/**
|
|
45
|
+
* Renders a waypoint arrow (relationship between two different nodes)
|
|
46
|
+
*/
|
|
47
|
+
private renderWaypointArrow;
|
|
48
|
+
/**
|
|
49
|
+
* Renders a self-referencing arrow (relationship from node to itself)
|
|
50
|
+
*/
|
|
51
|
+
private renderSelfArrow;
|
|
40
52
|
/**
|
|
41
53
|
* Draws the nodes and relationships to their positions on the canvas.
|
|
42
54
|
* @param positionArray {Node[]} - The array of nodes to draw
|
|
@@ -49,8 +61,6 @@ export default class CanvasRenderer {
|
|
|
49
61
|
ignoreAnimations?: boolean;
|
|
50
62
|
showCaptions?: boolean;
|
|
51
63
|
}): void;
|
|
52
|
-
private getRelationshipsToRender;
|
|
53
|
-
private getNodesToRender;
|
|
54
64
|
private renderNodes;
|
|
55
65
|
private renderRelationships;
|
|
56
66
|
/**
|
|
@@ -67,23 +77,6 @@ export default class CanvasRenderer {
|
|
|
67
77
|
* @todo: sort relationships by distance descending
|
|
68
78
|
*/
|
|
69
79
|
getRelsAt(pointer: Point): HitTargetRelationship[];
|
|
70
|
-
destroy(): void;
|
|
71
|
-
/**
|
|
72
|
-
* Checks if the bounding box is outside of the screen.
|
|
73
|
-
* @param boundingBox - The bounding box to check.
|
|
74
|
-
* @param clientWidth - The client width of the canvas.
|
|
75
|
-
* @param clientHeight - The client height of the canvas.
|
|
76
|
-
* @returns Whether the bounding box is off screen.
|
|
77
|
-
* @remarks This check doesn't catch all items that are off screen but its simple and removes many of them
|
|
78
|
-
*/
|
|
79
|
-
private isBoundingBoxOffScreen;
|
|
80
|
-
/**
|
|
81
|
-
* Handles the channel's additions, removals and updates and adds or removes the id from the active nodes.
|
|
82
|
-
* @param channel {Channel<Node>} - The channel to process
|
|
83
|
-
* @param fullData {DataSet<Node>} - The full data
|
|
84
|
-
* @param processUpdates {boolean} - Whether to process channel updates as well
|
|
85
|
-
*/
|
|
86
|
-
private handleChannelUpdate;
|
|
87
80
|
/**
|
|
88
81
|
* Handles zoom and pan on the canvas.
|
|
89
82
|
* @param context {CanvasRenderingContext2D} - The canvas context
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { BorderStyle, DisabledItemStyles } from '../../../modules/state/types';
|
|
2
|
+
import type { Relationship } from '../../../types/graph-element';
|
|
3
|
+
import type { Point } from '../../../utils/geometry';
|
|
4
|
+
import type ArrowBundle from '../shared/arrows/ArrowBundle';
|
|
5
|
+
/**
|
|
6
|
+
* Calculate label dimensions including font size, font weight, and truncated text.
|
|
7
|
+
*
|
|
8
|
+
* @param fullCaption - The complete caption text
|
|
9
|
+
* @param relWidth - The relationship width (may be undefined)
|
|
10
|
+
* @param selected - Whether the relationship is selected (affects font weight and width calculation)
|
|
11
|
+
* @param captionSize - The caption size multiplier (default 1)
|
|
12
|
+
* @param defaultRelWidth - The default relationship width to use if relWidth is undefined
|
|
13
|
+
* @param measureWidth - Function to measure text width given a text string
|
|
14
|
+
* @param maxWidth - The maximum width available for the label in pixels
|
|
15
|
+
* @returns LabelDimensions with calculated font metrics and label text
|
|
16
|
+
*/
|
|
17
|
+
export declare const calculateLabelDimensions: (fullCaption: string, measureWidth: (text: string) => number, maxWidth: number) => {
|
|
18
|
+
label: string;
|
|
19
|
+
width: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Calculate label transform including rotation and flip adjustments.
|
|
23
|
+
*
|
|
24
|
+
* @param angle - The base rotation angle in radians
|
|
25
|
+
* @param fontSize - The font size in pixels (including pixel ratio scaling)
|
|
26
|
+
* @param flip - Whether to flip the label (applies additional rotation)
|
|
27
|
+
* @param point - The base point (used to calculate offset in flip case)
|
|
28
|
+
* @returns object with final position and angle
|
|
29
|
+
*/
|
|
30
|
+
export declare const calculateLabelTransform: (angle: number, fontSize: number, flip: boolean, point: Point) => {
|
|
31
|
+
finalX: number;
|
|
32
|
+
finalY: number;
|
|
33
|
+
finalAngle: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Calculate vertical alignment offset for label based on caption alignment.
|
|
37
|
+
*
|
|
38
|
+
* @param captionAlign - The caption alignment: 'top' or 'bottom'
|
|
39
|
+
* @param fontSize - The font size in pixels (including pixel ratio scaling)
|
|
40
|
+
* @param lineWidth - The relationship line width in pixels
|
|
41
|
+
* @param padding - The padding around the label in pixels
|
|
42
|
+
* @returns The vertical offset in pixels to apply when drawing the label
|
|
43
|
+
*/
|
|
44
|
+
export declare const calculateLabelHeightAlign: (captionAlign: string, fontSize: number, lineWidth: number, padding: number) => number;
|
|
45
|
+
/**
|
|
46
|
+
* Calculate final label geometry for hit detection.
|
|
47
|
+
*
|
|
48
|
+
* @param point - The original point (before transform)
|
|
49
|
+
* @param angle - The rotation angle in radians
|
|
50
|
+
* @param maxWidth - The maximum width of the label in pixels
|
|
51
|
+
* @param fontSize - The font size in pixels (including pixel ratio scaling)
|
|
52
|
+
* @param heightAlign - The vertical alignment offset in pixels
|
|
53
|
+
* @param padding - The padding around the label in pixels
|
|
54
|
+
* @param pixelRatio - The device pixel ratio
|
|
55
|
+
* @param flip - Whether the label is flipped
|
|
56
|
+
* @returns object with position, rotation, width, and height for hit detection
|
|
57
|
+
*/
|
|
58
|
+
export declare const calculateLabelGeometry: (point: Point, angle: number, maxWidth: number, fontSize: number, heightAlign: number, padding: number, pixelRatio: number, flip: boolean) => {
|
|
59
|
+
position: {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
};
|
|
63
|
+
rotation: number;
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Determines the rendering state flags for a relationship.
|
|
69
|
+
*
|
|
70
|
+
* @param rel - The relationship to analyze
|
|
71
|
+
* @param disableArrowShadow - Global flag to disable arrow shadows
|
|
72
|
+
* @param showLabel - Whether the relationship label is visible
|
|
73
|
+
* @returns Object containing rendering state flags
|
|
74
|
+
*/
|
|
75
|
+
export declare const determineArrowRenderingState: (rel: Relationship, disableArrowShadow: boolean, showLabel: boolean) => {
|
|
76
|
+
isSelected: boolean;
|
|
77
|
+
isDisabled: boolean;
|
|
78
|
+
showOverlayIcon: boolean;
|
|
79
|
+
shouldRenderShadow: boolean;
|
|
80
|
+
shouldShowHoverEffect: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Selects relationship colors based on rendering state.
|
|
84
|
+
*
|
|
85
|
+
* @param rel - The relationship to get colors for
|
|
86
|
+
* @param selectedBorderStyle - The selected border style containing ring colors
|
|
87
|
+
* @param disabledItemStyles - Styling for disabled items
|
|
88
|
+
* @param defaultColor - Default color to use if none is specified
|
|
89
|
+
* @returns Object containing colors for different rendering layers
|
|
90
|
+
*/
|
|
91
|
+
export declare const selectArrowColors: (rel: Relationship, selectedBorderStyle: BorderStyle, disabledItemStyles: DisabledItemStyles, defaultColor: string) => {
|
|
92
|
+
mainColor: string;
|
|
93
|
+
selectedColor1: string;
|
|
94
|
+
selectedColor2: string;
|
|
95
|
+
hoverColor: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Calculates arrowhead adjustment for last segment truncation.
|
|
99
|
+
*
|
|
100
|
+
* @param lastSegmentDistance - Distance between the last two points
|
|
101
|
+
* @param headHeight - Height of the arrowhead
|
|
102
|
+
* @param headPositionOffset - Base position offset for the arrowhead (HeadChinHeight - headSelectedAdjustment)
|
|
103
|
+
* @param headSelectedAdjustment - Additional adjustment for selected state
|
|
104
|
+
* @param headChinHeight - Height of the arrowhead's chin (base)
|
|
105
|
+
* @param isSelected - Whether the arrow is selected
|
|
106
|
+
* @returns Object containing adjusted parameters and truncation flag
|
|
107
|
+
*/
|
|
108
|
+
export declare const calculateArrowheadAdjustment: (lastSegmentDistance: number, headHeight: number, headPositionOffset: number, headSelectedAdjustment: number, headChinHeight: number, isSelected: boolean) => {
|
|
109
|
+
adjustedHeadPositionOffset: number;
|
|
110
|
+
adjustedHeadSelectedAdjustment: number;
|
|
111
|
+
shouldTruncateLastSegment: boolean;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* The parameters for drawing an arrowhead.
|
|
115
|
+
*/
|
|
116
|
+
type ArrowHeadParameters = {
|
|
117
|
+
headPosition: Point;
|
|
118
|
+
headAngle: number;
|
|
119
|
+
headHeight: number;
|
|
120
|
+
headChinHeight: number;
|
|
121
|
+
headWidth: number;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Creates an arrowhead shape using a polygon.
|
|
125
|
+
* @param ctx - The canvas context to draw on.
|
|
126
|
+
* @param headLineWidth - The width of the arrowhead's outline.
|
|
127
|
+
* @param color - The color of the arrowhead.
|
|
128
|
+
* @param arrowHeadParameters - The parameters for the arrowhead.
|
|
129
|
+
* @param fill - Whether or not to fill the triangle.
|
|
130
|
+
* @param stroke - Whether or not to stroke the triangle.
|
|
131
|
+
*/
|
|
132
|
+
export declare const drawArrowHead: (ctx: CanvasRenderingContext2D, headLineWidth: number, color: string, arrowHeadParameters: ArrowHeadParameters, fill?: boolean, stroke?: boolean) => void;
|
|
133
|
+
/**
|
|
134
|
+
* Draws line segments on canvas (straight or curved).
|
|
135
|
+
*
|
|
136
|
+
* @param ctx - The canvas rendering context
|
|
137
|
+
* @param points - The array of points defining the segments
|
|
138
|
+
* @param width - The line width
|
|
139
|
+
* @param style - The stroke style (color)
|
|
140
|
+
* @param drawCurves - Whether to draw smooth curves through points
|
|
141
|
+
*/
|
|
142
|
+
export declare const drawSegments: (ctx: CanvasRenderingContext2D, points: Point[], width: number, style: string, drawCurves: boolean) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Draws a self-referencing loop on canvas using two quadratic Bézier curves.
|
|
145
|
+
*
|
|
146
|
+
* @param ctx - The canvas rendering context
|
|
147
|
+
* @param fromPoint - The start point of the loop
|
|
148
|
+
* @param toPoint - The end point of the loop
|
|
149
|
+
* @param apexPoint - The top point of the loop arc
|
|
150
|
+
* @param control1Point - Control point for the first curve segment
|
|
151
|
+
* @param control2Point - Control point for the second curve segment
|
|
152
|
+
*/
|
|
153
|
+
export declare const drawLoop: (ctx: CanvasRenderingContext2D, fromPoint: Point, toPoint: Point, apexPoint: Point, control1Point: Point, control2Point: Point) => void;
|
|
154
|
+
/**
|
|
155
|
+
* Draws a label for a relationship on canvas.
|
|
156
|
+
*
|
|
157
|
+
* @param ctx - The canvas rendering context
|
|
158
|
+
* @param point - The position to draw the label at
|
|
159
|
+
* @param angle - The rotation angle for the label
|
|
160
|
+
* @param maxWidth - The maximum width available for the label
|
|
161
|
+
* @param rel - The relationship to draw the label for
|
|
162
|
+
* @param bundle - The arrow bundle containing label info
|
|
163
|
+
* @param disabledItemStyles - Styles for disabled items
|
|
164
|
+
* @param fontColor - The font color to use
|
|
165
|
+
* @param flip - Whether to flip the label orientation (default false)
|
|
166
|
+
*/
|
|
167
|
+
export declare const drawLabel: (ctx: CanvasRenderingContext2D, point: Point, angle: number, maxWidth: number, rel: Relationship, bundle: ArrowBundle, disabledItemStyles: DisabledItemStyles, fontColor: string, flip?: boolean) => void;
|
|
168
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { BorderStyle, DisabledItemStyles, ShadowStyle } from '../../../modules/state/types';
|
|
2
|
+
import type { Node } from '../../../types/graph-element';
|
|
3
|
+
import type { TextSegment } from '../shared/types';
|
|
4
|
+
import type AnimationHandler from './AnimationHandler';
|
|
5
|
+
/**
|
|
6
|
+
* Draws borders around a node with a given array of border styles
|
|
7
|
+
* @param ctx - The canvas context.
|
|
8
|
+
* @param x - The x coordinate of the node.
|
|
9
|
+
* @param y - The y coordinate of the node.
|
|
10
|
+
* @param innerRadius - The inner radius of the node without any border.
|
|
11
|
+
* @param borderStyles - An array of border styles.
|
|
12
|
+
* @internal
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
15
|
+
export declare const drawCircleBand: (ctx: CanvasRenderingContext2D, x: number, y: number, innerRadius: number, borderStyles: {
|
|
16
|
+
width: number;
|
|
17
|
+
color: string;
|
|
18
|
+
}[]) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Fill a circle band with a gradient from a certain color to transparent
|
|
21
|
+
* @param ctx - The canvas context.
|
|
22
|
+
* @param x - The x coordinate of the node.
|
|
23
|
+
* @param y - The y coordinate of the node.
|
|
24
|
+
* @param color - The color of the gradient.
|
|
25
|
+
* @param radius - The inner radius of the node without any border.
|
|
26
|
+
* @param blur - The blur radius of the gradient.
|
|
27
|
+
* @param maxOpacity - The maximum opacity of the gradient.
|
|
28
|
+
*/
|
|
29
|
+
export declare const drawGradientCircleBand: (ctx: CanvasRenderingContext2D, x: number, y: number, color: string, radius: number, blur: number, maxOpacity?: number) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Draw a circle shape with a solid color
|
|
32
|
+
*/
|
|
33
|
+
export declare const drawSolidCircle: (ctx: CanvasRenderingContext2D, x: number, y: number, color: string, size: number) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Prints the caption for a node
|
|
36
|
+
*/
|
|
37
|
+
export declare const drawNodeCaption: (ctx: CanvasRenderingContext2D, lines: TextSegment[], stylesPerChar: string[][], initialYPos: number, fontSize: number, fontFace: string, lineDistance: number, x: number, y: number, ellipsisWidth: number) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate pulse animation parameters based on current animation state.
|
|
40
|
+
* The pulse grows from the node center to 1.88x the node radius, then fades out.
|
|
41
|
+
* This creates an expanding circle effect.
|
|
42
|
+
*
|
|
43
|
+
* @param nodeId - The unique identifier of the node
|
|
44
|
+
* @param animationHandler - The animation handler managing animation state
|
|
45
|
+
* @param mainFaceRadius - The radius of the main node circle in pixels
|
|
46
|
+
* @returns The calculated pulse radius
|
|
47
|
+
*/
|
|
48
|
+
export declare const calculatePulseAnimation: (mainFaceRadius: number) => {
|
|
49
|
+
pulseRadius: number;
|
|
50
|
+
pulseVisibility: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Calculate shadow animation parameters based on node state.
|
|
54
|
+
* Animates shadow width from 0 to target based on selected/hovered state.
|
|
55
|
+
*
|
|
56
|
+
* @param nodeId - The unique identifier of the node
|
|
57
|
+
* @param animationHandler - The animation handler managing animation state
|
|
58
|
+
* @param selected - Whether the node is selected
|
|
59
|
+
* @param hovered - Whether the node is hovered
|
|
60
|
+
* @param shadowStyle - The shadow style configuration
|
|
61
|
+
* @returns Object with shadowWidth, shadowFade, and shadowColor, or null if no shadow needed
|
|
62
|
+
*/
|
|
63
|
+
export declare const calculateShadowAnimation: (nodeId: string, animationHandler: AnimationHandler, selected: boolean, hovered: boolean, shadowStyle: ShadowStyle) => {
|
|
64
|
+
shadowWidth: number;
|
|
65
|
+
shadowColor: string;
|
|
66
|
+
shadowFade: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Returns an array of styles for the rings of a node.
|
|
70
|
+
* If the node is selected, it uses the selected ring styles.
|
|
71
|
+
* Otherwise, it uses the default ring styles.
|
|
72
|
+
* When no rings are configured, existing ring animations are wound down.
|
|
73
|
+
*
|
|
74
|
+
* @param node - The node to get the ring styles for.
|
|
75
|
+
* @param animationHandler - The animation handler.
|
|
76
|
+
* @param nodeBorderStyles - The node border styles.
|
|
77
|
+
* @returns An array of ring styles with computed widths.
|
|
78
|
+
*/
|
|
79
|
+
export type NodeRenderParamsInput = {
|
|
80
|
+
node: Node;
|
|
81
|
+
mainFaceRadius: number;
|
|
82
|
+
disabled: boolean;
|
|
83
|
+
disabledItemStyles: DisabledItemStyles;
|
|
84
|
+
selectedBorderStyle: BorderStyle;
|
|
85
|
+
animationHandler: AnimationHandler;
|
|
86
|
+
defaultNodeColor: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Calculate all node render parameters at once.
|
|
90
|
+
* This is the main entry point for preparing node rendering calculations.
|
|
91
|
+
*
|
|
92
|
+
* @param input - The input parameters object
|
|
93
|
+
* @returns object with node render parameters
|
|
94
|
+
*/
|
|
95
|
+
export declare const calculateNodeRenderParams: (input: NodeRenderParamsInput) => {
|
|
96
|
+
nodeColor: string;
|
|
97
|
+
fontColor: string;
|
|
98
|
+
shouldRenderPulse: boolean;
|
|
99
|
+
pulseAnimation: {
|
|
100
|
+
pulseColor: string;
|
|
101
|
+
pulseRadius: number;
|
|
102
|
+
};
|
|
103
|
+
shouldRenderShadow: boolean;
|
|
104
|
+
shadowAnimation: {
|
|
105
|
+
shadowWidth: number;
|
|
106
|
+
shadowFade: number;
|
|
107
|
+
shadowColor: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Cache } from '../shared/types';
|
|
2
|
+
declare class ImageCache {
|
|
3
|
+
cache: Cache;
|
|
4
|
+
constructor();
|
|
5
|
+
getImage(src: string, inverted?: boolean): HTMLCanvasElement;
|
|
6
|
+
private getOrCreateEntry;
|
|
7
|
+
private invertCanvas;
|
|
8
|
+
private loadImage;
|
|
9
|
+
private drawIfNeeded;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a promise that resolves when all images currently in the cache have finished loading.
|
|
12
|
+
* Useful before export operations to ensure all icons are available.
|
|
13
|
+
*/
|
|
14
|
+
waitForImages(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export default ImageCache;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Relationship } from '
|
|
2
|
-
import type { Point } from '
|
|
1
|
+
import type { Relationship } from '../../../../types/graph-element';
|
|
2
|
+
import type { Point } from '../../../../utils/geometry';
|
|
3
3
|
import type { WaypointPath } from '../types';
|
|
4
4
|
export interface LabelGeometry {
|
|
5
5
|
position: Point;
|
|
@@ -19,12 +19,28 @@ export default class ArrowBundle {
|
|
|
19
19
|
toId: string;
|
|
20
20
|
angles: number[];
|
|
21
21
|
labelInfo: Record<string, LabelGeometry>;
|
|
22
|
+
relIndexCache: Map<string, number>;
|
|
23
|
+
relDirectionCache: Map<string, boolean>;
|
|
24
|
+
private cachedMaxFontSize;
|
|
22
25
|
/**
|
|
23
26
|
* @param key - The key of the arrow bundle.
|
|
24
27
|
* @param fromId - The source node of the arrow bundle.
|
|
25
28
|
* @param toId - The target node of the arrow bundle.
|
|
26
29
|
*/
|
|
27
30
|
constructor(key: string, fromId: string, toId: string);
|
|
31
|
+
/**
|
|
32
|
+
* Recalculate and cache the maximum font size
|
|
33
|
+
*/
|
|
34
|
+
updateMaxFontSize(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Updates the relationship direction cache with a given relationship
|
|
37
|
+
* @param rel - The relationship to update the direction for.
|
|
38
|
+
*/
|
|
39
|
+
updateRelDirection(rel: Relationship): void;
|
|
40
|
+
/**
|
|
41
|
+
* Regenerates index cache for rel ids in bundle
|
|
42
|
+
*/
|
|
43
|
+
updateIndexCache(): void;
|
|
28
44
|
/**
|
|
29
45
|
* Insert a new arrow to the bundle
|
|
30
46
|
* @param rel - The relationship to insert.
|
|
@@ -53,7 +69,7 @@ export default class ArrowBundle {
|
|
|
53
69
|
* @param rel - The relationship to check.
|
|
54
70
|
* @returns True if the relationship is in opposite direction to the bundle.
|
|
55
71
|
*/
|
|
56
|
-
relIsOppositeDirection({
|
|
72
|
+
relIsOppositeDirection({ id }: Relationship): boolean;
|
|
57
73
|
/**
|
|
58
74
|
* Get the index of a given arrow in the bundle
|
|
59
75
|
* @param rel - The arrow to look for.
|
|
@@ -65,7 +81,7 @@ export default class ArrowBundle {
|
|
|
65
81
|
* @param index - The index of the arrow to get.
|
|
66
82
|
* @returns The arrow at the given index.
|
|
67
83
|
*/
|
|
68
|
-
getRel(index: number): Relationship
|
|
84
|
+
getRel(index: number): Relationship;
|
|
69
85
|
/**
|
|
70
86
|
* Set the waypoints for the arrow bundle
|
|
71
87
|
* @param waypoints - The waypoints for the arrow bundle.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { Node, Relationship } from '
|
|
1
|
+
import type { Node, Relationship } from '../../../../types/graph-element';
|
|
2
2
|
import type { WaypointPath } from '../types';
|
|
3
3
|
import ArrowBundle from './ArrowBundle';
|
|
4
4
|
export default class ArrowBundler {
|
|
5
5
|
bundles: Record<string, ArrowBundle>;
|
|
6
6
|
nodeToBundles: Record<string, ArrowBundle[]>;
|
|
7
|
+
relToBundleKey: Map<string, string>;
|
|
7
8
|
constructor(rels: Relationship[], waypoints: Record<string, WaypointPath>);
|
|
8
9
|
/**
|
|
9
10
|
* Get the arrow bundle for a given relation
|
|
@@ -23,6 +24,15 @@ export default class ArrowBundler {
|
|
|
23
24
|
* @param positionMap A map of node IDs to positions.
|
|
24
25
|
*/
|
|
25
26
|
updatePositions(positionMap: Record<string, Node>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Remove a bundle reference from the node→bundles index for one node id.
|
|
29
|
+
*/
|
|
30
|
+
private removeNodeFromMap;
|
|
31
|
+
/**
|
|
32
|
+
* Remove a relationship from a bundle.
|
|
33
|
+
* If the bundle is now empty, remove it from `bundles` and the node index.
|
|
34
|
+
*/
|
|
35
|
+
private removeRelFromBundle;
|
|
26
36
|
/**
|
|
27
37
|
* Get a unique ID for a pair of IDs
|
|
28
38
|
* @param id1 - The first ID.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|