添加新箭头时如何保持图形形式?
How to keep the graph form when adding new arrows?
我有这样的图表:
问题一:有没有办法让两列在顶部水平对齐?
如果我想要一个箭头 a5 -> a1
,那么图形将是:
问题 2:有没有办法让图表像以前一样干净?
代码如下:
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
a1
a2
a3
a4
a5
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1
b2
b3
b4
}
a1 -> b1
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1
}
需要两个小步骤:
(1) 将所有a
个节点放在同一个等级。如果不这样做,graphviz
会在 a1
和 a5
之间建立层次关系,这就是您的图表显示的内容。
(2) 在a1
和b1
之间的边缘增加一些额外的重量,以保持直线。
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
{rank = same; a1 a2 a3 a4 a5 } // !!!
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1
b2
b3
b4
}
a1 -> b1[ weight = 10 ]; // !!!
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1
}
现在生产
我将通过以下两个更改来解决此问题:
使用 constraint=false
以避免从 a5
到 a1
的边弄乱图形
使用group
属性建议节点之间的直边(与边连接时应放置在直线上的节点的相同属性值)
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
a1 [group=1]
a2
a3
a4
a5
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1 [group=1]
b2
b3
b4
}
a1 -> b1
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1 [constraint=false]
}
我有这样的图表:
问题一:有没有办法让两列在顶部水平对齐?
如果我想要一个箭头 a5 -> a1
,那么图形将是:
问题 2:有没有办法让图表像以前一样干净?
代码如下:
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
a1
a2
a3
a4
a5
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1
b2
b3
b4
}
a1 -> b1
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1
}
需要两个小步骤:
(1) 将所有a
个节点放在同一个等级。如果不这样做,graphviz
会在 a1
和 a5
之间建立层次关系,这就是您的图表显示的内容。
(2) 在a1
和b1
之间的边缘增加一些额外的重量,以保持直线。
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
{rank = same; a1 a2 a3 a4 a5 } // !!!
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1
b2
b3
b4
}
a1 -> b1[ weight = 10 ]; // !!!
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1
}
现在生产
我将通过以下两个更改来解决此问题:
使用
constraint=false
以避免从a5
到a1
的边弄乱图形使用
group
属性建议节点之间的直边(与边连接时应放置在直线上的节点的相同属性值)digraph { rankdir="LR"; // overlap=false; nodesep="0.2"; ranksep="0.4"; fontsize = 25 labelloc="t"; fontname="Lato"; node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ] edge [ fontname="Lato" color="#2B303A" ] subgraph cluster_0 { style=filled; color=lightgrey; label = "Column 1"; fontsize = 20 node [style=filled,color=white]; a1 [group=1] a2 a3 a4 a5 } subgraph cluster_1 { node [style=filled]; color=blue label = "Column 2"; fontsize = 20 // labeljust=r // labelloc=b b1 [group=1] b2 b3 b4 } a1 -> b1 b1 -> a2 a2 -> b2 b2 -> a3 a3 -> b3 b3 -> a4 a4 -> b4 b4 -> a5 a5 -> a1 [constraint=false] }