「Graphviz」- 常用设置

Graphviz Gallery

https://graphviz.org/gallery/
https://graphviz.gitlab.io/gallery/

Node

Node Shapes/Styles for Nodes
节点样式(style=):filled, invisible, diagonals, rounded, dashed, dotted, solid, bold

Q:是否能够对 rounded 指定 Radius 属性?
A:现在(Graphviz 2.43.0)暂不支持。graphviz – How to set the radius for rounded node style?

边框(Border)样式

Node Shapes/Polygon-based Nodes
边框形状(shape=):box; point; plaintext; plain; triangle; …

How can I hide the node boundary in graphviz?
去除边框:node [shape=plaintext]

背景(Background)填充

why doesn’t fillcolor work with graphviz? – Stack Overflow

nodeEdge0 [fixedsize=true,shape=diamond,label=".Nojjjj label.", fillcolor=red, style=filled]

字体(Font)配置

doxygen – how to change default font size for graphviz? – Stack Overflow
Graphviz: change font for the whole graph? – Stack Overflow
doxygen – how to change default font size for graphviz? – Stack Overflow

strict digraph {
	graph [ bgcolor=lightgray, resolution=128, fontname=Arial, fontcolor=blue, fontsize=12 ];
	node [ fontname=Arial, fontcolor=blue, fontsize=11];
	edge [ fontname=Helvetica, fontcolor=red, fontsize=10 ];
}

补充说明:fontname、fontsize 需要单独设置,而无法进行全局设置;

Edge

方向(dir=):back; both; …

避免 Edge 参与计算:[constraint=false]

outputorder | Specify order in which nodes and edges are drawn

breadthfirst, nodesfirst, edgesfirst

Edge : Arrow

arrowhead | 配置箭头样式

EDGE : Label

支持 HTML 标签(HTML-Like Labels)

HTML-Like Labels https://graphviz.org/doc/info/shapes.html#html

调整 Edge 和 Label 相对位置

使用 Edge 的属性 `taillabel`, `headlabel`, `labeldistance`, `labelangle`
使用 Label 的属性 `labeldistance` 和 `labelangle`。

`taillabel` 和 `headlabel` 属性可以将 Label 直接放置在 Edge 的起点和终点处,例如:

```
A -> B [taillabel="Start", headlabel="End"];
```

`labeldistance` 属性可以控制 Label 相对于 Edge 的位置,例如:

```
A -> B [label="Label", labeldistance=2];
```

`labelangle` 属性可以控制 Label 相对于 Edge 的旋转角度,例如:

```
A -> B [label="Label", labelangle=45];
```

同时,也可以使用 `xlabel` 和 `ylabel` 属性来为 Edge 添加额外的 Label,例如:

```
A -> B [xlabel="X-Label", ylabel="Y-Label"];
```

隐藏箭头

使用 `dir=none` 属性

添加边框

使用 Graphviz 的 HTML label 和 table 标签来添加 label 的边框:

digraph {
    node [shape=box]
    A [label=<<table border="1" cellborder="0" cellspacing="0"><tr><td>A</td></tr></table>>]
    B [label=<<table border="1" cellborder="0" cellspacing="0"><tr><td>B</td></tr></table>>]
    A -> B
}