如何强制两个圆形节点接触 GraphViz?

问题描述 投票:0回答:1

我想画两个相互接触的圆形节点。我尝试使用

ranksep
来实现这一点,但这导致了两个问题:

  • 不能归零,所以还有一段距离。
  • 由于
    ranksep
    是全局设置,并且它会影响所有节点,因此我必须将
    minlen
    添加到图中的所有边。 这就是我所做的:
digraph {
  graph [rankdir=LR, nodesep="1", ranksep="0.1"];
  a [shape=circle]
  b [shape=circle]
  a -> b [style=invis]

  x [shape=rect]
  x -> a [ minlen = 5]

  y [shape=rect]
  y -> a [ minlen = 5]
  
}

它看起来像这样:

知道如何让它们接触吗?

graphviz dot
1个回答
0
投票

没有简单的方法可以将两个节点对接在一起。
以下是两种不太简单的技巧:

  1. 根据需要创建两个圆圈的独立图像,然后将该图像包含在单个矩形节点中:
graph ab {
  // build by hand/eyeball
  margin=0
  pad=.01
  node[shape=circle]
  a [pos="72,72"]
  b [pos="108,72"]
}

创建图像文件:

 neato -Tpng -n2 mycircles.gv >mycircles.png
(参见https://graphviz.org/faq/#FaqDotWithCoords) 然后创建所需的(完整)图表:

digraph ab {
  rankdir=LR
  node[shape=circle]
  b [label="" shape=rect image="mycircles.png" peripheries=0]
  X->b:nw
  Y->b:sw
}

给予:

或者:

  • 创建您想要的图形 - 除了圆形节点不接触。
  • 创建一个增强输入(节点和边已定位),如下所示: ``dot -Tdot myfile.gv > myfile.dot`(参见 https://graphviz.org/docs/outputs/canon/
  • 手动或以编程方式编辑“myfile.dot”文件 - 更改第二个圆形节点的 pos
  • 通过以下方式运行编辑后的文件:`neato -n -Tpng myfile.dot >myfile.png 给予:
© www.soinside.com 2019 - 2024. All rights reserved.