/** * A topological layout using {@link Zherebko}. * * @packageDocumentation */ import type { Graph, Rank } from "../graph"; import type { LayoutResult, NodeSize } from "../layout"; import type { Tweak } from "../tweaks"; import { type U } from "../utils"; /** all operators for the zherebko layout */ export interface ZherebkoOps { /** the operator for assigning nodes a rank */ rank: Rank; /** node size operator */ nodeSize: NodeSize; /** tweaks */ tweaks: readonly Tweak[]; } /** * a simple topological layout operator. * * This layout algorithm constructs a topological representation of the graph * meant for visualization. The algorithm is based off a PR by D. Zherebko. The * nodes are topologically ordered, and edges are then positioned into "lanes" * to the left and right of the nodes. * * Create with {@link zherebko}. */ export interface Zherebko { /** * layout the graph using the current operator */ (graph: Ops extends ZherebkoOps ? Graph : never): LayoutResult; /** * set the {@link Rank} operator for the topological ordering */ rank(val: NewRank): Zherebko>; /** get the current lane operator */ rank(): Ops["rank"]; /** * set the {@link Tweak}s to apply after layout */ tweaks(val: NewTweaks): Zherebko>; /** * get the current {@link Tweak}s. */ tweaks(): Ops["tweaks"]; /** * sets the {@link NodeSize} * * (default: `[1, 1]`) */ nodeSize(val: NewNodeSize): Zherebko>; /** get the current node size */ nodeSize(): Ops["nodeSize"]; /** * set the gap size between nodes * * (default: `[1, 1]`) */ gap(val: readonly [number, number]): Zherebko; /** get the current gap size */ gap(): readonly [number, number]; } /** the default zherebko operator */ export type DefaultZherebko = Zherebko<{ /** no specified ranks */ rank: Rank; /** default node size */ nodeSize: readonly [1, 1]; /** no tweaks */ tweaks: readonly []; }>; /** * create a new {@link Zherebko} with default settings * * This layout creates a simple topological layout. It doesn't support behavior * beyond the layout defaults of {@link Zherebko#rank}, * {@link Zherebko#nodeSize}, {@link Zherebko#gap}, and * {@link Zherebko#tweaks}. * * zherebko example * * @example * * ```ts * const graph: Graph = ... * const layout = zherebko(); * const { width, height } = layout(graph); * for (const node of graph.nodes()) { * console.log(node.x, node.y); * } * ``` * */ export declare function zherebko(...args: never[]): DefaultZherebko;