d3-dag
Version:
Layout algorithms for visualizing directed acylic graphs.
92 lines (91 loc) • 3.64 kB
TypeScript
/**
* The {@link CoordSimplex} positions nodes to maximize line straightness.
* This is adapted from methods used for dot layout.
*
* @packageDocumentation
*/
import { Coord } from ".";
import { GraphLink } from "../../graph";
/**
* a strictly callable {@link SimplexWeight}
*/
export interface CallableSimplexWeight<NodeDatum = never, LinkDatum = never> {
/**
* get the simplex weights for a link
*
* Higher weights indicate a strong preference for verticality.
*
* @param link - the link in question
* @returns weights - the weights for short, medium, and long edges respectively
*/
(link: GraphLink<NodeDatum, LinkDatum>): readonly [number, number, number];
}
/**
* an accessor to get how vertical a weight should be.
*
* A weight accessor returns three postitive numbers, where higher numbers
* indicate than edge should be more vertical. The first number corresponds to
* short edges, the second to medium edges, and the last one to the middle of
* long edges. These numbers should generally be increasing.
*/
export type SimplexWeight<NodeDatum = never, LinkDatum = never> = readonly [number, number, number] | CallableSimplexWeight<NodeDatum, LinkDatum>;
/** the operators of the simplex operator */
export interface CoordSimplexOps<N = never, L = never> {
/** the weights for each edge */
weight: SimplexWeight<N, L>;
}
/** node datum for operators */
export type OpNodeDatum<O extends CoordSimplexOps> = O extends CoordSimplexOps<infer N, never> ? N : never;
/** link datum for operators */
export type OpLinkDatum<O extends CoordSimplexOps> = O extends CoordSimplexOps<never, infer L> ? L : never;
/**
* a {@link Coord} that places nodes to maximize edge verticality
*
* The minimization mirrors that of Gansner, Emden R., et al. "A technique for
* drawing directed graphs." IEEE Transactions on Software Engineering (1993).
* This tries to make nodes close together, assigning greater weight for nodes
* as part of an edge.
*
* Create with {@link coordSimplex}.
*/
export interface CoordSimplex<Ops extends CoordSimplexOps> extends Coord<OpNodeDatum<Ops>, OpLinkDatum<Ops>> {
/**
* set the weights for how vertical edges should be
*
* The higher the weight, the more vertical an edge should be. Weights are
* are triplets of numbers describing the weight for different parts of edge.
* The first is between true nodes, the second is for near true nodes, and
* the last is for the extents of long edges. Generally the number should be
* increasing, and all must be positive.
*
* (default: `[1, 2, 8]`)
*/
weight<NewWeight extends SimplexWeight>(val: NewWeight): CoordSimplex<{
/** new weight */
weight: NewWeight;
}>;
/** gets the current weight accessor */
weight(): Ops["weight"];
/** @internal flag indicating that this is built in to d3dag and shouldn't error in specific instances */
readonly d3dagBuiltin: true;
}
/** default simplex operator */
export type DefaultCoordSimplex = CoordSimplex<{
/** default weights taken from graphvis */
weight: readonly [1, 2, 8];
}>;
/**
* create a default {@link CoordSimplex}
*
* The simplex coordinate assignment operator tries to minimize edge length,
* while also trying to make long edges vertical. This uses an optimization
* that can take a long time, but is usually fast enough on moderately sized
* graphs.
*
* @example
*
* ```ts
* const layout = sugiyama().coord(coordSimplex().weight([2, 2, 4]));
* ```
*/
export declare function coordSimplex(...args: never[]): DefaultCoordSimplex;