Skip to content
D
Documentation

Layout — interfaces l–t

reference
10 min readUpdated

Interfaces L–T

Import these from @grafloria/engine.

Interfaces

LayoutRun

An in-flight, pre-emptible layout computation.

Pure and synchronous by construction: no DOM, no clock, no Math.random().

ts
interface LayoutRun

Properties

NameTypeDefaultDescription
iterationnumberIterations completed so far.
totalIterationsnumberIterations this run would do if left alone — the denominator for progress.

Members

  • step(): boolean — Advance exactly one iteration.
  • snapshot(): LayoutResult — The best answer so far. Must be safe to call at ANY point — before the first step (returns the input positions), midway (returns the partial simulation), or after the last (returns the final layout).

LayoutRunOptions

Caller-side options that must NEVER cross the wire (they are not clonable).

ts
interface LayoutRunOptions

Properties

NameTypeDefaultDescription
signal?AbortSignalCancel the run. Cooperative: takes effect within one slice.
onProgress?(progress: LayoutProgress) => voidStreaming progress. Called on the caller's thread.
timeBudgetMs?numberGive up after this long and return the best-so-far, flagged partial.
sliceMs?numberCompute-between-yields, ms. Lower = promper cancellation, more overhead.
stopAfterIteration?numberDeterministic pre-emption after N iterations. See LayoutRequestRun.

LayoutSelectionReport

What the auto-selector chose, and WHY. Returned on the layout result, so the reasoning is available to a UI, a log line or a test — never hidden.

ts
interface LayoutSelectionReport

Properties

NameTypeDefaultDescription
chosenstringThe candidate that won (its id, e.g. 'elk:layered
').
algorithmstringThe registered algorithm behind it.
reasonstringOne sentence a human can read.
shapeGraphShapeWhat we worked out about the graph before choosing.
candidatesCandidateScore[]Every candidate, scored, best first. Losers included on purpose.

LayoutServePort

The port surface the SERVER side needs — a worker's self satisfies it.

ts
interface LayoutServePort

Properties

NameTypeDefaultDescription
onmessage((ev: { data: LayoutRequest }) => void) | null

Members

  • postMessage(msg: LayoutResponse): void

LayoutSnapshot

Snapshot of node positions at a point in time

ts
interface LayoutSnapshot

Properties

NameTypeDefaultDescription
idstringUnique identifier for this snapshot
timestampnumberTimestamp when snapshot was created
positionsMap<string, { x: number; y: number }>Node positions
description?stringOptional description
algorithm?stringLayout algorithm used
options?anyLayout options used

NodeConstraint

Constraint definition for a single node

ts
interface NodeConstraint

Properties

NameTypeDefaultDescription
nodeIdstringID of the node this constraint applies to
typeConstraintTypeType of constraint
position?PositionFixed position for 'pin' constraint The node will be locked to this exact position
value?numberFixed value for 'fix-x' or 'fix-y' constraints - For 'fix-x': The X coordinate is locked to this value, Y can vary - For 'fix-y': The Y coordinate is locked to this value, X can vary
boundary?BoundaryBoundary limits for 'boundary' constraint The node position will be clamped within these bounds
priority?numberPriority of this constraint (higher = more important) Used when constraints conflict (default: 0)

OverlapRemovalOptions

ts
interface OverlapRemovalOptions

Properties

NameTypeDefaultDescription
spacing?numberGap to open up between two boxes that were overlapping.

PackBox

A box to pack, plus the id used to break ties deterministically.

ts
interface PackBox

Properties

NameTypeDefaultDescription
idstring
widthnumber
heightnumber

PackingOptions

ts
interface PackingOptions

Properties

NameTypeDefaultDescription
spacing?numberGap between packed components. Defaults to the layout's nodeSpacing.
aspectRatio?numberTarget width/height of the packed result. 1.6 ≈ a landscape screen.

PlacementOptions

Options for calculating node placement

ts
interface PlacementOptions

Properties

NameTypeDefaultDescription
nodeNodeModelThe node to place
viewportRectangleCurrent viewport dimensions
existingNodesNodeModel[]Existing nodes in the diagram
preferredPosition?PointPreferred position (optional hint)
respectManualPositions?booleanWhether to respect manual positions of existing nodes
spacing?numberSpacing between nodes
padding?numberPadding from viewport edges

PlacementResult

Result of placement calculation

ts
interface PlacementResult

Properties

NameTypeDefaultDescription
positionPointCalculated position for the node
successbooleanWhether placement was successful
metadata?{ /** * Grid position (for grid layouts) */ gridPosition?: { row: number; column: number }; /** * Pattern detected (for hybrid layouts) */ detectedPattern?: 'grid' | 'tree' | 'freeform'; /** * Reason for placement choice */ reason?: string; /** * Number of attempts made (for iterative placement) */ attempt?: number; /** * Allow additional metadata properties */ [key: string]: any; }Metadata about the placement decision

Point2D

Point in 2D space

ts
interface Point2D

Properties

NameTypeDefaultDescription
xnumber
ynumber

PortAwareLayoutOptions

Configuration for port-aware layout

ts
interface PortAwareLayoutOptions

Properties

NameTypeDefaultDescription
enabledbooleanEnable port-aware layout
ports?PortInfo[]Port information for all ports in the diagram
autoAssignSides?booleanAutomatic port side assignment based on node connections
autoOrderPorts?booleanAutomatic port ordering to minimize crossings
inputSide?PortSidePrefer inputs on specific side
outputSide?PortSidePrefer outputs on specific side
portSpacing?numberMinimum spacing between ports (in pixels)
usePortPositions?booleanWhether to consider port positions in edge routing
orderingStrategy?'minimize-crossings' | 'connection-based' | 'group-based' | 'manual'Strategy for port ordering
nodeSidePreferences?{ [nodeId: string]: { inputs?: PortSide; outputs?: PortSide; }; }Node-specific port side preferences
portOrdering?{ [nodeId: string]: string[]; // Ordered list of port IDs for this node }Per-port ordering constraints

PortAwareLayoutResult

Result of port-aware layout computation

ts
interface PortAwareLayoutResult

Properties

NameTypeDefaultDescription
portAssignmentsMap<string, PortSide>Final port assignments (port ID -> side)
portOrderingMap<string, string[]>Final port ordering (node ID -> ordered port IDs)
portPositionsMap<string, { x: number; y: number; side: PortSide }>Calculated port positions (port ID -> {x, y} relative to node)
edgeCrossingsnumberNumber of edge crossings
wasOptimizedbooleanWhether port positions were optimized
autoAssignedPortsstring[]Ports that were automatically assigned sides
autoOrderedPortsstring[]Ports that were automatically ordered

PortInfo

Information about a port for layout purposes

ts
interface PortInfo

Properties

NameTypeDefaultDescription
idstringPort unique identifier
nodeIdstringNode this port belongs to
preferredSide?PortSidePreferred side of the node
direction?PortFlowDirectionPort direction
offset?numberPosition along the side (0-1, where 0 is top/left, 1 is bottom/right)
fixed?booleanFixed position (prevents automatic ordering)
priority?numberPriority for ordering (higher = more important)
group?stringGroup identifier for related ports

PortRespectResult

ts
interface PortRespectResult

Properties

NameTypeDefaultDescription
violationsnumberLinks whose endpoint travels AGAINST the side its port faces.
judgednumberLinks that could be judged (both ends resolvable, both nodes placed).
scorenumber100 = every port-constrained edge leaves in the direction its port faces.
violatingLinksstring[]Which links violated, for the report.

Position

Position definition for pinned nodes

ts
interface Position

Properties

NameTypeDefaultDescription
xnumber
ynumber

QualityAssessmentOptions

Options for quality assessment

ts
interface QualityAssessmentOptions

Properties

NameTypeDefaultDescription
includeSuggestions?booleanWhether to include detailed suggestions
customWeights?{ edgeCrossings?: number; nodeOverlap?: number; edgeLength?: number; nodeDistribution?: number; symmetry?: number; aspectRatio?: number; }Custom metric weights (overrides defaults)
canvasDimensions?{ width: number; height: number; }Canvas dimensions for aspect ratio calculation

QualityMetric

Individual quality metric

ts
interface QualityMetric

Properties

NameTypeDefaultDescription
namestringMetric name
scorenumberScore (0-100, higher is better)
weightnumberWeight of this metric in overall score
descriptionstringDescription of what this measures
suggestions?string[]Suggestions for improvement

RadialLayoutOptions

Also has every member of UnifiedLayoutOptions, LayoutOptions, LayoutRunOptions, listed on their own entries.

ts
interface RadialLayoutOptions extends UnifiedLayoutOptions

Properties

NameTypeDefaultDescription
rootId?stringCentre of the rings. Defaults to a source node, else the hub. See pickRoot.

RegisteredLayout

What a registered layout engine must be able to do.

ts
interface RegisteredLayout

Properties

NameTypeDefaultDescription
namestring
adapter?LayoutAdapterThe underlying node/link algorithm, when the engine has one.
handlesContainers?booleanThe layout arranges CONTAINERS itself — zones are part of its composition (the architecture layout puts regions on a grid and sizes their frames), so engine.layout() must not hand it to the nested-container path, which lays out one container at a time with some other engine.

Members

  • apply(diagram: DiagramModel, options: UnifiedLayoutOptions): Promise<LayoutResult>

ScalePlan

A structural engine choice made without running a bake-off.

ts
interface ScalePlan

Properties

NameTypeDefaultDescription
candidatesLayoutCandidate[]Candidates to try, best-first; the first that runs wins.
whystringThe structural fact the pick rests on — goes into the report verbatim.

ServeLayoutDeps

ts
interface ServeLayoutDeps

Properties

NameTypeDefaultDescription
resolve?(name: string) => LayoutAdapter | undefinedName → algorithm. Injected, because the INLINE host resolves against the engine's live registry (so a host-registered custom layout still works), while a real worker resolves against whatever its own bundle registered — a function cannot be posted across a thread boundary, so an extension layout registered at runtime is inline-only, by physics rather than choice.
now?() => numberThe clock. Injected so tests can stop it lying.

SpectralLayoutOptions

Also has every member of LayoutOptions, listed on its own entry.

Spectral layout options

ts
interface SpectralLayoutOptions extends LayoutOptions

Properties

NameTypeDefaultDescription
normalized?booleanUse normalized Laplacian (default: true)
dimensions?numberNumber of dimensions to compute (default: 2)
scale?numberScale factor for positions (default: 500)
center?booleanCenter the layout (default: true)
convergenceThreshold?numberPower iteration convergence threshold (default: 1e-6)
maxIterations?numberMaximum power iterations (default: 1000)

SteppableLayoutAdapter

Also has every member of LayoutAdapter, listed on its own entry.

A layout adapter that can be driven a step at a time.

Optional: isSteppable() is a type guard, and the host degrades gracefully for adapters that are not.

ts
interface SteppableLayoutAdapter extends LayoutAdapter

Members

  • createRun( nodes: NodeModel[], links: LinkModel[], options?: Partial<LayoutOptions> ): LayoutRun

SubgraphLayoutOptions

Configuration for subgraph layout

ts
interface SubgraphLayoutOptions

Properties

NameTypeDefaultDescription
enabledbooleanEnable subgraph/group layout
groups?GroupInfo[]Group information for all groups in the diagram
targetGroups?string[]Specific group IDs to layout (if undefined, layout all)
recursive?booleanWhether to recursively layout nested groups
defaultPadding?numberDefault padding for groups without explicit padding
boundaryHandling?'strict' | 'flexible' | 'none'How to handle group boundaries
layoutTopLevel?booleanWhether to layout the top-level (non-grouped) nodes
groupPositioning?'compact' | 'spacious' | 'grid' | 'manual'Strategy for positioning groups relative to each other
groupSpacing?numberSpacing between groups
autoResize?booleanWhether to automatically resize groups to fit content
maintainAspectRatio?booleanWhether to maintain aspect ratio when resizing groups
interGroupLinks?'route-around' | 'direct' | 'hidden'How to handle links between groups

SubgraphLayoutResult

Result of subgraph layout computation

ts
interface SubgraphLayoutResult

Properties

NameTypeDefaultDescription
nodePositionsMap<string, { x: number; y: number; groupId?: string }>Node positions within their groups (node ID -> position)
groupPositionsMap<string, { x: number; y: number }>Group positions (group ID -> position)
groupSizesMap<string, { width: number; height: number }>Computed group sizes (group ID -> size)
laidOutGroupsstring[]Groups that were laid out
skippedGroupsstring[]Groups that were skipped (fixed, collapsed, etc.)
bounds{ x: number; y: number; width: number; height: number }Overall bounds
wasRecursivebooleanWhether groups were recursively laid out

TreeLayoutOptions

Also has every member of UnifiedLayoutOptions, LayoutOptions, LayoutRunOptions, listed on their own entries.

ts
interface TreeLayoutOptions extends UnifiedLayoutOptions

Properties

NameTypeDefaultDescription
rootId?stringRoot of the tree. Defaults to a source node (in-degree 0), else the hub.
branchDirections?Record<string, FlowDirection>Per-branch direction: the subtree rooted at this node flows this way instead of the tree's direction. A mind map is { 'child-a': 'LR', 'child-b': 'RL' }.

Was this page helpful?

Layout — interfaces l–t — Grafloria