# Graphviz note
```graphviz
digraph snakemake_dag {
graph[bgcolor=white, margin=0];
node[shape=box, style=rounded, fontname=sans, fontsize=10, penwidth=2];
edge[penwidth=2, color=grey];
0[label = "all", color = "0.03 0.6 0.85", style="rounded"];
1[label = "reformat", color = "0.43 0.6 0.85", style="rounded"];
2[label = "harmony\npipeline: profiles_var_mad_int_featselect", color = "0.30 0.6 0.85", style="rounded"];
3[label = "featselect\npipeline: profiles_var_mad_int", color = "0.27 0.6 0.85", style="rounded"];
4[label = "INT\npipeline: profiles_var_mad", color = "0.00 0.6 0.85", style="rounded"];
5[label = "mad_normalize", color = "0.33 0.6 0.85", style="rounded"];
6[label = "select_variant_feats", color = "0.53 0.6 0.85", style="rounded"];
7[label = "write_parquet\nscenario: compound", color = "0.63 0.6 0.85", style="rounded"];
8[label = "compute_norm_stats\npipeline: profiles", color = "0.20 0.6 0.85", style="rounded"];
9[label = "compute_norm_stats\npipeline: profiles_var", color = "0.20 0.6 0.85", style="rounded"];
10[label = "average_precision_nonrep\npipeline: profiles_var_mad_int_featselect_harmony\nprefix: compound", color = "0.13 0.6 0.85", style="rounded"];
11[label = "mean_average_precision\nreftype: nonrep", color = "0.37 0.6 0.85", style="rounded"];
1 -> 0
10 -> 0
11 -> 0
2 -> 1
3 -> 2
4 -> 3
5 -> 4
6 -> 5
9 -> 5
7 -> 6
8 -> 6
7 -> 8
6 -> 9
2 -> 10
10 -> 11
}
```
```graphviz
digraph g{
node0 [fillcolor="green"];
node1 [fillcolor="green"];
node2 [fillcolor="green"];
node3 [fillcolor="green"];
node4 [fillcolor="green"];
node5 [fillcolor="green"];
node6 [fillcolor="green"];
node7 [fillcolor="green"];
node8 [fillcolor="green"];
node9 [fillcolor="green"];
node10 [color="orange"];
node11 [color="orange"];
node12 [color="orange"];
node13 [color="orange"];
node14 [color="orange"];
node15 [color="orange"];
node16 [color="orange"];
node17 [color="orange"];
node18 [color="orange"];
node19 [color="orange"];
node20 [color="orange"];
node21 [color="orange"];
node22 [color="orange"];
node23 [color="orange"];
node24 [color="orange"];
node25 [color="orange"];
node26 [color="orange"];
node27 [color="orange"];
node28 [color="orange"];
node29 [color="orange"];
node30 [color="orange"];
node31 [color="orange"];
node32 [color="orange"];
node33 [color="orange"];
node34 [color="orange"];
node35 [color="orange"];
node36 [color="orange"];
node37 [color="orange"];
node38 [color="orange"];
node39 [color="orange"];
node40 [color="orange"];
node41 [color="orange"];
node42 [color="orange"];
node43 [color="orange"];
node44 [color="orange"];
node45 [color="orange"];
node46 [color="orange"];
node47 [color="orange"];
node48 [color="orange"];
node49 [color="orange"];
node1 -> node11;
node2 -> node11;
node11 -> node21;
node2 -> node12;
node3 -> node12;
node12 -> node21;
node21 -> node31;
node12 -> node22;
node3 -> node13;
node4 -> node13;
node13 -> node22;
node22 -> node31;
node31 -> node41;
node22 -> node32;
node13 -> node23;
node4 -> node14;
node5 -> node14;
node14 -> node23;
node23 -> node32;
node32 -> node41;
node14 -> node24;
node5 -> node15;
node6 -> node15;
node15 -> node24;
node24 -> node34;
node15 -> node25;
node6 -> node16;
node7 -> node16;
node16 -> node25;
node25 -> node34;
node34 -> node44;
node25 -> node35;
node16 -> node26;
node7 -> node17;
node8 -> node17;
node17 -> node26;
node26 -> node35;
node35 -> node44;
node1 -> node11;
node2 -> node11;
node11 -> node21;
node12 -> node21;
node21 -> node31;
node22 -> node31;
node31 -> node41;
node32 -> node41;
}
```
```graphviz
graph g{
a -- b;
b -- c;
c -- d;
d -- a;
}
```
### 有向圖 Digraph
```graphviz
digraph dg{
controller -> web1 ;
controller -> web2;
controller -> web3;
}
```
### Edges style
```graphviz
graph cg{
a -- b [color="#0F4D92 ", penwidth=3, label=1];
a -- c;
a -- d [color=blue, penwidth=3, label=4];
b -- c [color=green, penwidth=3, label=2];
b -- d;
c -- d [color=yellow, penwidth=3, label=3];
}
```
### Subgraphs
```graphviz
digraph {
subgraph cluster_0{
label="Subgraph A";
a; b; c; d;
c -> d;
}
subgraph cluster_1{
label="Subgraph B";
f; c;
f -> c;
}
a -> {b f}
b -> c
}
```
## Attributes
### graph
* label="My Graph";Label a graph itself
* __rankdir=LR;Lay the graph out from Left to Right, instead of Top to Bottom__
* {rank=same; a, b, c }Group nodes together at the same level of a graph
* splines="line";Force edges to be straight, no curves or angles
* K=0.6;Used to influence the 'spring' used in the layout, Can be used to push nodes further apart, which is especially useful for twopi and sfdp layouts
### vertex
* [label="Some Label"]Labels the Vertex
* [color="red"]Colors the Vertex
* [fillcolor="blue"]Fills the Vertex with the specified colour
### dege
* [label="Some Label"]Labels the Edge (Useful for Weights)
* [color="red"]Colors the Vertex (Useful for Paths)
* [penwidth=2.0]Adjusts the thickness of the edge line, Very useful for Paths
## References
1. [GraphViz Pocket Reference](https://graphs.grevian.org/)
## Playground
```graphviz
digraph G {
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "process #1";
}
subgraph cluster_1 {
node [style=filled];
b0 -> b1 -> b2 -> b3;
label = "process #2";
color=blue
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
```
```graphviz
digraph G {
randdir="LR"
subgraph cluster_0 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
a0 -> a1 -> a2 -> a3;
label = "初始化";
}
subgraph cluster_1 {
node [style=filled];
b0 -> b1 -> b2 -> b3;
label = "process #2";
color=blue
}
start -> a0;
start -> b0;
a1 -> b3;
b2 -> a3;
a3 -> a0;
a3 -> end;
b3 -> end;
start [shape=Mdiamond];
end [shape=Msquare];
}
```
$$
\begin{equation}
f(x)=
\begin{cases}
\frac{x^2-x}{x},& \text{if } x\geq 1\\
0, & \text{otherwise}
\end{cases}
\end{equation}
$$