我正在试图绘制一个GraphViz图(使用2.38.0 (20140413.2041)
版本),并且很难让它按照我想要的方式绘制。我尝试了许多隐藏边、约束操作、子图(包括集群和非集群)等不同的组合,但是似乎什么都没有做我想做的事情。
以下是我的当前代码:
digraph G {
subgraph clustera {
style=invis;rank=same
A->B->C
}
subgraph clusterb {
style=invis;rank=same;rankdir=LR
D->E [constraint=false]
}
subgraph clusterc {
style=invis;rank=same
F->G [constraint=false]
}
C -> D
D -> F [constraint=false]
E -> C
F -> A [constraint=false]
F -> C [constraint=false]
F -> E [constraint=false]
}
下面是它如何使用dot -Tpng
呈现的
(所有F
边都关闭了“约束”,因为几乎任何其他东西都会严重地扭曲图形。)
我想要的是:
F
(节点G
)F
和G
或多或少垂直地以图形为中心F
和G
通过E
在A
的右边A
通过E
或多或少地在他们现在的安排中F
到A
、C
和E
以及从D
到F
的边缘,大致遵循直线(即不绕F
/G
组的右侧路由)。A
通过C
正确地在D
和E
之上居中,但这并不重要。(我非常不希望F
出现在A
之上,就好像它是图形的根一样。)
下面是我正在寻找的东西的近似值,用yEd手工布局:
这在GraphViz中可行吗?
(我应该指出,我非常愿意使用其他GraphViz工具之一,只是dot
是我唯一熟悉的工具。)
发布于 2015-02-15 12:17:24
这里是我的方法,没有subgraphs
和weigth
,只有group
对节点垂直排列,constraint=false
和dir=back
保持布局失真。
digraph G {
// nodes without a group
D;
E;
// group left side
node[group=left];
A -> B -> C -> D;
C -> E [dir=back];
D -> E [constraint=false];
// group right side
node[group=right];
F -> G;
// inter group edges
F -> C;
edge [constraint=false];
D -> F;
F -> A;
F -> E;
}
结果在这里可以看到,并对应于你的近似。
发布于 2015-03-09 12:18:29
用一点自由来解释您的需求,您可能有一个没有边交叉的图。
digraph G { rankdir = LR ranksep = 1.2 nodesep = 0.5
{ rank=same A -> B -> C -> D -> E }
D -> F
{ rank=same F -> G }
edge [constraint=false]
E -> C
F -> A
F -> C
F -> E
}
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<!-- Generated by graphviz version 2.28.0 (20110507.0327)
-->
<!-- Title: G Pages: 1 -->
<svg width="250pt" height="332pt" viewBox="0.00 0.00 250.29 332.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph1" class="graph" transform="scale(1 1) rotate(0) translate(4 328)">
<title>G</title>
<polygon fill="white" stroke="white" points="-4,5 -4,-328 247.294,-328 247.294,5 -4,5"></polygon>
<!-- A -->
<g id="node2" class="node"><title>A</title>
<ellipse fill="none" stroke="black" cx="75.2936" cy="-306" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="75.2936" y="-301.8" font-family="Times,serif" font-size="14.00">A</text>
</g>
<!-- B -->
<g id="node4" class="node"><title>B</title>
<ellipse fill="none" stroke="black" cx="75.2936" cy="-234" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="75.2936" y="-229.8" font-family="Times,serif" font-size="14.00">B</text>
</g>
<!-- A->B -->
<g id="edge3" class="edge"><title>A->B</title>
<path fill="none" stroke="black" d="M75.2936,-287.859C75.2936,-279.268 75.2936,-270.677 75.2936,-262.085"></path>
<polygon fill="black" stroke="black" points="78.7937,-262 75.2936,-252 71.7937,-262 78.7937,-262"></polygon>
</g>
<!-- C -->
<g id="node5" class="node"><title>C</title>
<ellipse fill="none" stroke="black" cx="75.2936" cy="-162" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="75.2936" y="-157.8" font-family="Times,serif" font-size="14.00">C</text>
</g>
<!-- B->C -->
<g id="edge4" class="edge"><title>B->C</title>
<path fill="none" stroke="black" d="M75.2936,-215.859C75.2936,-207.268 75.2936,-198.677 75.2936,-190.085"></path>
<polygon fill="black" stroke="black" points="78.7937,-190 75.2936,-180 71.7937,-190 78.7937,-190"></polygon>
</g>
<!-- D -->
<g id="node6" class="node"><title>D</title>
<ellipse fill="none" stroke="black" cx="75.2936" cy="-90" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="75.2936" y="-85.8" font-family="Times,serif" font-size="14.00">D</text>
</g>
<!-- C->D -->
<g id="edge5" class="edge"><title>C->D</title>
<path fill="none" stroke="black" d="M75.2936,-143.859C75.2936,-135.268 75.2936,-126.677 75.2936,-118.085"></path>
<polygon fill="black" stroke="black" points="78.7937,-118 75.2936,-108 71.7937,-118 78.7937,-118"></polygon>
</g>
<!-- E -->
<g id="node7" class="node"><title>E</title>
<ellipse fill="none" stroke="black" cx="75.2936" cy="-18" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="75.2936" y="-13.8" font-family="Times,serif" font-size="14.00">E</text>
</g>
<!-- D->E -->
<g id="edge6" class="edge"><title>D->E</title>
<path fill="none" stroke="black" d="M75.2936,-71.8594C75.2936,-63.2681 75.2936,-54.6768 75.2936,-46.0854"></path>
<polygon fill="black" stroke="black" points="78.7937,-46 75.2936,-36 71.7937,-46 78.7937,-46"></polygon>
</g>
<!-- F -->
<g id="node9" class="node"><title>F</title>
<ellipse fill="none" stroke="black" cx="215.294" cy="-90" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="215.294" y="-85.8" font-family="Times,serif" font-size="14.00">F</text>
</g>
<!-- D->F -->
<g id="edge8" class="edge"><title>D->F</title>
<path fill="none" stroke="black" d="M102.575,-90C123.965,-90 154.385,-90 178.082,-90"></path>
<polygon fill="black" stroke="black" points="178.11,-93.5001 188.11,-90 178.11,-86.5001 178.11,-93.5001"></polygon>
</g>
<!-- E->C -->
<g id="edge13" class="edge"><title>E->C</title>
<path fill="none" stroke="black" d="M52.7625,-28.3877C36.2645,-37.3556 15.1112,-52.027 5.2936,-72 -1.76453,-86.3591 -1.76453,-93.6409 5.2936,-108 13.4238,-124.54 29.3279,-137.445 43.9243,-146.485"></path>
<polygon fill="black" stroke="black" points="42.3564,-149.621 52.7625,-151.612 45.8691,-143.567 42.3564,-149.621"></polygon>
</g>
<!-- F->A -->
<g id="edge15" class="edge"><title>F->A</title>
<path fill="none" stroke="black" d="M204.475,-106.621C185.434,-138.661 141.876,-211.016 102.294,-270 99.7106,-273.849 96.9068,-277.876 94.1283,-281.785"></path>
<polygon fill="black" stroke="black" points="91.1877,-279.879 88.1817,-290.038 96.8671,-283.971 91.1877,-279.879"></polygon>
</g>
<!-- F->C -->
<g id="edge17" class="edge"><title>F->C</title>
<path fill="none" stroke="black" d="M193.492,-100.853C170.263,-112.973 132.471,-132.69 106.103,-146.447"></path>
<polygon fill="black" stroke="black" points="104.2,-143.492 96.9536,-151.221 107.438,-149.698 104.2,-143.492"></polygon>
</g>
<!-- F->E -->
<g id="edge19" class="edge"><title>F->E</title>
<path fill="none" stroke="black" d="M193.492,-79.1472C170.263,-67.0274 132.471,-47.31 106.103,-33.5528"></path>
<polygon fill="black" stroke="black" points="107.438,-30.3018 96.9536,-28.7791 104.2,-36.5079 107.438,-30.3018"></polygon>
</g>
<!-- G -->
<g id="node12" class="node"><title>G</title>
<ellipse fill="none" stroke="black" cx="215.294" cy="-18" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="215.294" y="-13.8" font-family="Times,serif" font-size="14.00">G</text>
</g>
<!-- F->G -->
<g id="edge11" class="edge"><title>F->G</title>
<path fill="none" stroke="black" d="M215.294,-71.8594C215.294,-63.2681 215.294,-54.6768 215.294,-46.0854"></path>
<polygon fill="black" stroke="black" points="218.794,-46 215.294,-36 211.794,-46 218.794,-46"></polygon>
</g>
</g>
</svg>
另一种选择是底部节点位于相同的高度上。
digraph G { rankdir = LR ranksep = 1.2 nodesep = 0.5
{ rank=same A -> B -> C -> D }
D -> E
B -> F [style=invis]
{ rank=same F -> G }
edge [constraint=false]
E -> C
F -> A
F:w -> C
D -> F
F:e -> E:e
}
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<!-- Generated by graphviz version 2.28.0 (20110507.0327)
-->
<!-- Title: G Pages: 1 -->
<svg width="250pt" height="260pt" viewBox="0.00 0.00 250.27 260.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph1" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
<title>G</title>
<polygon fill="white" stroke="white" points="-4,5 -4,-256 247.27,-256 247.27,5 -4,5"></polygon>
<!-- A -->
<g id="node2" class="node"><title>A</title>
<ellipse fill="none" stroke="black" cx="27" cy="-234" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="27" y="-229.8" font-family="Times,serif" font-size="14.00">A</text>
</g>
<!-- B -->
<g id="node4" class="node"><title>B</title>
<ellipse fill="none" stroke="black" cx="27" cy="-162" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="27" y="-157.8" font-family="Times,serif" font-size="14.00">B</text>
</g>
<!-- A->B -->
<g id="edge3" class="edge"><title>A->B</title>
<path fill="none" stroke="black" d="M27,-215.859C27,-207.268 27,-198.677 27,-190.085"></path>
<polygon fill="black" stroke="black" points="30.5001,-190 27,-180 23.5001,-190 30.5001,-190"></polygon>
</g>
<!-- C -->
<g id="node5" class="node"><title>C</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="27" y="-85.8" font-family="Times,serif" font-size="14.00">C</text>
</g>
<!-- B->C -->
<g id="edge4" class="edge"><title>B->C</title>
<path fill="none" stroke="black" d="M27,-143.859C27,-135.268 27,-126.677 27,-118.085"></path>
<polygon fill="black" stroke="black" points="30.5001,-118 27,-108 23.5001,-118 30.5001,-118"></polygon>
</g>
<!-- F -->
<g id="node10" class="node"><title>F</title>
<ellipse fill="none" stroke="black" cx="167" cy="-162" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="167" y="-157.8" font-family="Times,serif" font-size="14.00">F</text>
</g>
<!-- B->F -->
<!-- D -->
<g id="node6" class="node"><title>D</title>
<ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="27" y="-13.8" font-family="Times,serif" font-size="14.00">D</text>
</g>
<!-- C->D -->
<g id="edge5" class="edge"><title>C->D</title>
<path fill="none" stroke="black" d="M27,-71.8594C27,-63.2681 27,-54.6768 27,-46.0854"></path>
<polygon fill="black" stroke="black" points="30.5001,-46 27,-36 23.5001,-46 30.5001,-46"></polygon>
</g>
<!-- E -->
<g id="node8" class="node"><title>E</title>
<ellipse fill="none" stroke="black" cx="167" cy="-18" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="167" y="-13.8" font-family="Times,serif" font-size="14.00">E</text>
</g>
<!-- D->E -->
<g id="edge7" class="edge"><title>D->E</title>
<path fill="none" stroke="black" d="M54.2816,-18C75.6717,-18 106.092,-18 129.789,-18"></path>
<polygon fill="black" stroke="black" points="129.816,-21.5001 139.816,-18 129.816,-14.5001 129.816,-21.5001"></polygon>
</g>
<!-- D->F -->
<g id="edge20" class="edge"><title>D->F</title>
<path fill="none" stroke="black" d="M42.2487,-32.8682C66.5235,-58.1984 116.031,-109.859 144.521,-139.587"></path>
<polygon fill="black" stroke="black" points="142.176,-142.199 151.622,-146.997 147.23,-137.355 142.176,-142.199"></polygon>
</g>
<!-- E->C -->
<g id="edge14" class="edge"><title>E->C</title>
<path fill="none" stroke="black" d="M145.199,-28.8528C121.969,-40.9726 84.1776,-60.69 57.8095,-74.4472"></path>
<polygon fill="black" stroke="black" points="55.9069,-71.4921 48.66,-79.2209 59.1449,-77.6982 55.9069,-71.4921"></polygon>
</g>
<!-- F->A -->
<g id="edge16" class="edge"><title>F->A</title>
<path fill="none" stroke="black" d="M145.199,-172.853C121.969,-184.973 84.1776,-204.69 57.8095,-218.447"></path>
<polygon fill="black" stroke="black" points="55.9069,-215.492 48.66,-223.221 59.1449,-221.698 55.9069,-215.492"></polygon>
</g>
<!-- F->C -->
<g id="edge18" class="edge"><title>F:w->C</title>
<path fill="none" stroke="black" d="M140,-162C103.148,-162 68.7605,-134.078 48.0591,-113.01"></path>
<polygon fill="black" stroke="black" points="50.4865,-110.483 41.0722,-105.623 45.4009,-115.293 50.4865,-110.483"></polygon>
</g>
<!-- F->E -->
<g id="edge22" class="edge"><title>F:e->E:e</title>
<path fill="none" stroke="black" d="M194,-162C254.5,-162 257.809,-33.3193 203.926,-19.2449"></path>
<polygon fill="black" stroke="black" points="204.358,-15.7717 194,-18 203.487,-22.7173 204.358,-15.7717"></polygon>
</g>
<!-- G -->
<g id="node13" class="node"><title>G</title>
<ellipse fill="none" stroke="black" cx="167" cy="-90" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="167" y="-85.8" font-family="Times,serif" font-size="14.00">G</text>
</g>
<!-- F->G -->
<g id="edge12" class="edge"><title>F->G</title>
<path fill="none" stroke="black" d="M167,-143.859C167,-135.268 167,-126.677 167,-118.085"></path>
<polygon fill="black" stroke="black" points="170.5,-118 167,-108 163.5,-118 170.5,-118"></polygon>
</g>
</g>
</svg>
发布于 2015-02-10 05:10:10
只需要一个集群来保持ABCDE组对齐。反向方向箭头和加权帮助很大。
digraph g
{
subgraph cluster_subCDE {
color=invis;
A; B; C; D; E;
}
A->B [weight=10];
A->F [dir=back];
B->C [weight=10];
F->C;
C->E [color=invis];
C->D;
D->E [constraint=false];
E->C;
F->G [weight=10];
F->D [dir=back];
F->E;
}
https://stackoverflow.com/questions/28388939
复制相似问题