UNPKG

d3-dag

Version:

Layout algorithms for visualizing directed acylic graphs.

90 lines (89 loc) 3.98 kB
/** * 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 { Graph, GraphLink, GraphNode, MutGraphNode } from "../graph"; import { NodeLength } from "../layout"; import { Named } from "../utils"; import { Separation } from "./utils"; /** data for a sugi node that maps to a real node */ export interface SugiNodeDatum<out NodeDatum = unknown, out LinkDatum = unknown> { /** 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<NodeDatum, LinkDatum>; } /** data for a dummy sugi node that maps to part of a link */ export interface SugiLinkDatum<out NodeDatum = unknown, out LinkDatum = unknown> { /** 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<NodeDatum, LinkDatum>; } /** * 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<NodeDatum = unknown, LinkDatum = unknown> = SugiNodeDatum<NodeDatum, LinkDatum> | SugiLinkDatum<NodeDatum, LinkDatum>; /** * a {@link GraphNode} with {@link SugiDatum | SugiData} */ export type SugiNode<NodeDatum = unknown, LinkDatum = unknown> = GraphNode<SugiDatum<NodeDatum, LinkDatum>, undefined>; /** * a {@link MutGraphNode} with {@link SugiDatum | SugiData} */ export type MutSugiNode<NodeDatum, LinkDatum> = MutGraphNode<SugiDatum<NodeDatum, LinkDatum>, 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<N, L>(input: Graph<N, L>, nodeHeight: NodeLength<N, L>, gap: number, numLayers: number, layering: Named): readonly [SugiNode<N, L>[][], 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<N, L>(input: Graph<N, L>, nodeHeight: NodeLength<N, L>, height: number, layering: Named): SugiNode<N, L>[][]; /** * 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<N, L>(layers: SugiNode<N, L>[][]): void; /** An accessor for computing the length of a sugi node */ export type SugiNodeLength<NodeDatum = never, LinkDatum = never> = NodeLength<SugiDatum<NodeDatum, LinkDatum>, 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<NodeDatum = never, LinkDatum = never> = Separation<SugiDatum<NodeDatum, LinkDatum>, 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<N, L>(len: NodeLength<N, L>, dummy?: number): SugiNodeLength<N, L>; /** validate accurate coordinate assignment */ export declare function validateCoord<N, L>(layers: SugiNode<N, L>[][], xSep: SugiSeparation<N, L>, width: number, coord: Named, tol?: number): void;