在Graphviz中,如何将边缘与节点的顶部中心对齐?

Vin*_*nto 5 dot graphviz

在Graphviz/dot中,是否可以将边缘准确地连接到节点的顶部中心?阅读点指南,我想,tailportheadport会帮助我,但添加这些没有区别,有时让我更奇怪的结果.

这就是我得到的:

样本图

这就是我要找的东西:

想要的结果

我用来获取(不正确)图表的代码是:

digraph G {

  graph [splines = ortho];
  node [shape = box];
  edge [dir = none];

  {
    rank = same

    A
    AB [shape = point]
    B

    A -> AB
    AB -> B
  }

  {
    rank = same
    point1 [shape = point]
    point2 [shape = point]
    point3 [shape = point]
  }

  AB -> point1

  // The following section if to make the nodes appear in 
  // the correct order, not sure if there's a better way
  {
    edge [style = invisible]
    rank = same
    C
    D
    E
    F
    C -> D
    D -> E
  }

  point2 -> point1
  point2 -> C
  point1 -> point3
  point3 -> E
  point1 -> D

}
Run Code Online (Sandbox Code Playgroud)

Fra*_*lli 6

笔记

  1. splines=ortho不支持tailportor headport(请参阅:“Graphviz 问题跟踪器 - 0002142:正交图不尊重端口。而且箭头似乎走错了方向。”
  2. 您可以使用隐藏节点,但不要在横向节点上使用它们(如下面的示例中C的 或)F

图像

结果

代码

该代码甚至适用于超过 3 个子节点,并且与 Graphviz 2.38 兼容。对于组织结构图很有用(即使它不完美,如果你有很多级别 - 我仍然尝试减少不对称性)。

 graph {
    splines=ortho;
    {0, 1, 2, 3 [width=0, shape=point, style=invis];}
    {rank=same; 1 -- 2 -- 3;}
    0 -- 2;
    node [shape=box];
    {rank=same; A -- 0 -- B;}
    1 -- C;
    1 -- D;
    3 -- E;
    3 -- F;
}
Run Code Online (Sandbox Code Playgroud)


Vin*_*nto 4

结果发现最新版本 (2.38) 在 Mac OS X Yosemite 中无法正常工作,我不得不降级到 2.36,如下载页面中所述。