Skip to content
D
Documentation

SnapController

reference
1 min readUpdated

Import it from @grafloria/renderer.

ts
class SnapController

Methods

  • constructor(config: Partial<SnapConfig> = {})
  • getConfig(): SnapConfig
  • updateConfig(patch: Partial<SnapConfig>): void
  • syncWithEngineConfig(engine: DiagramEngine): void — Read the snapping knobs off the engine's interaction config.
  • computeSnap(box: Rectangle, others: Rectangle[]): SnapResult — Snap box against others.
  • snapPointToGrid(point: Point): Point — Quantise a single point to the grid (used by the vertex drag).
  • keepInBounds(box: Rectangle, bounds: Rectangle): Rectangle — Clamp a box so it stays fully inside bounds (no-op when it cannot fit).
  • siblingBoxes(engine: DiagramEngine, excludeIds: Iterable<string> = []): Rectangle[] — World bounding boxes of every node EXCEPT excludeIds (the moving ones).
  • portPosition(node: NodeModel, port: PortModel): Point — World position of a port — THE one the port is actually drawn at.
  • findPortMagnet( engine: DiagramEngine, worldX: number, worldY: number, options: { excludeNodeId?: string; radius?: number; filter?: (port: PortModel, node: NodeModel) => boolean; } = {} ): PortHit | null — The nearest port to a world point within snapToPortRadius — the magnet the connection drag snaps to. excludeNodeId keeps a drag from snapping back to the node it started on.
  • findProximityConnection( engine: DiagramEngine, nodeId: string, radius?: number ): ProximityCandidate | null — React-Flow-style proximity connect: after dragging nodeId, is one of ITS ports close enough to a compatible port on another node to auto-link them?
  • buildProximityLinkCommand(candidate: ProximityCandidate): Command — Turn a candidate into the ONE undoable command that creates the link.
  • highlightProximityTarget(engine: DiagramEngine, candidate: ProximityCandidate | null): void — Paint the nearest valid target: exactly the flags the SVG renderer already draws for a connection drag (isValidTarget = eligible, isHighlighted = the one that would win). Clears every other port so the highlight can never go stale — the failure mode of "highlight on, nothing turns it off".

Was this page helpful?

SnapController — Grafloria