/** * Utility types for sugiyama layout * * This module should only really matter for those looking to develop custom * {@link Coord}s or {@link Decross}s. * * @packageDocumentation */ import { type Graph, type GraphLink, type GraphNode, type MutGraphNode } from "../graph"; import type { NodeLength } from "../layout"; import { type Named } from "../utils"; import type { Separation } from "./utils"; /** data for a sugi node that maps to a real node */ export interface SugiNodeDatum { /** tag indicating that this sugi node is backed by a graph node */ role: "node"; /** top layer of the sugi node */ topLayer: number; /** bottom layer of the sugi node */ bottomLayer: number; /** original node this sugi node wraps */ node: GraphNode; } /** data for a dummy sugi node that maps to part of a link */ export interface SugiLinkDatum { /** tag indicating that this sugi node is backed by a link */ role: "link"; /** layer of the sugi node */ layer: number; /** original link this sugi node is on */ link: GraphLink; } /** * the NodeDatum used for layered {@link sugiyama} layouts * * Nodes in the original graph have a layer and a reference to the original * node. "dummy nodes" have a link to the parent and child of the edge their on * in the original dag, as well as their actual layer. Given that duplicate * edges aren't allowed, this uniquely defines each dummy node. */ export type SugiDatum = SugiNodeDatum | SugiLinkDatum; /** * a {@link GraphNode} with {@link SugiDatum | SugiData} */ export type SugiNode = GraphNode, undefined>; /** * a {@link MutGraphNode} with {@link SugiDatum | SugiData} */ export type MutSugiNode = MutGraphNode, undefined>; /** * convert a layered graph in a sugi graph * * A sugi-graph is a non-multi dag that is layered, where each node is assigned * to a layer, and links only span a single layer. */ export declare function sugifyLayer(input: Graph, nodeHeight: NodeLength, gap: number, numLayers: number, layering: Named): readonly [SugiNode[][], number]; /** * Convert a layered graph in a sugi graph * * A sugi-graph is a non-multi dag that is layered, where each node is assigned * to a layer, and links only span a single layer. */ export declare function sugifyCompact(input: Graph, nodeHeight: NodeLength, height: number, layering: Named): SugiNode[][]; /** * Unsugify a sugi graph * * Given a sugi graph where each sugi node has an assigned x and y coordinate, * convert those back into coordinates on the underlying nodes, or point arrays * on the edges. */ export declare function unsugify(layers: SugiNode[][]): void; /** An accessor for computing the length of a sugi node */ export type SugiNodeLength = NodeLength, undefined>; /** * A function that defines the horizontal separation between nodes * * The separation function takes a left and right node, and returns how far * apart their centers should be. */ export type SugiSeparation = Separation, undefined>; /** * Convert a node length into a sugi node length * * @param len - the original node length * @param dummy - the length of dummy nodes */ export declare function sugiNodeLength(len: NodeLength, dummy?: number): SugiNodeLength; /** validate accurate coordinate assignment */ export declare function validateCoord(layers: SugiNode[][], xSep: SugiSeparation, width: number, coord: Named, tol?: number): void;