@neo4j-nvl/base 1.0.0 → 1.1.0-17f2ef68
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 +24 -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 -3
- package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment-verlet.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 +30 -9
- 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 +2 -1
- 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 +11 -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 +4 -1
- 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/package.json +25 -24
- 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 → domrenderer/BaseRenderer.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/Animation.d.ts +0 -0
- /package/dist/types/renderers/{canvasrenderer/ImageCache.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/ArrowBundle.test.d.ts → domrenderer/canvasrenderer/CanvasRenderer.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/arrows/ArrowBundler.test.d.ts → domrenderer/canvasrenderer/arrowDrawing.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/arrows/arrows.test.d.ts → domrenderer/canvasrenderer/nodeDrawing.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/nodes/nodes.test.d.ts → domrenderer/shared/ImageCache.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/util.test.d.ts → domrenderer/shared/arrows/ArrowBundle.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer/wordwrap.test.d.ts → domrenderer/shared/arrows/ArrowBundler.test.d.ts} +0 -0
- /package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/constants.d.ts +0 -0
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
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { BorderStyle } from '../../../../modules/state/types';
|
|
2
|
+
import type { Node, Relationship } from '../../../../types/graph-element';
|
|
3
|
+
import type { Point } from '../../../../utils/geometry';
|
|
4
|
+
import type ArrowBundle from './ArrowBundle';
|
|
5
|
+
/**
|
|
6
|
+
* This function calculates the difference in radius between two nodes.
|
|
7
|
+
* @param toArrowGap - The gap between the node and the arrow on the to side.
|
|
8
|
+
* @param fromArrowGap - The gap between the node and the arrow on the from side.
|
|
9
|
+
* @returns The difference in radius between the two nodes.
|
|
10
|
+
* @comment can be affected for example by the label crust and selected ring
|
|
11
|
+
* as well as a gap between the node and the arrow on it's side.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getRadiusDifference: (toArrowGap: number, fromArrowGap: number) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Calculates control points for self-referencing relationships
|
|
16
|
+
* @param {Relationship} rel - The relationship
|
|
17
|
+
* @param {Node} node - The node the relationship refers to
|
|
18
|
+
* @param {ArrowBundle} bundle - The arrow bundle
|
|
19
|
+
* @returns Object containing angles and coordinate points for the self-loop
|
|
20
|
+
*/
|
|
21
|
+
export declare const getSelfArrowControlPoints: (rel: Relationship, node: Node, bundle: ArrowBundle) => {
|
|
22
|
+
angle: number;
|
|
23
|
+
startAngle: number;
|
|
24
|
+
endAngle: number;
|
|
25
|
+
startPoint: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
};
|
|
29
|
+
endPoint: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
33
|
+
apexPoint: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
};
|
|
37
|
+
control1Point: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
control2Point: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
45
|
+
nodeGap: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Calculates position, angle and flip for a self-referencing relationship label.
|
|
49
|
+
* Used by both Canvas and SVG renderers to ensure consistent positioning.
|
|
50
|
+
* This function handles all the math internally including headAngle and headSelectedAdjustment calculations.
|
|
51
|
+
*/
|
|
52
|
+
export declare const getSelfArrowLabelPosition: (apexPoint: Point, angle: number, endPoint: Point, control2Point: Point, isSelected: boolean, selectionRings: BorderStyle["rings"], relWidth?: number) => {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
angle: number;
|
|
56
|
+
flip: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Calculates the padding for selected relationships based on border style
|
|
60
|
+
* @param selectedBorderRings - Array of border rings for selected state
|
|
61
|
+
* @returns The total selection padding
|
|
62
|
+
*/
|
|
63
|
+
export declare const getSelectionPadding: (selectedBorderRings?: BorderStyle["rings"]) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Calculates the position and angle for a relationship label based on the Canvas renderer's logic.
|
|
66
|
+
* This handles both straight lines and curves, with special logic for odd/even number of points.
|
|
67
|
+
*
|
|
68
|
+
* @param points - Array of points defining the relationship line
|
|
69
|
+
* @param fromNode - The source node
|
|
70
|
+
* @param toNode - The target node
|
|
71
|
+
* @param drawCurves - Whether curves are being drawn
|
|
72
|
+
* @param isSelected - Whether the relationship is selected
|
|
73
|
+
* @param captionAlign - Caption alignment ('top' or 'bottom')
|
|
74
|
+
* @param selectedBorderRings - Array of border rings for selected state
|
|
75
|
+
* @returns Object containing x, y position and angle for the label
|
|
76
|
+
*/
|
|
77
|
+
export declare const getRelationshipLabelPosition: (points: Point[], fromNode: Node, toNode: Node, drawCurves: boolean, isSelected: boolean, selectedBorderRings: BorderStyle["rings"], captionAlign?: "top" | "bottom") => {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
angle: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* This function calculates the coordinates of the via point
|
|
84
|
+
* between two nodes. The via point is used to bend the edge
|
|
85
|
+
* between the two nodes.
|
|
86
|
+
* @param fromNode - The node the edge starts from.
|
|
87
|
+
* @param toNode - The node the edge ends at.
|
|
88
|
+
* @param fromArrowGap - The gap between the node and the arrow on the from side.
|
|
89
|
+
* @param toArrowGap - The gap between the node and the arrow on the to side.
|
|
90
|
+
* @returns The coordinates of the via point.
|
|
91
|
+
*/
|
|
92
|
+
export declare const getViaCoordinates: (fromNode: Node, toNode: Node, fromArrowGap: number, toArrowGap: number, rel: Relationship, bundle: ArrowBundle) => Point;
|
|
93
|
+
export declare const getPointsForStraight: (rel: Relationship, bundle: ArrowBundle, fromNode: Node, toNode: Node, showLabel: boolean, curved?: boolean) => Point[];
|
|
94
|
+
export declare const distanceToEdge: (pos: Point, rel: Relationship, fromNode: Node, toNode: Node, bundle: ArrowBundle, showLabel: boolean, drawCurves?: boolean) => number;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the bounding box of the arrow.
|
|
97
|
+
* @param rel - The relationship to get the bounding box for.
|
|
98
|
+
* @param bundle - The arrow bundle the relationship is part of.
|
|
99
|
+
* @param fromNode - The node the relationship is coming from.
|
|
100
|
+
* @param toNode - The node the relationship is going to.
|
|
101
|
+
* @param showLabel - Whether or not a label is shown.
|
|
102
|
+
* @param drawCurves - Whether or the relationship is drawn as a curve.
|
|
103
|
+
* @returns The bounding box of the arrow.
|
|
104
|
+
*/
|
|
105
|
+
export declare const getBoundingBox: (rel: Relationship, bundle: ArrowBundle, fromNode: Node, toNode: Node, showLabel?: boolean, drawCurves?: boolean) => DOMRect | null;
|
|
106
|
+
/**
|
|
107
|
+
* Calculates the width of a relationship including selection factor and pixel ratio
|
|
108
|
+
* @param rel - The relationship
|
|
109
|
+
* @param defaultWidth - The default relationship width
|
|
110
|
+
* @returns The calculated relationship width
|
|
111
|
+
*/
|
|
112
|
+
export declare const getRelationshipWidth: (rel: Relationship, defaultWidth: number) => number;
|
|
113
|
+
/**
|
|
114
|
+
* Adjusts relationship line points to create proper gaps at start and end.
|
|
115
|
+
* The Canvas renderer uses this logic:
|
|
116
|
+
* - End gap (arrowhead): headHeight/2 + headSelectedAdjustment
|
|
117
|
+
* - Start gap (tail): Only for selected relationships, uses getSelectionPadding
|
|
118
|
+
*
|
|
119
|
+
* @param points - Array of points defining the relationship line (will be modified in place)
|
|
120
|
+
* @param isSelected - Whether the relationship is selected
|
|
121
|
+
* @param headHeight - The height of the arrowhead
|
|
122
|
+
* @param headSelectedAdjustment - Additional adjustment for selected relationships
|
|
123
|
+
* @param selectedBorderRings - Array of border rings for selected state
|
|
124
|
+
* @returns Object with adjusted points and the tail offset applied (for label positioning)
|
|
125
|
+
*/
|
|
126
|
+
export declare const adjustPointsForGaps: (points: Point[], isSelected: boolean, headHeight: number, headSelectedAdjustment: number, selectedBorderRings: BorderStyle["rings"]) => {
|
|
127
|
+
tailOffset: Point | null;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Calculates arrowhead scaling and dimensions for rendering.
|
|
131
|
+
*
|
|
132
|
+
* @param width - The raw width of the relationship (before pixel ratio scaling)
|
|
133
|
+
* @param isSelected - Whether the relationship is selected
|
|
134
|
+
* @param selectedBorderRings - Array of border rings for selected state
|
|
135
|
+
* @returns Object containing all calculated arrowhead dimensions and adjustments
|
|
136
|
+
*/
|
|
137
|
+
export declare const calculateArrowheadScaling: (width: number, isSelected: boolean, selectedBorderRings: BorderStyle["rings"]) => {
|
|
138
|
+
headFactor: number;
|
|
139
|
+
headHeight: number;
|
|
140
|
+
headChinHeight: number;
|
|
141
|
+
headWidth: number;
|
|
142
|
+
headSelectedAdjustment: number;
|
|
143
|
+
headPositionOffset: number;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Calculates the dimensions of an arrowhead
|
|
147
|
+
* @param relWidth - The width of the relationship line
|
|
148
|
+
* @param defaultRelWidth - The default relationship width
|
|
149
|
+
* @param isSelected - Whether the relationship is selected
|
|
150
|
+
* @param selectedBorderRings - Array of border rings for selected state
|
|
151
|
+
* @returns Object containing headHeight, headChinHeight, headWidth, and headSelectedAdjustment
|
|
152
|
+
*/
|
|
153
|
+
export declare const getArrowheadDimensions: (relWidth: number, defaultRelWidth: number, isSelected: boolean, selectedBorderRings: BorderStyle["rings"]) => {
|
|
154
|
+
headHeight: number;
|
|
155
|
+
headChinHeight: number;
|
|
156
|
+
headWidth: number;
|
|
157
|
+
headSelectedAdjustment: number;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Calculates the size of an overlay icon on a relationship
|
|
161
|
+
* @param iconSizeFactor - The size factor from the overlay icon configuration
|
|
162
|
+
* @returns The calculated overlay icon size
|
|
163
|
+
*/
|
|
164
|
+
export declare const getOverlayIconSize: (iconSizeFactor: number) => number;
|
|
165
|
+
/**
|
|
166
|
+
* Calculates the alignment offsets for an overlay icon on a relationship
|
|
167
|
+
* @param position - The position array [x, y] from overlay icon configuration
|
|
168
|
+
* @param width - The available width for the icon
|
|
169
|
+
* @param height - The height of the icon
|
|
170
|
+
* @returns Object with widthAlign and heightAlign offsets
|
|
171
|
+
*/
|
|
172
|
+
export declare const getOverlayIconAlignment: (position: [number, number], width: number, height: number) => {
|
|
173
|
+
widthAlign: number;
|
|
174
|
+
heightAlign: number;
|
|
175
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|