【问题标题】:Increase separation of edges in graphviz在graphviz中增加边缘的分离
【发布时间】:2016-08-16 23:53:09
【问题描述】:

我正在使用 dot-graphviz 创建几个 UML 活动图,只要目标形状是窄矩形(H=0.5,W=0.05),边/箭头 (2+) 就会收敛在同一点。如果目标形状是正方形(H=0.5,W=0.5),则不会出现此问题。

这是一个减少点的例子:

digraph G {
graph [ ranksep = 0.5, rankdir = LR ]
A4 [ shape = "record", height = 0.5, fontsize = 10, margin = "0.20,0.05", label = "Output\ to\rPreviewer", style = "rounded" ]
A5 [ shape = "rectangle", height = 0.5, width = 0.05, margin = "0,0", style = "filled", label = "" ]
A4 -> A5 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
A6 [ shape = "diamond", height = 0.5, width = 0.5, margin = "0,0", label = "" ]
A6 -> A5 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10, label = "[generate: false]" ]
A7 [ shape = "record", height = 0.5, fontsize = 10, margin = "0.20,0.05", label = "Output\ to\rFile", style = "rounded" ]
A6 -> A7 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10, label = "[generate: true]" ]
A8 [ shape = "doublecircle", height = 0.3, width = 0.3, margin = "0,0", label = "" ]
A7 -> A5 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
A5 -> A8 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
}

以上文字在http://webgraphviz.com中生成如下图

理想的输出如下

【问题讨论】:

  • 你可以试试A6 -> A5:nwA7 -> A5:sw。不能准确地给您想要的输出,但至少可以分离边缘。
  • @vaettchen,这听起来不像是一个通用的解决方案,而且对于提供的示例来说非常具体。如果有 4 个边也没有用。
  • 正确 - 我尝试了针对该特定问题的解决方案。也许您编辑您的帖子说您正在寻找更多边缘/箭头的通用解决方案。

标签: graphviz dot


【解决方案1】:

我发现了一个可以产生不错输出的调整,但需要大量的处理以及边缘计数和方向意识:

digraph G {
graph [ ranksep = 0.5, rankdir = LR ]
A4 [ shape = "record", height = 0.5, fontsize = 10, margin = "0.20,0.05", label = "Output\ to\rPreviewer", style = "rounded" ]
A5 [ shape = "record", height = 0.5, width = 0.05, margin = "0,0", style = "filled", label = "<f0>|<f1>|<f2>", fillcolor="black" ]
A4 -> A5:f0:w [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
A6 [ shape = "diamond", height = 0.5, width = 0.5, margin = "0,0", label = "" ]
A6 -> A5:f1:w [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10, label = "[generate: false]" ]
A7 [ shape = "record", height = 0.5, fontsize = 10, margin = "0.20,0.05", label = "Output\ to\rFile", style = "rounded" ]
A6 -> A7 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10, label = "[generate: true]" ]
A8 [ shape = "doublecircle", height = 0.3, width = 0.3, margin = "0,0", label = "" ]
A7 -> A5:f2:w [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
A5 -> A8 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
}

这是输出:

我仍然想知道是否有更简单的解决方案。

【讨论】:

  • 我接受我自己的答案,因为它产生了最好的结果,并且可以扩展到任意数量的边缘。
【解决方案2】:

您可以将所有边的输出端口指定为east 并获得非常好的结果(至少在这种情况下):

digraph G {
        graph [ ranksep = 0.5, rankdir = LR ]
        edge [tailport=e]                    # <----- added this line
        A4 [ shape = "record", height = 0.5, fontsize = 10, margin = "0.20,0.05", label = "Output\ to\rPreviewer", style = "rounded" ]
        A5 [ shape = "rectangle", height = 0.5, width = 0.05, margin = "0,0", style = "filled", label = "" ]
        A4 -> A5 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
        A6 [ shape = "diamond", height = 0.5, width = 0.5, margin = "0,0", label = "" ]
        A6 -> A5 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10, label     = "[generate: false]" ]
        A7 [ shape = "record", height = 0.5, fontsize = 10, margin = "0.20,0.05", label = "Output\ to\rFile", style = "rounded" ]
        A6 -> A7 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10, label     = "[generate: true]" ]
        A8 [ shape = "doublecircle", height = 0.3, width = 0.3, margin = "0,0", label = "" ]
        A7 -> A5 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
        A5 -> A8 [ shape = "edge", dir = "both", style = "solid", arrowtail = "none", arrowhead = "vee", labeldistance = 1, fontsize = 10 ]
}

生产:

【讨论】:

  • 您好 Ohad,乍一看,它看起来是一个不错的选择,但这只是所提供示例的巧合。尝试评论A7 -&gt; A5这一行,原来的效果又出现了。
  • 虽然这不是巧合,但你是对的,它并不是适用于所有情况的解决方案
猜你喜欢
  • 2017-12-19
  • 2010-12-20
  • 1970-01-01
  • 2019-06-19
  • 2010-10-24
  • 2020-09-06
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多