digraphG {
A-> B; // Simple edgeA-> B[label="calls"]; // Labeled edgeA-> {B; C; D}; // One to many
}
Edge Attributes
digraph G {
A -> B [
label="relationship",
style=dashed,
color="#FF6B6B",
penwidth=2,
arrowhead=normal,
arrowtail=none,
dir=both
];
}
Edge Styles
Style
Description
solid
Regular line (default)
dashed
Dashed line
dotted
Dotted line
bold
Thick line
invis
Invisible (for layout)
Arrow Heads
Type
Description
normal
Standard arrow (default)
open
Open arrow tip
none
No arrow
diamond
Diamond end
odiamond
Open diamond
dot
Dot end
box
Box end
crow
Crow's foot (ER diagrams)
vee
V-shaped
Layout Control
Layout Directions
digraph G {
rankdir=TB; // Top to Bottom (default)
// rankdir=LR; // Left to Right
// rankdir=RL; // Right to Left
// rankdir=BT; // Bottom to Top
}
Node Ranking
digraph G {
{rank=same; A; B; C;} // Force same level
{rank=min; StartNode;} // Force to top
{rank=max; EndNode;} // Force to bottom
{rank=source; Input;} // Absolutely first
{rank=sink; Output;} // Absolutely last
}
Spacing Control
digraph G {
graph [
nodesep=0.5, // Horizontal spacing between nodes
ranksep=1.0, // Vertical spacing between ranks
splines=ortho // Edge routing: ortho|polyline|curved|line
];
}
digraph G {
subgraph cluster_backend {
label="Backend Services";
style=filled;
fillcolor="#F0F0F0";
color="#333333";
API [label="API Gateway"];
DB [label="Database", shape=cylinder];
API -> DB;
}
subgraph cluster_frontend {
label="Frontend";
style=filled;
fillcolor="#F5F5F5";
Client [label="Web Client"];
}
Client -> API;
}
Note: Cluster names must start with cluster_ to render as boxes.
Global Defaults
digraphG {
// Default for all nodesnode[shape=box, style=filled, fillcolor="#3498DB", fontcolor=white];
// Default for all edgesedge[color="#666666", arrowhead=vee];
// Graph attributesgraph[rankdir=LR, bgcolor=white];
A-> B-> C;
}
Color Palette
Color
Hex
Usage
Green
#2ECC71
Success, completed
Red
#E74C3C
Error, critical
Orange
#F39C12
Warning, action
Blue
#3498DB
Info, process
Gray
#95A5A6
Neutral, disabled
Purple
#9B59B6
Concept, idea
Cyan
#1ABC9C
Secondary
Yellow
#F1C40F
Highlight
Node Shapes
Common Shapes
Shape
Description
Usage
box
Rectangle
Process, action
ellipse
Ellipse (default)
General node
circle
Circle
State, event
diamond
Diamond
Decision
plaintext
No border
Labels
record
Structured
Data tables
cylinder
Cylinder
Database
folder
Folder
Directory
component
UML component
Module
house
House
Root
invhouse
Inverted house
Leaf
HTML Labels
digraph G {
node [shape=plaintext];
A [label=<
<TABLEBORDER="0"CELLBORDER="1"CELLSPACING="0"><TR><TDBGCOLOR="#3498DB"><FONTCOLOR="white">Header</FONT></TD></TR><TR><TD>Content</TD></TR></TABLE>
>];
}
Undirected Graphs
graph G {
rankdir=LR;
A -- B -- C;
B -- D;
}
Use graph instead of digraph, and -- instead of ->.