A few examples of dot language to render fancy graphs.
Layout
Choosing layout engine
# The default layout is top to bottom. Lower rank is on top.
digraph {
a -> {b c d}
b -> {e f g}
}
digraph {
a -> {b c d}
b -> {e f g}
}
# Change the flow of default layout from left to right.
digraph {
rankdir=LR
a -> {b c d}
b -> {e f g}
}
digraph {
rankdir=LR
a -> {b c d}
b -> {e f g}
}
# Change engine to a force based layout.
digraph {
layout=neato
a -> {b c d}
b -> {e f g}
}
digraph {
layout=neato
a -> {b c d}
b -> {e f g}
}
# A couple of option to expand/compress the resulting node layout.
digraph {
layout=neato
edge [len=0.8] # change edge length
overlap=false # prevents nodes from overlapping each other
# These options MIGHT work on other implementations
#overlap_scaling=0.5
#overlap_shrink=true
a -> {b c d}
b -> {e f g}
}
digraph {
layout=neato
edge [len=0.8]
overlap=false
a -> {b c d}
b -> {e f g}
}
# A couple of option to expand/compress differently on x and y dimensions.
digraph {
layout=neato
overlap=false # you NEED THIS for `sep` to take effect
sep="+30,-5" # expands 30 pixels on the x direction, but shrink y by 5
a -> {b c d}
b -> {e f g}
}
digraph {
layout=neato
overlap=false
sep="+30,-5"
a -> {b c d}
b -> {e f g}
}
# A couple of option to expand/compress differently on x and y dimensions.
digraph {
nodesep=0.6 # distance between nodes along x axis
ranksep=0.3 # distance between nodes along y axis
a -> {b c d}
b -> {e f g}
}
digraph {
nodesep=0.6
ranksep=0.3
a -> {b c d}
b -> {e f g}
}
- Attributes
overlap
,sep
,len
only work for neato engine. - Attributes
nodesep
andranksep
used in the standard layout engine.
Playing with rank
# Each node is assigned a higher rank than the highest ranked node
# that point to it (also works for undirected edges).
digraph {
a -> {b c}
b -> d
# resulting rank : a=0, b=1, c=1, d=2
}
digraph {
a -> {b c}
b -> d
}
digraph {
a -> {b c}
b -> d
{rank=min d}
}
digraph {
a -> {b c}
b -> d
{rank=min d}
}
digraph {
a -> {b c}
b -> d
{rank=same b d}
{rank=max a}
}
digraph {
a -> {b c}
b -> d
{rank=same b d}
{rank=max a}
}
digraph {
# these edges are not used for ranking.
a -> {b c} [constraint=false]
b -> d
}
digraph {
a -> {b c} [constraint=false]
b -> d
}
Playing with subclusters
digraph {
# It is a trap ! subgraph MUST start with cluster.
# clusterrank=none will deactivate drawing the cluster boundary.
subgraph cluster_cl {
a -> {b c}
# By default rank is local to subgraph.
# The following statement does not change anything.
{rank=min a}
}
r -> a
b -> d
}
digraph {
subgraph cluster_cl {
a -> {b c}
{rank=min a}
}
r -> a
b -> d
}
digraph {
newrank=true # rank constraints are global
subgraph cluster_cl {
a -> {b c}
{rank=min a} # now rank_a < rank_r
}
r -> a
b -> d
}
digraph {
newrank=true
subgraph cluster_cl {
a -> {b c}
{rank=min a}
}
r -> a
b -> d
}
digraph {
subgraph cluster_cl {
a -> {b c}
}
r -> a
b -> d
# By declaring the constraint OUTSIDE the subgraph
# you somehow pull the node out of the cluster.
{rank=min a}
}
digraph {
subgraph cluster_cl {
a -> {b c}
}
r -> a
b -> d
{rank=min a}
}
digraph {
newrank=true
subgraph cluster_cl {
a -> {b c}
}
r -> a
b -> d
# You can quickly get in WTF?! territory ...
# You would expect that rank_d <= rank_r, but nope ...
{rank=min d}
}
digraph {
newrank=true
subgraph cluster_cl {
a -> {b c}
}
r -> a
b -> d
{rank=min d}
}
Node shapes
digraph {
a [label="multiline
label"]
# Be careful it is a trap !
# rankdir will change the direction of the record
b [shape=record label="{record
| vertical}"]
c [shape=record label="record
| horizontal"]
a -> { b c }
}
digraph {
a [label="multiline
label"]
b [shape=record label="{record
| vertical}"]
c [shape=record label="record
| horizontal"]
a -> { b c }
}
digraph {
a [shape=box label="text label
tags <b>NOT interpreted</b>
empty lines NOT ignored"]
b [shape=box label=<html label<br/>
tags <b>interpreted</b><br/>
empty lines ignored>]
a -> b
}
digraph {
a [shape=box label="text label
tags <b>NOT interpreted</b>
empty lines NOT ignored"]
b [shape=box label=<html label<br/>
tags <b>interpreted</b><br/>
empty lines ignored>]
a -> b
}
Other neat tricks
digraph {
a -> {b c}
# Heavy weight => short, straight and more vertical the edge.
a -> d [weight=3]
}
digraph {
a -> {b c}
a -> d [weight=3]
}