@neo4j-nvl/base 0.3.9 → 1.0.0-08b14670

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/base.mjs +1 -1
  3. package/dist/types/index.d.ts +101 -78
  4. package/dist/types/layouts/animatedlayout/animationUtils.d.ts +3 -3
  5. package/dist/types/layouts/circularLayout/CircularLayout.d.ts +18 -0
  6. package/dist/types/layouts/forcedirectedlayout/ForceCytoLayout.d.ts +1 -1
  7. package/dist/types/layouts/forcedirectedlayout/physlayout/PhysLayout.d.ts +27 -22
  8. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment-verlet.d.ts +1 -1
  9. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/SolarMerger.d.ts +17 -39
  10. package/dist/types/layouts/forcedirectedlayout/physlayout/solarmerger/types.d.ts +49 -0
  11. package/dist/types/modules/CallbackHelper.d.ts +5 -5
  12. package/dist/types/modules/ExternalCallbackHandler.d.ts +7 -0
  13. package/dist/types/modules/NvlController.d.ts +11 -7
  14. package/dist/types/modules/dataset.d.ts +1 -1
  15. package/dist/types/modules/state/state.d.ts +2 -2
  16. package/dist/types/modules/state/types.d.ts +73 -61
  17. package/dist/types/modules/state/utils.d.ts +8 -6
  18. package/dist/types/renderers/domrenderer/BaseRenderer.d.ts +66 -0
  19. package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/Animation.d.ts +8 -11
  20. package/dist/types/renderers/{canvasrenderer → domrenderer/canvasrenderer}/AnimationHandler.d.ts +15 -16
  21. package/dist/types/renderers/domrenderer/canvasrenderer/CanvasRenderer.d.ts +153 -0
  22. package/dist/types/renderers/domrenderer/canvasrenderer/canvasUtils.d.ts +56 -0
  23. package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/ImageCache.d.ts +1 -1
  24. package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/ArrowBundle.d.ts +17 -17
  25. package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/ArrowBundler.d.ts +9 -9
  26. package/dist/types/renderers/domrenderer/shared/arrows/arrows.d.ts +148 -0
  27. package/dist/types/renderers/domrenderer/shared/nodes/nodeUtils.d.ts +28 -0
  28. package/dist/types/renderers/domrenderer/shared/nodes/nodes.d.ts +58 -0
  29. package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/types.d.ts +8 -6
  30. package/dist/types/renderers/domrenderer/shared/util.d.ts +11 -0
  31. package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/vectorUtils.d.ts +1 -1
  32. package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/wordwrap.d.ts +13 -13
  33. package/dist/types/renderers/domrenderer/shared/wordwrap.test.d.ts +1 -0
  34. package/dist/types/renderers/domrenderer/svgrenderer/SvgRenderer.d.ts +27 -0
  35. package/dist/types/renderers/domrenderer/svgrenderer/SvgRenderer.test.d.ts +1 -0
  36. package/dist/types/renderers/domrenderer/svgrenderer/svgUtils.d.ts +191 -0
  37. package/dist/types/renderers/webglrenderer/Renderer.d.ts +5 -1
  38. package/dist/types/renderers/webglrenderer/Renderer.test.d.ts +1 -0
  39. package/dist/types/types/graph-element.d.ts +16 -7
  40. package/dist/types/utils/canvasManagement.d.ts +18 -2
  41. package/dist/types/utils/circularUtils.d.ts +3 -0
  42. package/dist/types/utils/circularUtils.test.d.ts +1 -0
  43. package/dist/types/utils/colorUtils.d.ts +3 -3
  44. package/dist/types/utils/constants.d.ts +6 -4
  45. package/dist/types/utils/errors.d.ts +2 -1
  46. package/dist/types/utils/geometry.d.ts +31 -30
  47. package/dist/types/utils/graphObjectUtils.d.ts +5 -5
  48. package/dist/types/utils/hittest.d.ts +2 -0
  49. package/dist/types/utils/jsDriverResultTransformer.d.ts +14 -7
  50. package/dist/types/utils/segmentAnalytics.d.ts +8 -8
  51. package/dist/types/utils/zoomFunctions.d.ts +30 -23
  52. package/package.json +25 -24
  53. package/dist/types/modules/performance.d.ts +0 -93
  54. package/dist/types/renderers/canvasrenderer/CanvasRenderer.d.ts +0 -93
  55. package/dist/types/renderers/canvasrenderer/arrows/arrows.d.ts +0 -55
  56. package/dist/types/renderers/canvasrenderer/nodes/nodes.d.ts +0 -59
  57. package/dist/types/renderers/canvasrenderer/util.d.ts +0 -69
  58. /package/dist/types/{renderers/canvasrenderer/Animation.test.d.ts → layouts/d3forcelayout/circularLayout.test.d.ts} +0 -0
  59. /package/dist/types/renderers/{canvasrenderer/CanvasRenderer.test.d.ts → domrenderer/canvasrenderer/Animation.test.d.ts} +0 -0
  60. /package/dist/types/renderers/{canvasrenderer/ImageCache.test.d.ts → domrenderer/canvasrenderer/CanvasRenderer.test.d.ts} +0 -0
  61. /package/dist/types/renderers/{canvasrenderer/arrows/ArrowBundle.test.d.ts → domrenderer/shared/ImageCache.test.d.ts} +0 -0
  62. /package/dist/types/renderers/{canvasrenderer/arrows/ArrowBundler.test.d.ts → domrenderer/shared/arrows/ArrowBundle.test.d.ts} +0 -0
  63. /package/dist/types/renderers/{canvasrenderer/arrows/arrows.test.d.ts → domrenderer/shared/arrows/ArrowBundler.test.d.ts} +0 -0
  64. /package/dist/types/renderers/{canvasrenderer/nodes/nodes.test.d.ts → domrenderer/shared/arrows/arrows.test.d.ts} +0 -0
  65. /package/dist/types/renderers/{canvasrenderer → domrenderer/shared}/arrows/constants.d.ts +0 -0
  66. /package/dist/types/renderers/{canvasrenderer/util.test.d.ts → domrenderer/shared/nodes/nodes.test.d.ts} +0 -0
  67. /package/dist/types/renderers/{canvasrenderer/wordwrap.test.d.ts → domrenderer/shared/util.test.d.ts} +0 -0
@@ -0,0 +1,153 @@
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 BaseRenderer from '../BaseRenderer';
6
+ export default class CanvasRenderer extends BaseRenderer {
7
+ private activeNodes;
8
+ private canvas;
9
+ private context;
10
+ private animationHandler;
11
+ private ellipsisWidth;
12
+ private disableArrowShadow;
13
+ /**
14
+ * Creates a new CanvasRenderer.
15
+ * @param canvas {HTMLCanvasElement} - The canvas to render on.
16
+ * @param context {CanvasRenderingContext2D} - The canvas context.
17
+ * @param state {NvlState} - The state.
18
+ * @param options {{ relationshipThreshold: number }} - The visualization options.
19
+ */
20
+ constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D | null, state: NvlState, { relationshipThreshold }?: {
21
+ relationshipThreshold?: number;
22
+ });
23
+ /**
24
+ * Checks if the renderer needs to run.
25
+ * @returns Whether the renderer needs to run.
26
+ */
27
+ needsToRun(): boolean;
28
+ /**
29
+ * Override to handle Canvas-specific node channel updates
30
+ */
31
+ protected onNodeVersionUpdate(nodeChannel: any): void;
32
+ /**
33
+ * Override processUpdates to add Canvas-specific shadow logic
34
+ */
35
+ processUpdates(): void;
36
+ /**
37
+ * Draws a single node on the canvas with all its visual elements (circle, icons, captions, etc.)
38
+ * @param ctx - The canvas rendering context
39
+ * @param node - The node to draw
40
+ * @param imageCache - The image cache for icons
41
+ * @param animationHandler - The animation handler for transitions
42
+ * @param nodeBorderStyles - The border styles for nodes
43
+ * @param disabledItemStyles - The styles for disabled items
44
+ * @param defaultNodeColor - The default node color
45
+ * @param ellipsisWidth - The width of the ellipsis character
46
+ * @param zoomLevel - The current zoom level
47
+ */
48
+ private drawNode;
49
+ /**
50
+ * Helper method to enable shadow on canvas context
51
+ */
52
+ private enableShadow;
53
+ /**
54
+ * Helper method to disable shadow on canvas context
55
+ */
56
+ private disableShadow;
57
+ /**
58
+ * Gets the relationship width considering selection factor
59
+ */
60
+ private getRelWidth;
61
+ /**
62
+ * Draws line segments on canvas (straight or curved)
63
+ */
64
+ private drawSegments;
65
+ /**
66
+ * Gets the padding for selected relationships
67
+ */
68
+ private getSelectionPadding;
69
+ /**
70
+ * Gets the overlay icon size
71
+ */
72
+ private getOverlayIconSize;
73
+ /**
74
+ * Gets the overlay icon alignment based on position
75
+ */
76
+ private getOverlayIconAlignment;
77
+ /**
78
+ * Draws a self-referencing loop on canvas
79
+ */
80
+ private drawLoop;
81
+ /**
82
+ * Draws a label for a relationship
83
+ */
84
+ private drawLabel;
85
+ /**
86
+ * Renders a waypoint arrow (relationship between two different nodes)
87
+ */
88
+ private renderWaypointArrow;
89
+ /**
90
+ * Renders a self-referencing arrow (relationship from node to itself)
91
+ */
92
+ private renderSelfArrow;
93
+ /**
94
+ * Main arrow rendering method that delegates to waypoint or self-arrow rendering
95
+ */
96
+ private renderArrow;
97
+ /**
98
+ * Draws the nodes and relationships to their positions on the canvas.
99
+ * @param positionArray {Node[]} - The array of nodes to draw
100
+ * @param options {any} - The options for the render
101
+ */
102
+ render(positionArray: Node[], options?: {
103
+ canvas?: HTMLCanvasElement;
104
+ context?: CanvasRenderingContext2D;
105
+ backgroundColor?: string;
106
+ ignoreAnimations?: boolean;
107
+ showCaptions?: boolean;
108
+ }): void;
109
+ private getRelationshipsToRenderCanvas;
110
+ private getNodesToRenderCanvas;
111
+ private renderNodes;
112
+ private renderRelationships;
113
+ /**
114
+ * Returns the nodes at the pointer position
115
+ * @param pointer - The position of the pointer.
116
+ * @returns The nodes at the pointer position.
117
+ * @todo Sort nodes by distance descending
118
+ */
119
+ getNodesAt(pointer: Point, hitNodeMarginWidth?: number): HitTargetNode[];
120
+ /**
121
+ * Returns the relationships at the pointer position
122
+ * @param pointer - The position of the pointer.
123
+ * @returns The relationships at the pointer position.
124
+ * @todo: sort relationships by distance descending
125
+ */
126
+ getRelsAt(pointer: Point): HitTargetRelationship[];
127
+ destroy(): void;
128
+ /**
129
+ * Handles the channel's additions, removals and updates and adds or removes the id from the active nodes.
130
+ * @param channel {Channel<Node>} - The channel to process
131
+ * @param fullData {DataSet<Node>} - The full data
132
+ * @param processUpdates {boolean} - Whether to process channel updates as well
133
+ */
134
+ private handleChannelUpdate;
135
+ /**
136
+ * Returns an array of styles for the rings of a node.
137
+ * It takes the node as an argument, and an optional array of size animations.
138
+ * If the node is selected, it returns the selectedStyle.rings array.
139
+ * If the node is not selected, it returns an array containing only one object with
140
+ * a width of 0 and an empty color.
141
+ * @param node - The node to get the ring styles for.
142
+ * @param animationHandler - The animation handler.
143
+ * @param nodeBorderStyles - The node border styles.
144
+ * @returns An array of ring styles.
145
+ */
146
+ private getRingStyles;
147
+ /**
148
+ * Handles zoom and pan on the canvas.
149
+ * @param context {CanvasRenderingContext2D} - The canvas context
150
+ * @param canvas {HTMLCanvasElement} - The canvas
151
+ */
152
+ private zoomAndPan;
153
+ }
@@ -0,0 +1,56 @@
1
+ import type { Point } from '../../../utils/geometry';
2
+ import type { TextSegment } from '../shared/types';
3
+ /**
4
+ * The parameters for drawing an arrowhead.
5
+ */
6
+ type ArrowHeadParameters = {
7
+ headPosition: Point;
8
+ headAngle: number;
9
+ headHeight: number;
10
+ headChinHeight: number;
11
+ headWidth: number;
12
+ };
13
+ /**
14
+ * Creates an arrowhead shape using a polygon.
15
+ * @param ctx - The canvas context to draw on.
16
+ * @param headLineWidth - The width of the arrowhead's outline.
17
+ * @param color - The color of the arrowhead.
18
+ * @param arrowHeadParameters - The parameters for the arrowhead.
19
+ * @param fill - Whether or not to fill the triangle.
20
+ * @param stroke - Whether or not to stroke the triangle.
21
+ */
22
+ export declare const drawArrowHead: (ctx: CanvasRenderingContext2D, headLineWidth: number, color: string, arrowHeadParameters: ArrowHeadParameters, fill?: boolean, stroke?: boolean) => void;
23
+ /**
24
+ * Draws borders around a node with a given array of border styles
25
+ * @param ctx - The canvas context.
26
+ * @param x - The x coordinate of the node.
27
+ * @param y - The y coordinate of the node.
28
+ * @param innerRadius - The inner radius of the node without any border.
29
+ * @param borderStyles - An array of border styles.
30
+ * @internal
31
+ * @hidden
32
+ */
33
+ export declare const drawCircleBand: (ctx: CanvasRenderingContext2D, x: number, y: number, innerRadius: number, borderStyles: {
34
+ width: number;
35
+ color: string;
36
+ }[]) => void;
37
+ /**
38
+ * Fill a circle band with a gradient from a certain color to transparent
39
+ * @param ctx - The canvas context.
40
+ * @param x - The x coordinate of the node.
41
+ * @param y - The y coordinate of the node.
42
+ * @param color - The color of the gradient.
43
+ * @param radius - The inner radius of the node without any border.
44
+ * @param blur - The blur radius of the gradient.
45
+ * @param maxOpacity - The maximum opacity of the gradient.
46
+ */
47
+ export declare const drawGradientCircleBand: (ctx: CanvasRenderingContext2D, x: number, y: number, color: string, radius: number, blur: number, maxOpacity?: number) => void;
48
+ /**
49
+ * Draw a circle shape with a solid color
50
+ */
51
+ export declare const drawSolidCircle: (ctx: CanvasRenderingContext2D, x: number, y: number, color: string, size: number) => void;
52
+ /**
53
+ * Prints the caption for a node
54
+ */
55
+ 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;
56
+ export {};
@@ -1,4 +1,4 @@
1
- import type { Cache } from './types';
1
+ import type { Cache } from '../shared/types';
2
2
  declare class ImageCache {
3
3
  cache: Cache;
4
4
  constructor();
@@ -1,5 +1,5 @@
1
- import type { Relationship } from '../../../types/graph-element';
2
- import type { Point } from '../../../utils/geometry';
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;
@@ -20,60 +20,60 @@ export default class ArrowBundle {
20
20
  angles: number[];
21
21
  labelInfo: Record<string, LabelGeometry>;
22
22
  /**
23
- * @param {string} key - The key of the arrow bundle
24
- * @param {string} fromId - The source node of the arrow bundle
25
- * @param {string} toId - The target node of the arrow bundle
23
+ * @param key - The key of the arrow bundle.
24
+ * @param fromId - The source node of the arrow bundle.
25
+ * @param toId - The target node of the arrow bundle.
26
26
  */
27
27
  constructor(key: string, fromId: string, toId: string);
28
28
  /**
29
29
  * Insert a new arrow to the bundle
30
- * @param {Relationship} rel - The relationship to insert
30
+ * @param rel - The relationship to insert.
31
31
  */
32
32
  insert(rel: Relationship): void;
33
33
  setLabelInfo(relId: string, labelInfo: LabelGeometry): void;
34
34
  has({ id }: Relationship): boolean;
35
35
  /**
36
36
  * Remove an arrow from the bundle
37
- * @param {Relationship} rel - The arrow to remove
37
+ * @param rel - The arrow to remove.
38
38
  */
39
39
  remove({ id }: Relationship): void;
40
40
  /**
41
41
  * Get the size of the arrow bundle
42
- * @returns {number} The size of the arrow bundle
42
+ * @returns The size of the arrow bundle.
43
43
  */
44
44
  size(): number;
45
45
  relArray(): Relationship[];
46
46
  /**
47
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
48
+ * @returns The maximum font size of the arrows in the bundle.
49
49
  */
50
50
  maxFontSize(): number;
51
51
  /**
52
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
53
+ * @param rel - The relationship to check.
54
+ * @returns True if the relationship is in opposite direction to the bundle.
55
55
  */
56
56
  relIsOppositeDirection({ from, to }: Relationship): boolean;
57
57
  /**
58
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
59
+ * @param rel - The arrow to look for.
60
+ * @returns The index of the arrow in the bundle, or -1 if not found.
61
61
  */
62
62
  indexOf({ id }: Relationship): number;
63
63
  /**
64
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
65
+ * @param index - The index of the arrow to get.
66
+ * @returns The arrow at the given index.
67
67
  */
68
68
  getRel(index: number): Relationship | null;
69
69
  /**
70
70
  * Set the waypoints for the arrow bundle
71
- * @param {WaypointPath} waypoints - The waypoints for the arrow bundle
71
+ * @param waypoints - The waypoints for the arrow bundle.
72
72
  */
73
73
  setWaypoints(waypoints: WaypointPath): void;
74
74
  /**
75
75
  * Set the angles for the arrow bundle
76
- * @param {number[]} angles - The angles for the arrow bundle
76
+ * @param angles - The angles for the arrow bundle.
77
77
  */
78
78
  setAngles(angles: number[]): void;
79
79
  }
@@ -1,4 +1,4 @@
1
- import type { Node, Relationship } from '../../../types/graph-element';
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 {
@@ -7,15 +7,15 @@ export default class ArrowBundler {
7
7
  constructor(rels: Relationship[], waypoints: Record<string, WaypointPath>);
8
8
  /**
9
9
  * Get the arrow bundle for a given relation
10
- * @param {Relationship} rel - The relationship
11
- * @returns {ArrowBundle} The arrow bundle
10
+ * @param rel - The relationship.
11
+ * @returns The arrow bundle.
12
12
  */
13
13
  getBundle(rel: Relationship): ArrowBundle;
14
14
  /**
15
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
16
+ * @param addedRels - The added relations.
17
+ * @param removedRels - The removed relations.
18
+ * @param waypoints - The waypoints.
19
19
  */
20
20
  updateData(addedRels: Record<string, Relationship>, removedRels: Record<string, Relationship>, updatedRels: Record<string, Relationship>, waypoints: Record<string, WaypointPath>): void;
21
21
  /**
@@ -25,9 +25,9 @@ export default class ArrowBundler {
25
25
  updatePositions(positionMap: Record<string, Node>): void;
26
26
  /**
27
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
28
+ * @param id1 - The first ID.
29
+ * @param id2 - The second ID.
30
+ * @returns A unique ID for the pair of IDs.
31
31
  */
32
32
  private generatePairId;
33
33
  }
@@ -0,0 +1,148 @@
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 the padding for selected relationships based on border style
49
+ * @param selectedBorderRings - Array of border rings for selected state
50
+ * @returns The total selection padding
51
+ */
52
+ export declare const getSelectionPadding: (selectedBorderRings?: BorderStyle["rings"]) => number;
53
+ /**
54
+ * Calculates the position and angle for a relationship label based on the Canvas renderer's logic.
55
+ * This handles both straight lines and curves, with special logic for odd/even number of points.
56
+ *
57
+ * @param points - Array of points defining the relationship line
58
+ * @param fromNode - The source node
59
+ * @param toNode - The target node
60
+ * @param drawCurves - Whether curves are being drawn
61
+ * @param isSelected - Whether the relationship is selected
62
+ * @param captionAlign - Caption alignment ('top' or 'bottom')
63
+ * @param selectedBorderRings - Array of border rings for selected state
64
+ * @returns Object containing x, y position and angle for the label
65
+ */
66
+ export declare const getRelationshipLabelPosition: (points: Point[], fromNode: Node, toNode: Node, drawCurves: boolean, isSelected: boolean, selectedBorderRings: BorderStyle["rings"], captionAlign?: "top" | "bottom") => {
67
+ x: number;
68
+ y: number;
69
+ angle: number;
70
+ };
71
+ /**
72
+ * This function calculates the coordinates of the via point
73
+ * between two nodes. The via point is used to bend the edge
74
+ * between the two nodes.
75
+ * @param fromNode - The node the edge starts from.
76
+ * @param toNode - The node the edge ends at.
77
+ * @param fromArrowGap - The gap between the node and the arrow on the from side.
78
+ * @param toArrowGap - The gap between the node and the arrow on the to side.
79
+ * @returns The coordinates of the via point.
80
+ */
81
+ export declare const getViaCoordinates: (fromNode: Node, toNode: Node, fromArrowGap: number, toArrowGap: number, rel: Relationship, bundle: ArrowBundle) => Point;
82
+ export declare const getPointsForStraight: (rel: Relationship, bundle: ArrowBundle, fromNode: Node, toNode: Node, showLabel: boolean, curved?: boolean) => Point[];
83
+ export declare const distanceToEdge: (pos: Point, rel: Relationship, fromNode: Node, toNode: Node, bundle: ArrowBundle, showLabel: boolean, drawCurves?: boolean) => number;
84
+ /**
85
+ * Returns the bounding box of the arrow.
86
+ * @param rel - The relationship to get the bounding box for.
87
+ * @param bundle - The arrow bundle the relationship is part of.
88
+ * @param fromNode - The node the relationship is coming from.
89
+ * @param toNode - The node the relationship is going to.
90
+ * @param showLabel - Whether or not a label is shown.
91
+ * @param drawCurves - Whether or the relationship is drawn as a curve.
92
+ * @returns The bounding box of the arrow.
93
+ */
94
+ export declare const getBoundingBox: (rel: Relationship, bundle: ArrowBundle, fromNode: Node, toNode: Node, showLabel?: boolean, drawCurves?: boolean) => DOMRect | null;
95
+ /**
96
+ * Calculates the width of a relationship including selection factor and pixel ratio
97
+ * @param rel - The relationship
98
+ * @param defaultWidth - The default relationship width
99
+ * @returns The calculated relationship width
100
+ */
101
+ export declare const getRelationshipWidth: (rel: Relationship, defaultWidth: number) => number;
102
+ /**
103
+ * Adjusts relationship line points to create proper gaps at start and end.
104
+ * The Canvas renderer uses this logic:
105
+ * - End gap (arrowhead): headHeight/2 + headSelectedAdjustment
106
+ * - Start gap (tail): Only for selected relationships, uses getSelectionPadding
107
+ *
108
+ * @param points - Array of points defining the relationship line (will be modified in place)
109
+ * @param isSelected - Whether the relationship is selected
110
+ * @param headHeight - The height of the arrowhead
111
+ * @param headSelectedAdjustment - Additional adjustment for selected relationships
112
+ * @param selectedBorderRings - Array of border rings for selected state
113
+ * @returns Object with adjusted points and the tail offset applied (for label positioning)
114
+ */
115
+ export declare const adjustPointsForGaps: (points: Point[], isSelected: boolean, headHeight: number, headSelectedAdjustment: number, selectedBorderRings: BorderStyle["rings"]) => {
116
+ tailOffset: Point | null;
117
+ };
118
+ /**
119
+ * Calculates the dimensions of an arrowhead
120
+ * @param relWidth - The width of the relationship line
121
+ * @param defaultRelWidth - The default relationship width
122
+ * @param isSelected - Whether the relationship is selected
123
+ * @param selectedBorderRings - Array of border rings for selected state
124
+ * @returns Object containing headHeight, headChinHeight, headWidth, and headSelectedAdjustment
125
+ */
126
+ export declare const getArrowheadDimensions: (relWidth: number, defaultRelWidth: number, isSelected: boolean, selectedBorderRings: BorderStyle["rings"]) => {
127
+ headHeight: number;
128
+ headChinHeight: number;
129
+ headWidth: number;
130
+ headSelectedAdjustment: number;
131
+ };
132
+ /**
133
+ * Calculates the size of an overlay icon on a relationship
134
+ * @param iconSizeFactor - The size factor from the overlay icon configuration
135
+ * @returns The calculated overlay icon size
136
+ */
137
+ export declare const getOverlayIconSize: (iconSizeFactor: number) => number;
138
+ /**
139
+ * Calculates the alignment offsets for an overlay icon on a relationship
140
+ * @param position - The position array [x, y] from overlay icon configuration
141
+ * @param width - The available width for the icon
142
+ * @param height - The height of the icon
143
+ * @returns Object with widthAlign and heightAlign offsets
144
+ */
145
+ export declare const getOverlayIconAlignment: (position: [number, number], width: number, height: number) => {
146
+ widthAlign: number;
147
+ heightAlign: number;
148
+ };
@@ -0,0 +1,28 @@
1
+ import type { Node } from '../../../../types/graph-element';
2
+ /**
3
+ * Returns the caption font size that should be used
4
+ * for the given info level and node diameter.
5
+ * @param infoLevel {number} - The info level.
6
+ * @param nodeRadius {number} - The radius of the node.
7
+ * @param captionSize {number} - The size of the caption.
8
+ * @returns {number} - The font size.
9
+ */
10
+ export declare const infoLevelToFontSize: (infoLevel: number, nodeRadius?: number, captionSize?: number, hasIcon?: boolean) => number;
11
+ /**
12
+ * Prepares node caption data for rendering (works for both Canvas and SVG)
13
+ * @param node - The node to prepare caption data for
14
+ * @param zoomLevel - Current zoom level
15
+ * @param ctx - Canvas context for text measurement (optional for SVG, will create one if not provided)
16
+ * @returns Caption rendering data including lines, styles, positioning, and font info
17
+ */
18
+ export declare function prepareNodeCaptionData(node: Node, zoomLevel: number, ctx?: CanvasRenderingContext2D): {
19
+ lines: any[];
20
+ stylesPerChar: string[][];
21
+ fullCaption: string;
22
+ fontSize: number;
23
+ fontFace: string;
24
+ fontColor: string;
25
+ yPos: number;
26
+ maxNoLines: number;
27
+ hasContent: boolean;
28
+ };
@@ -0,0 +1,58 @@
1
+ import type { Node } from '../../../../types/graph-element';
2
+ /**
3
+ * Returns the bounding box of a node with the given x, y, and size properties.
4
+ * If no size is given, the default size is used.
5
+ * @param Node - The node to get the bounding box for.
6
+ * @returns The bounding box of the node.
7
+ */
8
+ export declare const getBoundingBox: ({ x, y, size }: Node) => DOMRect;
9
+ /**
10
+ * Calculates the size of a node icon based on node properties
11
+ * @param mainFaceRadius - The radius of the node's main face (already adjusted for pixel ratio)
12
+ * @param hasCaption - Whether the node has a caption
13
+ * @param iconInfoLevel - The icon info level (determines size scaling)
14
+ * @param nodeInfoLevel - The node info level (determines whether icon should show with text)
15
+ * @returns The calculated icon size
16
+ */
17
+ export declare const getNodeIconSize: (mainFaceRadius: number, hasCaption: boolean, iconInfoLevel: number, nodeInfoLevel: number) => number;
18
+ /**
19
+ * Calculates the position of a node icon
20
+ * @param iconSize - The size of the icon
21
+ * @param hasCaption - Whether the node has a caption
22
+ * @param captionAlign - The caption alignment ('center', 'bottom', or 'top')
23
+ * @param iconInfoLevel - The icon info level
24
+ * @param nodeInfoLevel - The node info level
25
+ * @returns Object with iconXPos and iconYPos
26
+ */
27
+ export declare const getNodeIconPosition: (iconSize: number, hasCaption: boolean, captionAlign: string, iconInfoLevel: number, nodeInfoLevel: number) => {
28
+ iconXPos: number;
29
+ iconYPos: number;
30
+ };
31
+ /**
32
+ * Calculates the size of a node overlay icon
33
+ * @param mainFaceDiameter - The diameter of the node's main face (already adjusted for pixel ratio)
34
+ * @param overlayIconSizeFactor - The size factor from the overlay icon configuration
35
+ * @returns The calculated overlay icon size
36
+ */
37
+ export declare const getNodeOverlayIconSize: (mainFaceDiameter: number, overlayIconSizeFactor: number) => number;
38
+ /**
39
+ * Calculates the position of a node overlay icon
40
+ * @param iconSize - The size of the overlay icon
41
+ * @param mainFaceRadius - The radius of the node's main face
42
+ * @param position - The position array [x, y] from overlay icon configuration
43
+ * @returns Object with iconXPos and iconYPos
44
+ */
45
+ export declare const getNodeOverlayIconPosition: (iconSize: number, mainFaceRadius: number, position: [number, number]) => {
46
+ iconXPos: number;
47
+ iconYPos: number;
48
+ };
49
+ /**
50
+ * Calculates the rendered radius of a node including pixel ratio
51
+ * @param node - The node object with optional size property
52
+ * @param pixelRatio - Device pixel ratio
53
+ * @param defaultNodeSize - Default size to use if node.size is undefined
54
+ * @returns The radius in pixels
55
+ */
56
+ export declare const getNodeRadius: (node: {
57
+ size?: number;
58
+ }, pixelRatio: number, defaultNodeSize: number) => number;
@@ -1,5 +1,5 @@
1
- import type { Node, Relationship } from '../../types/graph-element';
2
- import type { Point } from '../../utils/geometry';
1
+ import type { Node, Relationship } from '../../../types/graph-element';
2
+ import type { Point } from '../../../utils/geometry';
3
3
  export type TextSegment = {
4
4
  hasEllipsisChar?: boolean;
5
5
  hasHyphenChar?: boolean;
@@ -8,14 +8,16 @@ export type TextSegment = {
8
8
  };
9
9
  /**
10
10
  * The caption text and its text style.
11
- * @property styles - The font styles as comma separated values
12
- * @example 'bold,italic'
13
- * @property value - The text for the caption.
14
- * @property key - The caption identifier key.
15
11
  */
16
12
  export type StyledCaption = {
13
+ /**
14
+ * The font styles as an array of style keywords.
15
+ * @example `['bold', 'italic']`
16
+ */
17
17
  styles?: string[];
18
+ /** The text value for the caption. */
18
19
  value?: string;
20
+ /** The identifier key for the caption. */
19
21
  key?: string;
20
22
  };
21
23
  export type StyledCaptionWithChars = StyledCaption & {
@@ -0,0 +1,11 @@
1
+ export declare const fontThresholds: [number, number][];
2
+ /**
3
+ * This function takes color in hex format or rgb() or rgba() format and overrides the opacity. Returns rgba() string.
4
+ * @param color - * @param opacity - * @returns rgba() string with the given opacity.
5
+ */
6
+ export declare const overrideOpacity: (color: string, opacity: number) => string;
7
+ export declare function getIndividualInfoLevels(r: number, zoomLevel: number): {
8
+ nodeInfoLevel: number;
9
+ fontInfoLevel: number;
10
+ iconInfoLevel: number;
11
+ };
@@ -1,4 +1,4 @@
1
- import type { Point } from '../../utils/geometry';
1
+ import type { Point } from '../../../utils/geometry';
2
2
  export declare const add: (v1: Point, v2: Point) => {
3
3
  x: number;
4
4
  y: number;