Defines a class for MermaidWriter.nodeClass to assign, written as classDef name style.
Time: O(1).
class name, an identifier other than a Mermaid keyword
style of the class, such as fill:#f96,stroke:#333
this writer
Draws each group of partition as a cluster (a Mermaid subgraph), 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 shows the name of the cluster: c and the group ID,
such as c2.
Time: O(1).
the groups, over the nodes of the graph, such as an Sccs
called with a group ID, returns the label of its cluster, or null or undefined
this writer
Sets the direction of the flowchart; without a call, it is Direction.TOP_DOWN.
Time: O(1).
the direction
this writer
Error if direction is not a value of Direction (not in Java, where an enum
value is always valid)
Sets the label of each edge, by edge index; null or undefined leaves an edge unlabeled.
Time: O(1).
called with an edge index, returns the label of the edge, or null or undefined
this writer
Sets the style of each edge, by edge index, written as a linkStyle statement; null or
undefined leaves an edge in the default style.
Time: O(1).
called with an edge index, returns the style of the edge, such as
stroke:red,stroke-width:2px, or null or undefined
this writer
Sets the class of each node, by node ID; null or undefined assigns none.
Time: O(1).
called with a node ID, returns the name of the class of the node, an
identifier other than a Mermaid keyword, or null or undefined
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).
called with a node ID, returns whether to write the node
this writer
Sets the label of each node, by node ID; null or undefined shows the name of the node, such
as n4.
Time: O(1).
called with a node ID, returns the label of the node, or null or undefined
this writer
Sets the shape of each node, by node ID; null or undefined draws a rectangle.
A value that is not one of Shape makes MermaidWriter.write throw an Error.
Time: O(1).
called with a node ID, returns the shape of the node, or null or undefined
this writer
Switches to the undirected reading of the graph: edges without arrowheads.
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).
this writer
Writes the graph to out, as the text of a Mermaid flowchart. 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: up to twice the size of the linkStyle lines while it runs, as they
are written last, and a chunk of text.
where the text goes; not closed
Error what out.write throws (Java: IOException), or if a hook returns a class name
that is not an identifier or is a Mermaid keyword, an edge style that is blank or contains
a line break or a semicolon, or a shape that is not one of Shape; 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 text of the Mermaid flowchart, as MermaidWriter.write writes it.
Time: as for MermaidWriter.write. Memory: the text for the result; while it
runs, up to twice as much again, and the linkStyle lines as for MermaidWriter.write.
the Mermaid text
Error as for MermaidWriter.write
StaticofReturns a writer for graph, top down, with no labels, shapes, classes, clusters or filter
yet.
Time: O(1).
the graph to write
the writer
A writer of Mermaid flowcharts that labels and styles a graph with the caller's data by node ID and edge index. Mermaid flowcharts render in Markdown.
MermaidWriter.of returns a writer for a graph, the methods that configure it return the writer again, and MermaidWriter.write or MermaidWriter.writeToString write the text. The graph holds no data, so labels, shapes, classes and styles 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 componentssccstell which packages are in a cycle, and these are drawn in red:Nodes are named by their node IDs after an
n, such asn4. The text lists the class definitions, the clusters in group order with their nodes, then the nodes in no cluster, then the edges in edge index order, the classes of the nodes and the edge styles, so the same graph and hooks always give the same text. Mermaid numbers the edges in the order they are written; the writer translates edge indices into these numbers forlinkStyle, also when a filter leaves edges out.Labels are written as quoted strings: the writer turns quotes,
#,%,&,:,<,>and backticks into Mermaid entity codes and line breaks into<br>, so that no label reads as HTML, as a Markdown string or as a directive. For the same reason, whitespace right after the worddirectionbecomes an entity code, and an empty label, which Mermaid rejects, is written as one space.Mermaid's renderer still changes some labels. Mermaid 11 applies Markdown emphasis and backslash escapes to every label, so
2*3*4loses its asterisks; Mermaid 12 shows a backslash beforenas a line break. Both read¶ßandfl°, which Mermaid uses internally for entity codes, as;and&. Both also turnfa:fa-name into an icon in a node label with a line break. WithhtmlLabelsset tofalse, Mermaid shows some entity codes as written, such as:for:.Class names must be identifiers - an ASCII letter or underscore, then ASCII letters, digits or underscores - other than a Mermaid keyword:
style,linkStyle,interpolate,classDef,class,href,click,call,graph,flowchart,subgraph,end,_self,_blank,_parentand_top. Keywords are case-sensitive, soEndis a valid class name. Styles are written as given and must not be blank or contain a line break or a semicolon.Mermaid renders graphs of a few hundred nodes well; for larger ones,
DotWriterin the package@kobayami/graphity-dotwrites DOT (the language of Graphviz). A writer keeps its configuration and can write any number of times.Instances are mutable.