Graphviz:树结构
Graphviz: tree structure
我想使用 graphviz 生成结构树,从左到右的结构(请忽略颜色):
我得出的结论是我需要使用不可见节点来实现它,我当前的代码如下所示:
digraph G {
node [ shape="box", width = 2, height = 1, fixedsize=true];
edge [arrowhead=none];
nodesep = 1;
ranksep=0.05;
splines = ortho;
rankdir = LR;
A1 [ shape="box", width = 2, height = 1, fixedsize=true];
B1 [ shape="box", width = 2, height = 1, fixedsize=true];
B2 [ shape="box", width = 2, height = 1, fixedsize=true];
B3 [ shape="box", width = 2, height = 1, fixedsize=true];
B4 [ shape="box", width = 2, height = 1, fixedsize=true];
B5 [ shape="box", width = 2, height = 1, fixedsize=true];
B6 [ shape="box", width = 2, height = 1, fixedsize=true];
W0 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W1 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W2 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W3 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W4 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W5 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W6 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
subgraph {
A1 -> W0
W0 -> W3
W3 -> W2
W2 -> W1
W0 -> W4
W4 -> W5
W5 -> W6
W1 -> B1
W2 -> B2
W3 -> B3
W4 -> B4
W5 -> B5
W6 -> B6
{rank = same; A1;}
{rank = same; B1; B2; B3; B4; B5; B6;}
{rank = same; W0; W1; W2; W3; W4; W5; W6;}
}
}
使用点引擎我得到:
我的问题:
我可以强制某些节点占据中心位置 (A1) 吗?
我可以强制边连接到节点形状边界上的特定位置(例如:左中)吗?
也许有更好的方法来实现这种以节点为中心的树结构(我必须考虑到树的下一层可能会非常复杂)
为了得到你想要的,你需要
- 按照您希望绘制节点的顺序定义节点(在此处给出的示例中不是绝对必要的,但很好的做法)
- 确保空节点处于同一等级(您已经拥有)
- 并将这些空节点以正确的顺序相互连接(这是这里的关键项)
应用这些更改,并简单地修改您的代码(您可能喜欢或不喜欢,这就是我的做法),我得到
digraph G {
edge [arrowhead=none];
nodesep = 1;
ranksep=0.05;
splines = ortho;
rankdir = LR;
node [ shape="box", width = 2, height = 1, fixedsize=true];
A1;
B4 B5 B6 B3 B2 B1;
node [ shape="point", width = 0, height = 0 ];
{ rank = same; W4 W5 W6 W0 W3 W2 W1 }
A1 -> W0;
W4 -> W5 -> W6 -> W0 -> W3 -> W2 -> W1; /* critical! */
W1 -> B1;
W2 -> B2;
W3 -> B3;
W4 -> B4;
W5 -> B5;
W6 -> B6;
}
产生
我想使用 graphviz 生成结构树,从左到右的结构(请忽略颜色):
我得出的结论是我需要使用不可见节点来实现它,我当前的代码如下所示:
digraph G {
node [ shape="box", width = 2, height = 1, fixedsize=true];
edge [arrowhead=none];
nodesep = 1;
ranksep=0.05;
splines = ortho;
rankdir = LR;
A1 [ shape="box", width = 2, height = 1, fixedsize=true];
B1 [ shape="box", width = 2, height = 1, fixedsize=true];
B2 [ shape="box", width = 2, height = 1, fixedsize=true];
B3 [ shape="box", width = 2, height = 1, fixedsize=true];
B4 [ shape="box", width = 2, height = 1, fixedsize=true];
B5 [ shape="box", width = 2, height = 1, fixedsize=true];
B6 [ shape="box", width = 2, height = 1, fixedsize=true];
W0 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W1 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W2 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W3 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W4 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W5 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
W6 [ shape="circle", width = 0, height = 0, fixedsize=true, label=""];
subgraph {
A1 -> W0
W0 -> W3
W3 -> W2
W2 -> W1
W0 -> W4
W4 -> W5
W5 -> W6
W1 -> B1
W2 -> B2
W3 -> B3
W4 -> B4
W5 -> B5
W6 -> B6
{rank = same; A1;}
{rank = same; B1; B2; B3; B4; B5; B6;}
{rank = same; W0; W1; W2; W3; W4; W5; W6;}
}
}
使用点引擎我得到:
我的问题:
我可以强制某些节点占据中心位置 (A1) 吗?
我可以强制边连接到节点形状边界上的特定位置(例如:左中)吗?
也许有更好的方法来实现这种以节点为中心的树结构(我必须考虑到树的下一层可能会非常复杂)
为了得到你想要的,你需要
- 按照您希望绘制节点的顺序定义节点(在此处给出的示例中不是绝对必要的,但很好的做法)
- 确保空节点处于同一等级(您已经拥有)
- 并将这些空节点以正确的顺序相互连接(这是这里的关键项)
应用这些更改,并简单地修改您的代码(您可能喜欢或不喜欢,这就是我的做法),我得到
digraph G {
edge [arrowhead=none];
nodesep = 1;
ranksep=0.05;
splines = ortho;
rankdir = LR;
node [ shape="box", width = 2, height = 1, fixedsize=true];
A1;
B4 B5 B6 B3 B2 B1;
node [ shape="point", width = 0, height = 0 ];
{ rank = same; W4 W5 W6 W0 W3 W2 W1 }
A1 -> W0;
W4 -> W5 -> W6 -> W0 -> W3 -> W2 -> W1; /* critical! */
W1 -> B1;
W2 -> B2;
W3 -> B3;
W4 -> B4;
W5 -> B5;
W6 -> B6;
}
产生