UNPKG

d3-dag

Version:

Layout algorithms for visualizing directed acylic graphs.

61 lines (60 loc) 2.23 kB
/** * A {@link LayeringTopological} that assigns each node a unique layer. * * @packageDocumentation */ import { Layering } from "."; import { Rank } from "../../graph"; import { U } from "../../utils"; /** topological operators */ export interface LayeringTopologicalOps<in N = never, in L = never> { /** rank operator */ rank: Rank<N, L>; } /** the node datum of a set of operators */ type OpsNodeDatum<Ops extends LayeringTopologicalOps> = Ops extends LayeringTopologicalOps<infer N, never> ? N : never; /** the link datum of a set of operators */ type OpsLinkDatum<Ops extends LayeringTopologicalOps> = Ops extends LayeringTopologicalOps<never, infer L> ? L : never; /** * a layering that assigns every node a distinct layer * * This combined with topological coordinate assignment can be thought of as an * alternative to {@link zherebko}. The latter generally produces more pleasing * layouts, but both are options. This layering is very fast, but it may make * other steps take longer due to the many created dummy nodes. * * Create with {@link layeringTopological}. */ export interface LayeringTopological<Ops extends LayeringTopologicalOps = LayeringTopologicalOps> extends Layering<OpsNodeDatum<Ops>, OpsLinkDatum<Ops>> { /** * set the {@link Rank} * * Nodes will first be in rank order, and then in topological order * attempting to minimize edge inversions. */ rank<NewRank extends Rank>(newRank: NewRank): LayeringTopological<U<Ops, "rank", NewRank>>; /** * get the current {@link Rank}. */ rank(): Ops["rank"]; /** @internal flag indicating that this is built in to d3dag and shouldn't error in specific instances */ readonly d3dagBuiltin: true; } /** default topological operator */ export type DefaultLayeringTopological = LayeringTopological<{ /** unconstrained rank */ rank: Rank<unknown, unknown>; }>; /** * create a default {@link LayeringTopological} * * This is a layering that assigns every node to a distinct layer. * * @example * * ```ts * const layout = sugiyama().layering(layeringTopological()); * ``` */ export declare function layeringTopological(...args: never[]): DefaultLayeringTopological; export {};