--- name: dot-syntax description: Use when writing or reading DOT/Graphviz code and needing quick syntax reference — node declarations, edge syntax, attributes, subgraphs, HTML labels, and common gotchas --- # DOT Syntax Quick Reference ## Overview Fast lookup for DOT graph description language syntax. Covers the constructs you'll use 90% of the time. **Core principle:** DOT describes structure (what connects to what). Layout engines handle positioning. You never specify coordinates. ## Graph Declaration ```dot digraph name { } // directed graph (use ->) graph name { } // undirected graph (use --) strict digraph name { } // no multi-edges allowed ``` ## Nodes ```dot my_node // implicit creation my_node [label="Display Name" shape=box] // explicit with attributes my_node [label="Line 1\nLine 2"] // multiline label "node with spaces" // quoted ID for special chars ``` **ID rules:** `[a-zA-Z_][a-zA-Z_0-9]*` unquoted. Use quotes for spaces/special chars. ## Edges ```dot A -> B // directed edge A -> B [label="calls"] // labeled edge A -> B -> C // chain A -> {B C D} // fan-out (A connects to B, C, and D) A -> B [style=dashed color=red] // styled edge ``` ## Attributes ```dot // Defaults (apply to all subsequent nodes/edges) node [shape=box style="rounded,filled" fillcolor="#E8F0FE" fontname="Helvetica"] edge [color="#666666" fontsize=10] graph [rankdir=TB nodesep=0.5] // Per-element (override defaults) my_node [shape=diamond fillcolor="#FFF9C4"] A -> B [color=blue penwidth=2] ``` ## Shapes Quick Table | Shape | Description | |-------|-------------| | `box` / `rectangle` | Rectangle (default-ish) | | `ellipse` | Oval (true default) | | `circle` | Equal width/height ellipse | | `diamond` | Decision / branch | | `hexagon` | Process step | | `cylinder` | Database / storage | | `note` | Document with folded corner | | `folder` | Folder tab shape | | `parallelogram` | Skewed rectangle | | `doublecircle` | Final state (state machines) | | `plaintext` | No border (label only) | ## Subgraphs and Clusters ```dot // Cluster — name MUST start with cluster_ subgraph cluster_group { label="Group Name" style=filled fillcolor="#F0F0F0" A; B; C } // Rank control — force nodes to same level subgraph { rank=same; A; B; C } // rank values: same | min | max | source | sink // Edges between clusters (needs compound=true on graph) digraph G { compound=true subgraph cluster_a { A } subgraph cluster_b { B } A -> B [ltail=cluster_a lhead=cluster_b] } ``` ## HTML Labels Use `<...>` instead of `"..."` for the label value: ```dot node [label=<
| Left | Right |