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.

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 graph
  • src {string} - the source node id
  • dst {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 graph
  • key {string} - the attribute name
  • value {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 graph
  • src {string} - the source node id
  • dst {string} - the destination node id
  • attrs {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 graph
  • key {string} - the attribute name
  • value {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 graph
  • id {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 graph
  • key {string} - the attribute name
  • value {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 graph
  • id {string} - the node id
  • attrs {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.

FieldTypeDescription
fromstringthe source node id
tostringthe destination node id
attrsmap of string to stringDOT 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.

FieldTypeDescription
directedbooltrue renders a digraph with -> edges, false a graph with --
namestringthe graph name (quoted in the output)
nodeslist of Nodeexplicit nodes, in insertion order
edgeslist of Edgeedges, in insertion order
graphAttrsmap of string to stringkey="value"; graph-level attributes
nodeAttrsmap of string to stringthe node [ ... ] default block
edgeAttrsmap of string to stringthe edge [ ... ] default block

dot.Node

A single graph node: an id (its key in the graph) plus an ordered attribute map (label, shape, color, ...).

FieldTypeDescription
idstringthe node identifier
attrsmap of string to stringDOT attributes, in insertion order