Skip to content
Jennifer Programming Language

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

NameWhat it is
digraphA new, empty directed graph.
edgeAdd a bare edge between two node ids.
edgeAttrSet a default edge attribute, rendered once as `edge [ ...
edgeWithAdd an edge with attributes ({"label": "calls", "style": "dashed"}).
graphA new, empty undirected graph.
graphAttrSet a graph-level attribute (rendered as key="value";), e.g.
nodeAdd a bare node (no attributes).
nodeAttrSet a default node attribute, rendered once as `node [ ...
nodeWithAdd a node with attributes ({"label": "Parser", "shape": "box"}).
renderRender the graph to DOT text (a trailing newline included), ready to write to a .dot file or pipe to dot.
Edgestruct: A directed or undirected edge between two node ids, with its own attributes.
Graphstruct: A whole graph: its kind (directed = digraph), name, ordered nodes and edges, and default attribute blocks f...
Nodestruct: A single graph node: an id (its key in the graph) plus an ordered attribute map (label, shape, color, ...).

Functions

digraph

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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.

jennifer
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.

jennifer
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 digraph with -> edges, false a graph with --
name
the graph name (quoted in the output)
nodes
explicit nodes, in insertion order
edges
edges, in insertion order
graphAttrs
key="value"; graph-level attributes
nodeAttrs
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, ...).

jennifer
def struct Node {
    id as string,
    attrs as map of string to string
};
id
the node identifier
attrs
DOT attributes, in insertion order