d3-dag
    Preparing search index...

    Interface DagreGraph<GraphLabel, NodeLabel, EdgeLabel>

    dagre-compatible mutable graph backed by d3-dag

    Accessed as dagre.graphlib.Graph. Use with dagre.layout. Like dagre's Graph, it takes the graph, node and edge label types as parameters, so node returns the node label with x and y, and edge returns the edge label with points.

    import { dagre } from "d3-dag";

    const grf = new dagre.graphlib.Graph();
    grf.setGraph({});
    grf.setDefaultEdgeLabel(() => ({}));
    grf.setNode("a", { width: 40, height: 40 });
    grf.setNode("b", { width: 40, height: 40 });
    grf.setEdge("a", "b");
    dagre.layout(grf);
    const pos = grf.node("a"); // the label passed to setNode, with x and y
    interface DagreGraph<
        GraphLabel extends DagreGraphConfig = DagreGraphConfig,
        NodeLabel extends DagreNodeLabel = DagreNodeLabel,
        EdgeLabel extends DagreEdgeLabel = DagreEdgeLabel,
    > {
        edge(v: string, w: string, name?: string): EdgeLabel & DagreEdge;
        edge(edge: { name?: string; v: string; w: string }): EdgeLabel & DagreEdge;
        edgeCount(): number;
        edges(): DagreEdgeDescriptor[];
        filterNodes(
            fn: (id: string) => boolean,
        ): DagreGraph<GraphLabel, NodeLabel, EdgeLabel>;
        graph(): GraphLabel;
        hasEdge(v: string, w: string, name?: string): boolean;
        hasEdge(edge: { name?: string; v: string; w: string }): boolean;
        hasNode(id: string): boolean;
        inEdges(v: string, w?: string): DagreEdgeDescriptor[];
        isCompound(): false;
        isDirected(): true;
        isMultigraph(): boolean;
        neighbors(id: string): string[];
        node(id: string): NodeLabel & DagreNode;
        nodeCount(): number;
        nodeEdges(v: string, w?: string): DagreEdgeDescriptor[];
        nodes(): string[];
        outEdges(v: string, w?: string): DagreEdgeDescriptor[];
        predecessors(id: string): string[];
        removeEdge(v: string, w: string, name?: string): this;
        removeEdge(edge: { name?: string; v: string; w: string }): this;
        removeNode(id: string): this;
        setDefaultEdgeLabel(
            labelOrFn:
                | EdgeLabel
                | ((v: string, w: string, name: undefined) => EdgeLabel),
        ): this;
        setDefaultNodeLabel(
            labelOrFn: NodeLabel | ((id: string) => NodeLabel),
        ): this;
        setEdge(v: string, w: string, label?: EdgeLabel, name?: string): this;
        setEdge(
            edge: { name?: string; v: string; w: string },
            label?: EdgeLabel,
        ): this;
        setGraph(label: GraphLabel): this;
        setNode(id: string, label?: NodeLabel): this;
        setNodes(ids: string[], label?: NodeLabel): this;
        setPath(nodes: string[]): this;
        sinks(): string[];
        sources(): string[];
        successors(id: string): string[];
    }

    Type Parameters

    Index
    • get the label of the edge from v to w

      This is the label passed to setEdge, with points after layout. An edge with a name is never found, since edges have no names.

      Parameters

      • v: string
      • w: string
      • Optionalname: string

      Returns EdgeLabel & DagreEdge

    • get the label of an edge given by a descriptor

      Parameters

      • edge: { name?: string; v: string; w: string }
        • Optionalname?: string

          edge name

        • v: string

          source node id

        • w: string

          target node id

      Returns EdgeLabel & DagreEdge

    • number of edges

      Returns number

    • check if the edge from v to w exists

      An edge with a name is never found, since edges have no names.

      Parameters

      • v: string
      • w: string
      • Optionalname: string

      Returns boolean

    • check if an edge given by a descriptor exists

      Parameters

      • edge: { name?: string; v: string; w: string }
        • Optionalname?: string

          edge name

        • v: string

          source node id

        • w: string

          target node id

      Returns boolean

    • check if a node exists

      Parameters

      • id: string

      Returns boolean

    • always false, since compound graphs are not supported

      Returns false

    • always true, since dagre graphs are directed

      Returns true

    • true if the graph has multiple edges between the same pair of nodes

      Returns boolean

    • get all neighbor node ids (predecessors and successors, deduplicated)

      Parameters

      • id: string

      Returns string[]

    • number of nodes

      Returns number

    • get all node ids

      Returns string[]

    • get predecessor node ids

      Parameters

      • id: string

      Returns string[]

    • remove the edge from v to w

      An edge with a name is never found, since edges have no names.

      Parameters

      • v: string
      • w: string
      • Optionalname: string

      Returns this

    • remove an edge given by a descriptor

      Parameters

      • edge: { name?: string; v: string; w: string }
        • Optionalname?: string

          edge name

        • v: string

          source node id

        • w: string

          target node id

      Returns this

    • remove a node and all its edges

      Parameters

      • id: string

      Returns this

    • set the label used when setEdge adds an edge without one

      As in dagre, a function is called with the source id, the target id, and the edge name for each new edge, and anything else is used as is, so every such edge shares the same object. Edges have no names, so the name is always undefined.

      Parameters

      Returns this

    • set the label used when setNode adds a node without one

      As in dagre, a function is called with the node id for each new node, and anything else is used as is, so every such node shares the same object.

      Parameters

      Returns this

    • add or update the edge from v to w

      The label object is kept as is, and dagre.layout writes points onto it. Fields such as minlen or weight are kept but don't affect layout.

      Edges have no names, so setting one with a name throws, as dagre does for a graph that isn't a multigraph.

      Parameters

      • v: string
      • w: string
      • Optionallabel: EdgeLabel
      • Optionalname: string

      Returns this

    • add or update an edge given by a descriptor like those edges returns

      Parameters

      • edge: { name?: string; v: string; w: string }
        • Optionalname?: string

          edge name

        • v: string

          source node id

        • w: string

          target node id

      • Optionallabel: EdgeLabel

      Returns this

    • set the graph label, replacing any earlier one

      The object is kept as is: dagre.layout reads its options, using defaults for missing ones without writing them, and writes width and height onto it.

      Parameters

      Returns this

    • add or update a node

      The label object is kept as is, and dagre.layout writes x and y onto it.

      Parameters

      Returns this

    • add or update multiple nodes

      Parameters

      Returns this

    • add edges between consecutive pairs of nodes

      Parameters

      • nodes: string[]

      Returns this

    • get sink node ids (no children)

      Returns string[]

    • get source node ids (no parents)

      Returns string[]

    • get successor node ids

      Parameters

      • id: string

      Returns string[]