d3-dag
    Preparing search index...

    Interface Json<NodeDatum, LinkDatum, Ops>

    an operator that hydrates serialized json into a graph

    Since type information is inherently lost with serialization, use nodeDatum and linkDatum to define node and link data type, and optionally perform extra deserialization.

    interface Json<NodeDatum, LinkDatum, Ops extends JsonOps<NodeDatum, LinkDatum>> {
        linkDatum<NL, NewLink extends Hydrator<NL>>(
            val: NewLink & Hydrator<NL>,
        ): Json<NodeDatum, NL, U<Ops, "linkDatum", NewLink>>;
        linkDatum(): Ops["linkDatum"];
        nodeDatum<NN, NewNode extends Hydrator<NN>>(
            val: NewNode & Hydrator<NN>,
        ): Json<NN, LinkDatum, U<Ops, "nodeDatum", NewNode>>;
        nodeDatum(): Ops["nodeDatum"];
        (json: unknown): MutGraph<NodeDatum, LinkDatum>;
    }

    Type Parameters

    • NodeDatum

      the node data type of the deserialized graph

    • LinkDatum

      the link data type of the deserialized graph

    • Ops extends JsonOps<NodeDatum, LinkDatum>

      the operators associated with deserialization

    Index

    Methods

    • set custom hydration for node data

      Type Parameters

      Parameters

      Returns Json<NN, LinkDatum, U<Ops, "nodeDatum", NewNode>>

      In the simpliest case, this can be used to cast the data types appropriately (or alternatively you could just cast the Graph itself.

      const grf: Graph<number> = ...
      const builder = graphJson().nodeDatum(data => data as number);
      const deser: MutGraph<number> = builder(JSON.parse(JSON.serialize(grf)));

      Ideally though, you'll use typescripts warnings to make serialization error proof:

      const grf: Graph<number> = ...
      const builder = graphJson().nodeDatum(data => {
      if (typeof data === "number") {
      return data;
      } else {
      throw new Error("...");
      }
      });
      const deser: MutGraph<number> = builder(JSON.parse(JSON.serialize(grf)));
    • get the node data hydrator

      Returns Ops["nodeDatum"]