【问题标题】:In Graphviz, how do I align an edge to the top center of a node?在 Graphviz 中,如何将边缘与节点的顶部中心对齐?
【发布时间】:2014-12-16 12:28:32
【问题描述】:

在 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

}

【问题讨论】:

  • 将您的代码复制粘贴到graphvizFiddle 会产生正确的结果。您使用的是最新版本的 graphviz 吗?
  • @marapet 谢谢!事实证明,最新的(2.38)版本在 Mac OS X Yosemite 中无法正常工作,我不得不降级到 2.36,如下载页面中所述:graphviz.org/Download_macos.php 如果您将此作为答案发布,我会接受,谢谢又来了!
  • 我很高兴你知道了!既然你做了所有的工作,你应该添加并接受你自己的答案;)

标签: graphviz dot


【解决方案1】:

注意事项

  1. splines=ortho 不支持 tailportheadport(参见:"Graphviz Issue Tracker - 0002142: ortho plots do not respect ports. also arrowheads seem to go the wrong way."
  2. 您可以使用隐藏节点,但不要在横向节点上使用它们(如下例中的CF

图片

代码

此代码甚至可以使用超过 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;
}

【讨论】:

    【解决方案2】:

    事实证明最新 (2.38) 版本在 Mac OS X Yosemite 中无法正常运行,我不得不降级到 2.36,如 download page 中所述。

    【讨论】:

      【解决方案3】:

      我在 Windows7 下看到同样的效果 - 没有尝试其他平台。

      我尝试摆弄“端口位置”,请参阅http://www.graphviz.org/content/attrs#kportPos

      例如将代码的最后几行更改为

        point2 -> point1
        point2 -> C:nw
        point1 -> point3
        point3 -> E:ne
        point1 -> D
      

      提供(稍微)更好的连接线定位。

      【讨论】:

        猜你喜欢
        • 2020-08-10
        • 2020-07-23
        • 1970-01-01
        • 2021-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-04
        相关资源
        最近更新 更多