The DOT language

edit

Statements

The parser reads the grammar of DOT:

  • graph and digraph, strict (the edges between the same nodes are merged), and the name of the graph.
  • The node statements (a [label="A"]), the edge statements, with chains (a -> b -> c) and groups of nodes (a -> {b c}, subgraph s {d e} -> f), and the attribute statements (graph [...], node [...], edge [...], name=value).
  • The subgraphs, anonymous or named. A subgraph whose name starts with cluster, or that has cluster=true, is a cluster: it becomes a subgraph of the flowchart, drawn as a frame. The other subgraphs only group nodes and attributes. A node of several clusters is drawn in the innermost one.
  • The identifiers, the numbers, the quoted strings joined with +, the lines continued with a backslash, and the HTML strings (<...>). The keywords are case-insensitive.
  • The comments (//, /* */) and the lines of the C preprocessor (#).

As in Graphviz, the default attributes set by node [...] and edge [...] apply to the nodes and the edges created after them, in the same subgraph and its nested subgraphs. A subgraph starts with the attributes its parent graph has when the subgraph is created: a label set at the top of the graph is also the title of the clusters that follow, so set it after them.

The edges of a digraph are written ->, and the edges of a graph --. The edges of an undirected graph have no arrowheads, unless their dir attribute adds some. The ports of the nodes (a:port:n) are read and ignored: the edges are attached to the nodes.

Attributes

ElementAttributeEffect
GraphlabelThe Title of the diagram.
GraphrankdirThe Direction: TB, LR, BT or RL.
Graphnodesep, ranksepThe NodeSpacing and the RankSpacing, in inches (72 pixels).
Graphsplinesline, polyline and false draw straight edges, ortho draws horizontal and vertical segments, spline and true curves.
GraphbgcolorThe background of the theme.
GraphcompoundEnables lhead and ltail.
ClusterlabelThe title of the frame. A cluster without a label has no title.
Clusterbgcolor, fillcolor, color, pencolorThe background (bgcolor, or fillcolor with style=filled) and the border (pencolor, else color).
NodelabelThe label; without one, the node shows its name.
Nodeshape, sidesThe shape: see the shapes below.
Nodecolor, fillcolorThe border, and the background of a node with style=filled (fillcolor, else color, else light gray).
EdgelabelThe label.
Edgedir, arrowhead, arrowtailThe arrowheads: see the arrowheads below.
EdgecolorThe color of the line.
EdgeminlenThe Length: the minimum number of ranks the edge spans, from 1 to 100.
Edgelhead, ltailWith compound=true, the edge ends at the frame of a cluster that contains its end: its end is the subgraph.
AllstyleSee the styles below.
Allfontcolor, fontsize, penwidthThe color and the size of the texts, and the width of the lines.
Nodes and clustersURL (or href), tooltipThe link and the tooltip of the element in the SVG. A link that is not relative and whose scheme is not http, https or mailto (such as javascript:) is ignored, with a warning.
AllclassThe CSS classes of the element in the SVG.

The other attributes, such as fontname, width, height, weight or constraint, are ignored and reported as warnings. So is a layout other than dot, and the rank of the subgraphs (rank=same): the layered layout places the nodes.

Styles

The style attribute is a list of styles separated by commas:

  • filled fills a node or a cluster.
  • rounded rounds the corners of a box (shape=box, record).
  • dashed and dotted draw dashed and dotted lines. An edge that is dashed or dotted is a Dotted edge.
  • bold draws a Thick edge, and the border of a node 2 pixels wide. setlinewidth(n) sets the width of the lines.
  • invis hides the element: an Invisible edge, or a node or a cluster whose opacity is 0, which keeps its place in the layout.

The other styles (diagonals, striped, wedged, radial, tapered) are ignored and reported as warnings.

Shapes

Each shape of Graphviz is drawn as the closest shape of the flowcharts:

GraphvizFlowchart
box, rect, rectangle, square, Msquare, invhouse, recordRectangle (RoundedRectangle with style=rounded)
MrecordRoundedRectangle
ellipse (the default), oval, eggStadium
circle, McircleCircle
doublecircleDoubleCircle
pointFilledCircle
diamond, MdiamondDiamond
hexagon, pentagon, septagon, octagon, doubleoctagon, tripleoctagonHexagon
parallelogramLeanRight
trapezium, invtrapeziumTrapezoidBaseBottom, TrapezoidBaseTop
triangle, invtriangleTriangle, FlippedTriangle
houseTrapezoidalPentagon
cylinderCylinder
noteTaggedRectangle
folder, tabFolder
box3dStackedRectangle
componentLinedRectangle
plaintext, plain, none, underlineText
starBang
cds, rarrow, larrow, rpromoter, lpromoterOdd
polygonTriangle with sides=3, Hexagon with 5 sides or more, else Rectangle

The shapes of synthetic biology (promoter, terminator...) are drawn as rectangles. A shape Graphviz does not have is drawn as a rectangle, with a warning.

Arrowheads

The dir attribute chooses the ends of an edge that have an arrowhead: forward (the default of a digraph), back, both or none (the default of a graph). arrowhead and arrowtail choose their shape:

GraphvizFlowchart
normal, vee, empty, open, halfopen and their o, l and r variantsArrow
dot, odotCircle
tee, oteeCross, with a warning
noneNone

The other arrowheads, such as diamond, box or crow, are drawn as arrows, with a warning.

Colors

A color is a color name of X11, as Graphviz reads it (green is #00ff00, gray is #bebebe), or of CSS, grayN from 0 to 100, #rrggbb or #rrggbbaa, or three numbers from 0 to 1 for a color in HSV ("0.6 0.5 1"). A list of colors ("red:blue") uses its first color, and a scheme other than x11 (/accent3/1) and the numbered colors of X11 (red2) are ignored, with a warning.

Labels

The labels read the escapes of Graphviz: \n, \l and \r start a new line, \N is the name of the node, \G the name of the graph, \E the name of the edge (tail->head), and \T and \H the names of its ends. The line break that ends the last line is removed.

The labels of the record and Mrecord shapes are drawn as lines: each field is a line, without the separators and the ports. The HTML-like labels (label=<...>) are drawn as plain text: their line breaks and the rows of their tables start new lines, and their fonts, colors and images are ignored, with a warning.