Graphity for TypeScript 3.0.0
    Preparing search index...

    A writer of DOT (the language of Graphviz) that labels and styles a graph with the caller's data by node ID and edge index.

    DotWriter.of returns a writer for a graph, the methods that configure it return the writer again, and DotWriter.write or DotWriter.writeToString write the text. The graph holds no data, so labels and attributes come from hooks that receive a node ID or an edge index and read the caller's arrays. Here, the packages of a small program get their names from names. The strongly connected components sccs tell which packages are in a cycle, and these are drawn in red:

    const dot = DotWriter.of(dependencies)
    .nodeLabel((node) => names[node])
    .nodeAttributes((node, attributes) => {
    if (sccs.containsCycle(sccs.sccOf(node))) {
    attributes.set("color", "red");
    }
    })
    .writeToString();
    // model and storage, the cycle, in red:
    // 4 [label="model", color="red"];
    // 5 [label="storage", color="red"];

    Nodes are named by their node IDs. The text lists the graph attributes, the clusters in group order with their nodes, then the nodes in no cluster, then the edges in edge index order, so the same graph and hooks always give the same text. A node outside the clusters is listed only if it has a label or attributes, or no edge in the text; Graphviz creates the other nodes from their edges.

    Labels and attribute values are written as quoted strings: the writer escapes quotes and backslashes and turns line breaks into DOT's \n. Graphviz decodes HTML entities such as < in the attributes label, xlabel, headlabel and taillabel. In these, the writer also turns & into &, so that a label shows exactly its text. Other values, such as a URL, keep their &. NUL, which DOT cannot hold, is written as U+FFFD.

    Attribute names must be identifiers - an ASCII letter or underscore, then ASCII letters, digits or underscores - other than the DOT keywords node, edge, graph, digraph, subgraph and strict, in any letter case.

    A writer keeps its configuration and can write any number of times. For Markdown and documentation, MermaidWriter in the package @kobayami/graphity-mermaid writes a Mermaid flowchart.

    Instances are mutable.

    Index
    • Draws each group of partition as a cluster, with a label by group ID.

      Nodes in no group stay outside every cluster, and a group without a node to write has no cluster. A label of null or undefined leaves a cluster unlabeled, also when the graph has a label, which Graphviz would otherwise repeat on every cluster.

      Time: O(1).

      Parameters

      • partition: NodePartition

        the groups, over the nodes of the graph, such as an Sccs

      • label: (group: number) => string | null | undefined

        called with a group ID, returns the label of its cluster, or null or undefined

      Returns this

      this writer

      Error if partition has a different node count than the graph

    • Sets the hook that adds DOT attributes, such as color or style, to each edge, by edge index.

      The hook receives the label from DotWriter.edgeLabel as the attribute label, which it can replace or remove.

      Time: O(1).

      Parameters

      • hook: AttributeHook

        called with each edge that is written, puts its attributes

      Returns this

      this writer

    • Sets the label of each edge, by edge index; null or undefined leaves an edge unlabeled.

      Time: O(1).

      Parameters

      • label: (edge: number) => string | null | undefined

        called with an edge index, returns the label of the edge, or null or undefined

      Returns this

      this writer

    • Sets an attribute of the graph, such as rankdir to LR.

      Time: O(1).

      Parameters

      • name: string

        attribute name, an identifier other than a DOT keyword

      • value: string

        attribute value

      Returns this

      this writer

      Error if name is not an identifier or is a DOT keyword

    • Sets the hook that adds DOT attributes, such as shape, color or style, to each node, by node ID.

      The hook receives the label from DotWriter.nodeLabel as the attribute label, which it can replace or remove.

      Time: O(1).

      Parameters

      • hook: AttributeHook

        called with each node that is written, puts its attributes

      Returns this

      this writer

    • Restricts the text to the nodes that include accepts and the edges between them.

      Node IDs stay those of the graph, so the hooks keep reading the same arrays.

      Time: O(1).

      Parameters

      • include: (node: number) => boolean

        called with a node ID, returns whether to write the node

      Returns this

      this writer

    • Sets the label of each node, by node ID; null or undefined leaves a node unlabeled, and Graphviz then shows its node ID.

      Time: O(1).

      Parameters

      • label: (node: number) => string | null | undefined

        called with a node ID, returns the label of the node, or null or undefined

      Returns this

      this writer

    • Switches to the undirected reading of the graph: a graph with -- edges instead of a digraph.

      The edges a -> b and b -> a become one, written as the edge from the lower node ID; the edge hooks receive its edge index.

      Time: O(1).

      Returns this

      this writer

    • Writes the graph to out, as DOT text. out is anything with a method write(text), such as process.stdout or a file stream of Node.js (Java: an Appendable).

      The text goes to out.write in chunks of about 8 KiB characters, not piece by piece.

      Time: O(nodeCount + edgeCount + groupCount), plus the hooks, with groupCount the number of groups of the partition drawn as clusters; in the undirected reading, O(log outDegree(target)) more per edge. Memory: nodeCount bytes while it runs, and a chunk of text.

      Parameters

      • out: TextSink

        where the text goes; not closed

      Returns void

      Error what out.write throws (Java: IOException), or if an attribute hook puts a name that is not an identifier or is a DOT keyword; the text written before the error has gone to out. Only a write that throws fails the call. A stream reports its errors through its own event or promise, which the caller must watch (see TextSink)

    • Returns the DOT text of the graph, as DotWriter.write writes it.

      Time: as for DotWriter.write. Memory: the text for the result; while it runs, up to twice as much again and nodeCount bytes more.

      Returns string

      the DOT text

      Error as for DotWriter.write

      RangeError the engine's Invalid string length, if the text is longer than a JavaScript string can be (2^29 - 24 characters in V8, where Java allows 2^31 - 9; Java: an OutOfMemoryError)