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.
Functions
dot.digraph(name as string)
A new, empty directed graph. Renders as digraph with a -> b edges.
Parameters
name{string}- the graph name
Returns {Graph} - an empty directed graph
dot.edge(g as Graph, src as string, dst as string)
Add a bare edge between two node ids.
Parameters
g{Graph}- the graphsrc{string}- the source node iddst{string}- the destination node id
Returns {Graph} - a copy with the edge appended
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.
Parameters
g{Graph}- the graphkey{string}- the attribute namevalue{string}- the attribute value
Returns {Graph} - a copy with the default set
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"}).
Parameters
g{Graph}- the graphsrc{string}- the source node iddst{string}- the destination node idattrs{map of string to string}- the edge's DOT attributes
Returns {Graph} - a copy with the edge appended
dot.graph(name as string)
A new, empty undirected graph. Renders as graph with a -- b edges.
Parameters
name{string}- the graph name
Returns {Graph} - an empty undirected graph
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.
Parameters
g{Graph}- the graphkey{string}- the attribute namevalue{string}- the attribute value
Returns {Graph} - a copy with the attribute set
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.
Parameters
g{Graph}- the graphid{string}- the node id
Returns {Graph} - a copy with the node appended
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.
Parameters
g{Graph}- the graphkey{string}- the attribute namevalue{string}- the attribute value
Returns {Graph} - a copy with the default set
dot.nodeWith(g as Graph, id as string, attrs as map of string to string)
Add a node with attributes ({"label": "Parser", "shape": "box"}).
Parameters
g{Graph}- the graphid{string}- the node idattrs{map of string to string}- the node's DOT attributes
Returns {Graph} - a copy with the node appended
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.
Parameters
g{Graph}- the graph to render
Returns {string} - the DOT source
Structs
dot.Edge
A directed or undirected edge between two node ids, with its own attributes.
| Field | Type | Description |
|---|---|---|
from | string | the source node id |
to | string | the destination node id |
attrs | map of string to string | DOT attributes, in insertion order |
dot.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.
| Field | Type | Description |
|---|---|---|
directed | bool | true renders a digraph with -> edges, false a graph with -- |
name | string | the graph name (quoted in the output) |
nodes | list of Node | explicit nodes, in insertion order |
edges | list of Edge | edges, in insertion order |
graphAttrs | map of string to string | key="value"; graph-level attributes |
nodeAttrs | map of string to string | the node [ ... ] default block |
edgeAttrs | map of string to string | the edge [ ... ] default block |
dot.Node
A single graph node: an id (its key in the graph) plus an ordered attribute map (label, shape, color, ...).
| Field | Type | Description |
|---|---|---|
id | string | the node identifier |
attrs | map of string to string | DOT attributes, in insertion order |