Graphviz:左右子图,子图中的左右子图
Graphviz: Left-Right subgraphs, Left-Right inside subgraphs
我想要实现的是并排的集群(子图),而它们的内容也是并排的,如图所示:
但我所能做的就是子图的上下行为,如图所示:
我知道这是一个悬而未决的问题 (Allow different rankdir for subgraph cluster)
但我也看到了类似问题的一些解决方法(即 top-down subgraphs, left-right inside subgraphs, GraphViz - How to have a subgraph be left-to-right when main graph is top-to-bottom?)
根据解决方法,我可以获得对角线表示:
但不是想要的。
这是我的 .Dot 文件:
digraph {
node [shape=plain]
rankdir=LR;
subgraph cluster_Asia {
label = "Asia";
China [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>China</i></td></tr>
<tr><td bgcolor="yellow" port="Shanghai">Shanghai</td></tr>
<tr><td bgcolor="white" port="Beijing">Beijing</td></tr>
<tr><td bgcolor="white" port="Chongqing">Chongqing</td></tr>
<tr><td bgcolor="white" port="Tianjin">Tianjin</td></tr>
</table>>];
India [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>India</i></td></tr>
<tr><td bgcolor="yellow" port="NewDelhi">NewDelhi</td></tr>
<tr><td bgcolor="white" port="Mumbai">Mumbai</td></tr>
<tr><td bgcolor="white" port="Bangalore">Bangalore</td></tr>
<tr><td bgcolor="white" port="Ahmadabad">Ahmadabad</td></tr>
</table>>];
Thailand [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Thailand</i></td></tr>
<tr><td bgcolor="yellow" port="Bangkok">Bangkok</td></tr>
<tr><td bgcolor="white" port="ChiangRai">ChiangRai</td></tr>
</table>>];
Nepal [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Nepal</i></td></tr>
<tr><td bgcolor="yellow" port="Kathmandu">Kathmandu</td></tr>
<tr><td bgcolor="white" port="Birgunj">Birgunj</td></tr>
</table>>];
China:Shanghai->Thailand:Bangkok[color="blue", style=solid ]
China:Beijing->Nepal:Kathmandu[color="blue", style=solid ]
China:Tianjin->India:NewDelhi[color="blue",style=solid ]
China:Chongqing->India:Ahmadabad[color="blue", style=solid ]
India:Ahmadabad->India:Mumbai[color="blue", style=solid ]
}
subgraph cluster_Europe {
label = "Europe";
Spain [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Spain</i></td></tr>
<tr><td bgcolor="yellow" port="Madrid">Madrid</td></tr>
<tr><td bgcolor="white" port="Malaga">Malaga</td></tr>
<tr><td bgcolor="white" port="Barcelona">Barcelona</td></tr>
<tr><td bgcolor="white" port="Valencia">Valencia</td></tr>
</table>>];
Netherlands [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Netherlands</i></td></tr>
<tr><td bgcolor="yellow" port="Amsterdam">Amsterdam</td></tr>
<tr><td bgcolor="white" port="Rotterdam">Rotterdam</td></tr>
<tr><td bgcolor="white" port="Dokkum">Dokkum</td></tr>
</table>>];
Italy [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Italy</i></td></tr>
<tr><td bgcolor="yellow" port="Rome">Rome</td></tr>
<tr><td bgcolor="white" port="Venice">Venice</td></tr>
<tr><td bgcolor="white" port="Milan">Milan</td></tr>
</table>>];
France [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>France</i></td></tr>
<tr><td bgcolor="yellow" port="Paris">Paris</td></tr>
<tr><td bgcolor="white" port="Nice">Nice</td></tr>
<tr><td bgcolor="white" port="Marseille">Marseille</td></tr>
</table>>];
Spain:Madrid->Netherlands:Dokkum[ color="blue",style=solid ]
Spain:Barcelona->Italy:Milan[ color="blue",style=solid ]
Spain:Malaga->Netherlands:Amsterdam[color="blue", style=solid ]
Spain:Valencia->France:Nice[color="blue", style=solid ]
}
// { rank=same;
// 00 [style=invis];
// 01 [style=invis];
// 00 -> 01 [constraint=false,style=invis];
// }
// 00 -> Spain [style=invis];
// 01 -> China [style=invis];
// Spain -> China [ style=invis];
}
请注意,代码范围底部的对角线代码被注释掉了。
我的问题:
如何更改我的代码以获得与第一张图片尽可能相似的结果?
感谢 Albert 的评论,我找到了解决方案:
这是代码:
digraph {
node [shape=plain]
rankdir=LR;
subgraph cluster_Asia {
label = "Asia";
China [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>China</i></td></tr>
<tr><td bgcolor="yellow" port="Shanghai">Shanghai</td></tr>
<tr><td bgcolor="white" port="Beijing">Beijing</td></tr>
<tr><td bgcolor="white" port="Chongqing">Chongqing</td></tr>
<tr><td bgcolor="white" port="Tianjin">Tianjin</td></tr>
</table>>];
India [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>India</i></td></tr>
<tr><td bgcolor="yellow" port="NewDelhi">NewDelhi</td></tr>
<tr><td bgcolor="white" port="Mumbai">Mumbai</td></tr>
<tr><td bgcolor="white" port="Bangalore">Bangalore</td></tr>
<tr><td bgcolor="white" port="Ahmadabad">Ahmadabad</td></tr>
</table>>];
Thailand [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Thailand</i></td></tr>
<tr><td bgcolor="yellow" port="Bangkok">Bangkok</td></tr>
<tr><td bgcolor="white" port="ChiangRai">ChiangRai</td></tr>
</table>>];
Nepal [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Nepal</i></td></tr>
<tr><td bgcolor="yellow" port="Kathmandu">Kathmandu</td></tr>
<tr><td bgcolor="white" port="Birgunj">Birgunj</td></tr>
</table>>];
China:Shanghai->Thailand:Bangkok[color="blue", tyle=solid ]
China:Beijing->Nepal:Kathmandu[color="blue", style=solid ]
China:Tianjin->India:NewDelhi[color="blue",style=solid ]
China:Chongqing->India:Ahmadabad[color="blue", style=solid ]
India:Ahmadabad->India:Mumbai[color="blue", style=solid ]
}
subgraph cluster_Europe {
label = "Europe";
Spain [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Spain</i></td></tr>
<tr><td bgcolor="yellow" port="Madrid">Madrid</td></tr>
<tr><td bgcolor="white" port="Malaga">Malaga</td></tr>
<tr><td bgcolor="white" port="Barcelona">Barcelona</td></tr>
<tr><td bgcolor="white" port="Valencia">Valencia</td></tr>
</table>>];
Netherlands [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Netherlands</i></td></tr>
<tr><td bgcolor="yellow" port="Amsterdam">Amsterdam</td></tr>
<tr><td bgcolor="white" port="Rotterdam">Rotterdam</td></tr>
<tr><td bgcolor="white" port="Dokkum">Dokkum</td></tr>
</table>>];
Italy [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Italy</i></td></tr>
<tr><td bgcolor="yellow" port="Rome">Rome</td></tr>
<tr><td bgcolor="white" port="Venice">Venice</td></tr>
<tr><td bgcolor="white" port="Milan">Milan</td></tr>
</table>>];
France [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>France</i></td></tr>
<tr><td bgcolor="yellow" port="Paris">Paris</td></tr>
<tr><td bgcolor="white" port="Nice">Nice</td></tr>
<tr><td bgcolor="white" port="Marseille">Marseille</td></tr>
</table>>];
Spain:Madrid->Netherlands:Dokkum[ color="blue",style=solid ]
Spain:Barcelona->Italy:Milan[ color="blue",style=solid ]
Spain:Malaga->Netherlands:Amsterdam[color="blue", style=solid ]
Spain:Valencia->France:Nice[color="blue", style=solid ]
}
{
00 [style=invis];
01 [style=invis];
02 [style=invis];
03 [style=invis];
00 -> 01 -> 02 -> 03 [style=invis];
00 -> Spain [style=invis];
01 -> Netherlands [style=invis];
01 -> Italy [style=invis];
01 -> France [style=invis];
02 -> China [style=invis];
03 -> Nepal [style=invis];
03 -> Thailand [style=invis];
03 -> India [style=invis];
Spain -> China [ style=invis];
}
}
最后一个范围是修复布局。
我想要实现的是并排的集群(子图),而它们的内容也是并排的,如图所示:
但我所能做的就是子图的上下行为,如图所示:
我知道这是一个悬而未决的问题 (Allow different rankdir for subgraph cluster)
但我也看到了类似问题的一些解决方法(即 top-down subgraphs, left-right inside subgraphs, GraphViz - How to have a subgraph be left-to-right when main graph is top-to-bottom?)
根据解决方法,我可以获得对角线表示:
但不是想要的。
这是我的 .Dot 文件:
digraph {
node [shape=plain]
rankdir=LR;
subgraph cluster_Asia {
label = "Asia";
China [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>China</i></td></tr>
<tr><td bgcolor="yellow" port="Shanghai">Shanghai</td></tr>
<tr><td bgcolor="white" port="Beijing">Beijing</td></tr>
<tr><td bgcolor="white" port="Chongqing">Chongqing</td></tr>
<tr><td bgcolor="white" port="Tianjin">Tianjin</td></tr>
</table>>];
India [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>India</i></td></tr>
<tr><td bgcolor="yellow" port="NewDelhi">NewDelhi</td></tr>
<tr><td bgcolor="white" port="Mumbai">Mumbai</td></tr>
<tr><td bgcolor="white" port="Bangalore">Bangalore</td></tr>
<tr><td bgcolor="white" port="Ahmadabad">Ahmadabad</td></tr>
</table>>];
Thailand [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Thailand</i></td></tr>
<tr><td bgcolor="yellow" port="Bangkok">Bangkok</td></tr>
<tr><td bgcolor="white" port="ChiangRai">ChiangRai</td></tr>
</table>>];
Nepal [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Nepal</i></td></tr>
<tr><td bgcolor="yellow" port="Kathmandu">Kathmandu</td></tr>
<tr><td bgcolor="white" port="Birgunj">Birgunj</td></tr>
</table>>];
China:Shanghai->Thailand:Bangkok[color="blue", style=solid ]
China:Beijing->Nepal:Kathmandu[color="blue", style=solid ]
China:Tianjin->India:NewDelhi[color="blue",style=solid ]
China:Chongqing->India:Ahmadabad[color="blue", style=solid ]
India:Ahmadabad->India:Mumbai[color="blue", style=solid ]
}
subgraph cluster_Europe {
label = "Europe";
Spain [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Spain</i></td></tr>
<tr><td bgcolor="yellow" port="Madrid">Madrid</td></tr>
<tr><td bgcolor="white" port="Malaga">Malaga</td></tr>
<tr><td bgcolor="white" port="Barcelona">Barcelona</td></tr>
<tr><td bgcolor="white" port="Valencia">Valencia</td></tr>
</table>>];
Netherlands [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Netherlands</i></td></tr>
<tr><td bgcolor="yellow" port="Amsterdam">Amsterdam</td></tr>
<tr><td bgcolor="white" port="Rotterdam">Rotterdam</td></tr>
<tr><td bgcolor="white" port="Dokkum">Dokkum</td></tr>
</table>>];
Italy [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Italy</i></td></tr>
<tr><td bgcolor="yellow" port="Rome">Rome</td></tr>
<tr><td bgcolor="white" port="Venice">Venice</td></tr>
<tr><td bgcolor="white" port="Milan">Milan</td></tr>
</table>>];
France [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>France</i></td></tr>
<tr><td bgcolor="yellow" port="Paris">Paris</td></tr>
<tr><td bgcolor="white" port="Nice">Nice</td></tr>
<tr><td bgcolor="white" port="Marseille">Marseille</td></tr>
</table>>];
Spain:Madrid->Netherlands:Dokkum[ color="blue",style=solid ]
Spain:Barcelona->Italy:Milan[ color="blue",style=solid ]
Spain:Malaga->Netherlands:Amsterdam[color="blue", style=solid ]
Spain:Valencia->France:Nice[color="blue", style=solid ]
}
// { rank=same;
// 00 [style=invis];
// 01 [style=invis];
// 00 -> 01 [constraint=false,style=invis];
// }
// 00 -> Spain [style=invis];
// 01 -> China [style=invis];
// Spain -> China [ style=invis];
}
请注意,代码范围底部的对角线代码被注释掉了。
我的问题:
如何更改我的代码以获得与第一张图片尽可能相似的结果?
感谢 Albert 的评论,我找到了解决方案:
这是代码:
digraph {
node [shape=plain]
rankdir=LR;
subgraph cluster_Asia {
label = "Asia";
China [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>China</i></td></tr>
<tr><td bgcolor="yellow" port="Shanghai">Shanghai</td></tr>
<tr><td bgcolor="white" port="Beijing">Beijing</td></tr>
<tr><td bgcolor="white" port="Chongqing">Chongqing</td></tr>
<tr><td bgcolor="white" port="Tianjin">Tianjin</td></tr>
</table>>];
India [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>India</i></td></tr>
<tr><td bgcolor="yellow" port="NewDelhi">NewDelhi</td></tr>
<tr><td bgcolor="white" port="Mumbai">Mumbai</td></tr>
<tr><td bgcolor="white" port="Bangalore">Bangalore</td></tr>
<tr><td bgcolor="white" port="Ahmadabad">Ahmadabad</td></tr>
</table>>];
Thailand [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Thailand</i></td></tr>
<tr><td bgcolor="yellow" port="Bangkok">Bangkok</td></tr>
<tr><td bgcolor="white" port="ChiangRai">ChiangRai</td></tr>
</table>>];
Nepal [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Nepal</i></td></tr>
<tr><td bgcolor="yellow" port="Kathmandu">Kathmandu</td></tr>
<tr><td bgcolor="white" port="Birgunj">Birgunj</td></tr>
</table>>];
China:Shanghai->Thailand:Bangkok[color="blue", tyle=solid ]
China:Beijing->Nepal:Kathmandu[color="blue", style=solid ]
China:Tianjin->India:NewDelhi[color="blue",style=solid ]
China:Chongqing->India:Ahmadabad[color="blue", style=solid ]
India:Ahmadabad->India:Mumbai[color="blue", style=solid ]
}
subgraph cluster_Europe {
label = "Europe";
Spain [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Spain</i></td></tr>
<tr><td bgcolor="yellow" port="Madrid">Madrid</td></tr>
<tr><td bgcolor="white" port="Malaga">Malaga</td></tr>
<tr><td bgcolor="white" port="Barcelona">Barcelona</td></tr>
<tr><td bgcolor="white" port="Valencia">Valencia</td></tr>
</table>>];
Netherlands [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Netherlands</i></td></tr>
<tr><td bgcolor="yellow" port="Amsterdam">Amsterdam</td></tr>
<tr><td bgcolor="white" port="Rotterdam">Rotterdam</td></tr>
<tr><td bgcolor="white" port="Dokkum">Dokkum</td></tr>
</table>>];
Italy [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>Italy</i></td></tr>
<tr><td bgcolor="yellow" port="Rome">Rome</td></tr>
<tr><td bgcolor="white" port="Venice">Venice</td></tr>
<tr><td bgcolor="white" port="Milan">Milan</td></tr>
</table>>];
France [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>France</i></td></tr>
<tr><td bgcolor="yellow" port="Paris">Paris</td></tr>
<tr><td bgcolor="white" port="Nice">Nice</td></tr>
<tr><td bgcolor="white" port="Marseille">Marseille</td></tr>
</table>>];
Spain:Madrid->Netherlands:Dokkum[ color="blue",style=solid ]
Spain:Barcelona->Italy:Milan[ color="blue",style=solid ]
Spain:Malaga->Netherlands:Amsterdam[color="blue", style=solid ]
Spain:Valencia->France:Nice[color="blue", style=solid ]
}
{
00 [style=invis];
01 [style=invis];
02 [style=invis];
03 [style=invis];
00 -> 01 -> 02 -> 03 [style=invis];
00 -> Spain [style=invis];
01 -> Netherlands [style=invis];
01 -> Italy [style=invis];
01 -> France [style=invis];
02 -> China [style=invis];
03 -> Nepal [style=invis];
03 -> Thailand [style=invis];
03 -> India [style=invis];
Spain -> China [ style=invis];
}
}
最后一个范围是修复布局。