dot API reference
Graphviz DOT graph description: build a graph of nodes and edges with attributes and render it to .dot text for an external Graphviz tool to lay out and draw (dot -Tsvg graph.dot > graph.svg). Pure Jennifer - no Go, no system library, both binaries - it emits the text description only; graph layout is Graphviz's job and is deliberately not reimplemented. Value semantics throughout: every builder returns a fresh Graph, so the graph you pass in is never mutated.
Import with import "dot.j" as dot;. See the dot guide for prose and examples.
Contents
| Name | What it is |
|---|---|
digraph | A new, empty directed graph. |
edge | Add a bare edge between two node ids. |
edgeAttr | Set a default edge attribute, rendered once as `edge [ ... |
edgeWith | Add an edge with attributes ({"label": "calls", "style": "dashed"}). |
graph | A new, empty undirected graph. |
graphAttr | Set a graph-level attribute (rendered as key="value";), e.g. |
node | Add a bare node (no attributes). |
nodeAttr | Set a default node attribute, rendered once as `node [ ... |
nodeWith | Add a node with attributes ({"label": "Parser", "shape": "box"}). |
render | Render the graph to DOT text (a trailing newline included), ready to write to a .dot file or pipe to dot. |
Edge | struct: A directed or undirected edge between two node ids, with its own attributes. |
Graph | struct: A whole graph: its kind (directed = digraph), name, ordered nodes and edges, and default attribute blocks f... |
Node | struct: A single graph node: an id (its key in the graph) plus an ordered attribute map (label, shape, color, ...). |
Functions
digraph
dot.digraph(name as string)A new, empty directed graph. Renders as digraph with a -> b edges.
name- the graph name
- Returns
Graph - an empty directed graph
edge
dot.edge(g as Graph, src as string, dst as string)Add a bare edge between two node ids.
g- the graph
src- the source node id
dst- the destination node id
- Returns
Graph - a copy with the edge appended
edgeAttr
dot.edgeAttr(g as Graph, key as string, value as string)Set a default edge attribute, rendered once as edge [ ... ] before the edges - so every edge inherits, e.g. color = gray.
g- the graph
key- the attribute name
value- the attribute value
- Returns
Graph - a copy with the default set
- Throws
Error - kind "dot" if key is not a DOT identifier
edgeWith
dot.edgeWith(
g as Graph,
src as string,
dst as string,
attrs as map of string to string)Add an edge with attributes ({"label": "calls", "style": "dashed"}).
g- the graph
src- the source node id
dst- the destination node id
attrs- the edge's DOT attributes
- Returns
Graph - a copy with the edge appended
graph
dot.graph(name as string)A new, empty undirected graph. Renders as graph with a -- b edges.
name- the graph name
- Returns
Graph - an empty undirected graph
graphAttr
dot.graphAttr(g as Graph, key as string, value as string)Set a graph-level attribute (rendered as key="value";), e.g. rankdir = LR or a graph label.
g- the graph
key- the attribute name
value- the attribute value
- Returns
Graph - a copy with the attribute set
- Throws
Error - kind "dot" if key is not a DOT identifier
node
dot.node(g as Graph, id as string)Add a bare node (no attributes). Adding a node is optional - an id first seen on an edge is created implicitly by Graphviz - but an explicit node carries a label, shape, or colour.
g- the graph
id- the node id
- Returns
Graph - a copy with the node appended
nodeAttr
dot.nodeAttr(g as Graph, key as string, value as string)Set a default node attribute, rendered once as node [ ... ] before the nodes - so every node inherits, e.g. shape = box.
g- the graph
key- the attribute name
value- the attribute value
- Returns
Graph - a copy with the default set
- Throws
Error - kind "dot" if key is not a DOT identifier
nodeWith
dot.nodeWith(g as Graph, id as string, attrs as map of string to string)Add a node with attributes ({"label": "Parser", "shape": "box"}).
g- the graph
id- the node id
attrs- the node's DOT attributes
- Returns
Graph - a copy with the node appended
render
dot.render(g as Graph)Render the graph to DOT text (a trailing newline included), ready to write to a .dot file or pipe to dot.
g- the graph to render
- Returns
string - the DOT source
- Throws
Error - kind "dot" if an attribute name is not a DOT identifier, or an id, the graph name or a value holds a control character other than tab, LF and CR
Structs
Edge
A directed or undirected edge between two node ids, with its own attributes.
def struct Edge {
from as string,
to as string,
attrs as map of string to string
};from- the source node id
to- the destination node id
attrs- DOT attributes, in insertion order
Graph
A whole graph: its kind (directed = digraph), name, ordered nodes and edges, and default attribute blocks for the graph, its nodes, and its edges.
def struct Graph {
directed as bool,
name as string,
nodes as list of Node,
edges as list of Edge,
graphAttrs as map of string to string,
nodeAttrs as map of string to string,
edgeAttrs as map of string to string
};directed- true renders a
digraphwith->edges, false agraphwith-- name- the graph name (quoted in the output)
nodes- explicit nodes, in insertion order
edges- edges, in insertion order
graphAttrskey="value";graph-level attributesnodeAttrs- the
node [ ... ]default block edgeAttrs- the
edge [ ... ]default block
Node
A single graph node: an id (its key in the graph) plus an ordered attribute map (label, shape, color, ...).
def struct Node {
id as string,
attrs as map of string to string
};id- the node identifier
attrs- DOT attributes, in insertion order