Function graph

  • create a new mutable empty MutGraph

    When creating a new mutable graph via typescript, you must specify the type of the node data and link data you intend on using, since these types are invariant for mutable graphs.

    Type Parameters

    • NodeDatum

      the extra user data attached to each node

    • LinkDatum

      the extra data attached to each link

    Returns MutGraph<NodeDatum, LinkDatum>

    Creating a graph with node and link data:

    // create a new graph
    const grf = graph<string, number>();
    // add two nodes with some data
    const a = grf.node("a");
    const b = grf.node("b");
    // add a new link with the data `1`
    const link = grf.link(a, b, 1);
    grf.connected(); // true

    If undefined extends the data types then they can be omitted:

    // create a new graph
    const grf = graph<undefined | string, undefined | number>();
    const a = grf.node();
    const b = grf.node();
    const link = grf.link(a, b);
    grf.connected(); // true