import { IGraphEdge, IGraphNode, IPoint } from './graph'; /** * Graph layout engines. * * A layout is a pure function from a graph to repositioned nodes. It never * mutates, never renders, and knows nothing about React — which makes each one * testable in isolation and lets an application supply its own. * * ```ts * const positioned = layeredLayout({ direction: 'right' })(nodes, edges); * ``` * * See {@link useGraphLayout} for applying one to a live graph, including the * freeform mode that lets a hand-placed node escape the engine. */ /** Repositions a graph. Must be pure: same input, same output, no mutation. */ export type GraphLayout = (nodes: IGraphNode[], edges: IGraphEdge[]) => IGraphNode[]; /** Which way a layered layout flows. */ export type LayoutDirection = 'down' | 'up' | 'right' | 'left'; export interface LayeredLayoutOptions { /** Flow direction. Defaults to `"down"`. */ direction?: LayoutDirection; /** Gap between siblings within a layer, in graph units. Defaults to `48`. */ nodeSpacing?: number; /** Gap between layers, in graph units. Defaults to `96`. */ layerSpacing?: number; /** Top-left of the laid-out block. Defaults to the origin. */ origin?: IPoint; /** * How siblings line up across a layer. `center` reads best for trees; * `start` keeps a ragged left edge, which suits deep hierarchies. * Defaults to `"center"`. */ align?: 'center' | 'start'; } /** * A layered (Sugiyama-style) tree layout. * * Nodes are grouped into layers by graph depth, then spread along the * cross-axis within each layer. Real node sizes are used, so mixed-size nodes * don't overlap — a fixed step would. * * Handles cycles and disconnected components without dropping nodes. * * @example * ```ts * const layout = layeredLayout({ direction: 'right', layerSpacing: 140 }); * setNodes(layout(nodes, edges)); * ``` */ export declare const layeredLayout: ({ direction, nodeSpacing, layerSpacing, origin, align, }?: LayeredLayoutOptions) => GraphLayout; export interface GridLayoutOptions { /** * Number of columns. Defaults to a square-ish grid, which keeps a large * unstructured set roughly as wide as it is tall. */ columns?: number; /** Horizontal gap between cells. Defaults to `48`. */ spacingX?: number; /** Vertical gap between cells. Defaults to `48`. */ spacingY?: number; /** Top-left of the grid. Defaults to the origin. */ origin?: IPoint; } /** * A uniform grid, ignoring edges entirely. * * Useful for a set with no meaningful hierarchy, or as a reset before hand * arranging. Column widths and row heights come from the largest node in each, * so mixed sizes stay aligned. * * @example * ```ts * setNodes(gridLayout({ columns: 4 })(nodes, edges)); * ``` */ export declare const gridLayout: ({ columns, spacingX, spacingY, origin, }?: GridLayoutOptions) => GraphLayout; /** * The layouts bundled with the library, ready to pass to * {@link useGraphLayout}. * * Spread it and add your own, or ignore it and supply a different set — * `useGraphLayout` takes any `Record`. */ export declare const BUILT_IN_LAYOUTS: Record;