【问题标题】:Arrowhead overlaps node in Graphviz箭头与 Graphviz 中的节点重叠
【发布时间】:2015-03-09 16:52:47
【问题描述】:

当您查看上图时,您可以很容易地看到 a->b 的箭头与节点 b 重叠。箭头的尖端应该在 b 节点框之前停止,就像 c->d 中的情况一样。产生这个结果的代码是:

digraph{
  node[shape="box"]
  a->b[color=blue, penwidth=20]
  c->d[color=blue]
}

使用的布局引擎是“点”布局引擎。

【问题讨论】:

  • 案例 c->d 不会在节点 d 之前“停止”。问题是什么?
  • 问题是:如何防止a->b的箭头与节点“b”重叠?

标签: graph-theory graphviz overlap


【解决方案1】:

headclip(和 tailclip)使画边缘的笔的中心在穿过 shape-pen 中心绘制的假想线时停止。这是预期的行为。 graphviz 不补偿笔宽,因为它旨在进行图形布局。您必须发布流程或手动编辑点引擎的输出(svg 或 dot)。

digraph{ ranksep=0.5 nodesep=0.5 margin=0.5
  node[shape="box"]
  { node[penwidth=1] a c e}
  { node[penwidth=20] b d f}
  a->b->c [color=blue penwidth=20]
  d->e->f [color=blue]
}

png 显示圆笔边缘(和令人讨厌的剪裁)

svg 在边缘和形状上显示尖锐的提示

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
 -->
<!-- Title: %8851 Pages: 1 -->
<svg width="224pt" height="260pt"
 viewBox="36.00 36.00 188.00 224.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(40 220)">
<title>%8851</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-184 148,-184 148,4 -4,4"/>
<!-- a -->
<g id="node1" class="node"><title>a</title>
<polygon fill="none" stroke="black" points="54,-180 0,-180 0,-144 54,-144 54,-180"/>
<text text-anchor="middle" x="27" y="-158.3" font-family="Times New Roman,serif" font-size="14.00">a</text>
</g>
<!-- b -->
<g id="node4" class="node"><title>b</title>
<polygon fill="none" stroke="black" stroke-width="20" points="54,-108 0,-108 0,-72 54,-72 54,-108"/>
<text text-anchor="middle" x="27" y="-86.3" font-family="Times New Roman,serif" font-size="14.00">b</text>
</g>
<!-- a&#45;&gt;b -->
<g id="edge1" class="edge"><title>a&#45;&gt;b</title>
<path fill="none" stroke="blue" stroke-width="20" d="M27,-143.697C27,-135.983 27,-126.712 27,-118.112"/>
<polygon fill="blue" stroke="blue" stroke-width="20" points="44.5001,-118.104 27,-108.104 9.5001,-118.105 44.5001,-118.104"/>
</g>
<!-- c -->
<g id="node2" class="node"><title>c</title>
<polygon fill="none" stroke="black" points="54,-36 0,-36 0,-0 54,-0 54,-36"/>
<text text-anchor="middle" x="27" y="-14.3" font-family="Times New Roman,serif" font-size="14.00">c</text>
</g>
<!-- e -->
<g id="node3" class="node"><title>e</title>
<polygon fill="none" stroke="black" points="144,-108 90,-108 90,-72 144,-72 144,-108"/>
<text text-anchor="middle" x="117" y="-86.3" font-family="Times New Roman,serif" font-size="14.00">e</text>
</g>
<!-- f -->
<g id="node6" class="node"><title>f</title>
<polygon fill="none" stroke="black" stroke-width="20" points="144,-36 90,-36 90,-0 144,-0 144,-36"/>
<text text-anchor="middle" x="117" y="-14.3" font-family="Times New Roman,serif" font-size="14.00">f</text>
</g>
<!-- e&#45;&gt;f -->
<g id="edge4" class="edge"><title>e&#45;&gt;f</title>
<path fill="none" stroke="blue" d="M117,-71.6966C117,-63.9827 117,-54.7125 117,-46.1124"/>
<polygon fill="blue" stroke="blue" points="120.5,-46.1043 117,-36.1043 113.5,-46.1044 120.5,-46.1043"/>
</g>
<!-- b&#45;&gt;c -->
<g id="edge2" class="edge"><title>b&#45;&gt;c</title>
<path fill="none" stroke="blue" stroke-width="20" d="M27,-71.6966C27,-63.9827 27,-54.7125 27,-46.1124"/>
<polygon fill="blue" stroke="blue" stroke-width="20" points="44.5001,-46.1042 27,-36.1043 9.5001,-46.1045 44.5001,-46.1042"/>
</g>
<!-- d -->
<g id="node5" class="node"><title>d</title>
<polygon fill="none" stroke="black" stroke-width="20" points="144,-180 90,-180 90,-144 144,-144 144,-180"/>
<text text-anchor="middle" x="117" y="-158.3" font-family="Times New Roman,serif" font-size="14.00">d</text>
</g>
<!-- d&#45;&gt;e -->
<g id="edge3" class="edge"><title>d&#45;&gt;e</title>
<path fill="none" stroke="blue" d="M117,-143.697C117,-135.983 117,-126.712 117,-118.112"/>
<polygon fill="blue" stroke="blue" points="120.5,-118.104 117,-108.104 113.5,-118.104 120.5,-118.104"/>
</g>
</g>
</svg>

【讨论】:

  • 我还观察到了 png 和 svg 输出之间的这种差异。但是你要说的是,这个问题没有 GraphViz 解决方案。我唯一能做的就是事后操作 SVG。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-10
  • 1970-01-01
  • 2018-11-22
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
相关资源
最近更新 更多