Import it from @grafloria/engine.
Also has every member of DiagramEntity, listed on its own entry.
tsclass LinkModel extends DiagramEntity
Properties
| Name | Type | Default | Description |
|---|---|---|---|
diagram? | DiagramModel | Back-reference to the owning diagram, set by DiagramModel.installLink, as on NodeModel. It is how a LinkModel mutator (waypoints, control points, labels, reconnection) sees the document's read-only lock. | |
sourcePortId | string | ||
targetPortId | string | ||
sourceNodeId? | string | ||
targetNodeId? | string | ||
pathType | 'direct' | 'orthogonal' | 'smooth' | 'bezier' | 'smooth' | |
router? | LinkRouterName | WHERE the line goes. When unset, derived from pathType — see {@link effectiveRouter}. Setting it does NOT touch pathType, so legacy consumers keep working; the explicit field simply wins. | |
connector? | LinkConnectorName | HOW the polyline is drawn. Unset = derived from pathType. | |
points | Point[] | [] | |
segments | PathSegment[] | [] | |
labels | LinkLabel[] | [] | |
state | 'default' | 'selected' | 'hovered' | 'highlighted' | 'default' | |
style | Partial<LinkStyle> | {} | |
data | Record<string, any> | {} | |
isSourceEndpointSelected | boolean | false | Whether source endpoint handle is selected Used for dragging endpoint to reconnect |
isTargetEndpointSelected | boolean | false | Whether target endpoint handle is selected Used for dragging endpoint to reconnect |
DEFAULT_CURVATURE (static) (not released yet) | 0.5 | The curve tightness of a smooth/bezier link. |
Methods
constructor( sourcePortId: string, targetPortId: string, pathType?: 'direct' | 'orthogonal' | 'smooth' | 'bezier' )isSelfLoop(): boolean— Is this link a SELF-LOOP, i.e. do both ends live on the same node?getNodePairKey(): string | null— The unordered node pair this link connects, as a stable key. UNORDERED on purpose: A→B and B→A are the same visual bundle and must fan out together, or a bidirectional pair would draw both links on the same centre line. Returns null when the owning nodes are unknown.setSourcePort(portId: string, nodeId?: string): void— Set source portsetTargetPort(portId: string, nodeId?: string): void— Set target portsetPathType(pathType: 'direct' | 'orthogonal' | 'smooth' | 'bezier'): void— Set path typesetRouter(router: LinkRouterName | undefined): void— Set the routing geometry explicitly. Clears the cached route the same way setPathType does — the old polyline belongs to the old router.setConnector(connector: LinkConnectorName | undefined): void— Set the polyline rendering explicitly. Pure re-render; the routed points are still valid, so the cache is NOT cleared.effectiveRouter(): LinkRouterName— The router actually in force: the explicit field, else derived from pathType exactly as the renderer always derived it (direct → straight, orthogonal → orthogonal, smooth/bezier → straight-with-curved-rendering).effectiveConnector(): LinkConnectorName— The connector actually in force: the explicit field, else implied by an explicitly axis-aligned ROUTER, else derived from pathType.setPoints(points: Point[]): void— Set points for custom pathaddPoint(point: Point, index?: number): void— Add point to pathremovePoint(index: number): Point | undefined— Remove point from pathgeneratePath( sourcePoint: Point, targetPoint: Point, sourceDirection?: 'left' | 'right' | 'top' | 'bottom', targetDirection?: 'left' | 'right' | 'top' | 'bottom' ): void— Generate path based on typegetCurvature(): numberaddLabel( label: Partial<LinkLabel> & { text: string } & ( | { position: number } | { slot: NonNullable<LinkLabel['slot']> } ) ): void— Add labelremoveLabel(labelId: string): LinkLabel | undefined— Remove label by IDremoveLabelAt(index: number): LinkLabel | undefined— Remove label by indexupdateLabel(index: number, updates: Partial<LinkLabel>): void— Update label by indexsetLabels(labels: LinkLabel[]): void— REPLACE the whole label collection — the writeaddLabel/updateLabelcannot express.override getLabel(): string | undefined— Overloaded label read.override getLabel(labelId: string): LinkLabel | undefined— Overloaded label read.override getLabel(labelId?: string): string | LinkLabel | undefined— Overloaded label read.setState(state: 'default' | 'selected' | 'hovered' | 'highlighted'): void— Set stateupdateStyle(style: Partial<LinkStyle>): void— Update stylereplaceStyle(style: Partial<LinkStyle>): void— REPLACE the whole style object — the writeupdateStylecannot express.setData(key: string, value: any): void— Set data propertygetData(key: string): any— Get data propertyreconnectSource(newPortId: string, newNodeId?: string): void— Reconnect source endpoint to new port Used for link reconnection workflowreconnectTarget(newPortId: string, newNodeId?: string): void— Reconnect target endpoint to new port Used for link reconnection workflowgetSourceEndpoint(): Point— Get source endpoint position Returns the first point in the path (source end)getTargetEndpoint(): Point— Get target endpoint position Returns the last point in the path (target end)selectSourceEndpoint(): void— Select source endpoint handleselectTargetEndpoint(): void— Select target endpoint handledeselectEndpoints(): void— Deselect all endpoint handleshasSelectedEndpoint(): boolean— Check if any endpoint is selectedgetPointAtPosition(t: number): Point | null— Get point at position along link (0-1)getTotalLength(): number— Get total path lengthgetLength(): number— Get path length (alias for getTotalLength for API consistency)getTangentAt(t: number): Point | null— Get tangent (direction vector) at position along path (0-1) Returns normalized direction vectorgetNormalAt(t: number): Point | null— Get normal (perpendicular vector) at position along path (0-1) Returns normalized perpendicular vector (90° counter-clockwise from tangent)getClosestPoint(point: Point): { point: Point; distance: number; t: number } | null— Get closest point on path to a given point Returns the closest point, distance, and normalized position (t)getAngleAt(t: number): number | null— Get angle at position along path (0-1) in degrees Useful for label rotationoverride serialize(): SerializedLink— Serialize to JSONstatic fromJSON(data: SerializedLink): LinkModel(static) — Deserialize from JSON
Was this page helpful?