In Graphviz, how do I align an edge to the top center of a node?

不问归期 提交于 2019-11-29 04:47:49

Turns out the most recent (2.38) version isn't working properly in Mac OS X Yosemite, I had to downgrade to 2.36 as noted in the download page.

Notes

  1. splines=ortho doesn't support tailport or headport (see: "Graphviz Issue Tracker - 0002142: ortho plots do not respect ports. also arrowheads seem to go the wrong way.")
  2. You can use hidden nodes, but don't use them on the lateral nodes (like C or F on the example below)

Image

Code

This code works even with more than 3 child nodes and it's compatible with Graphviz 2.38. Useful for Org Chart (even if it's not perfect if you have many levels - I'm still try to reduce asymmetries).

 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;
}

I see the same effect under Windows7 - did not try other platforms.

I tried fiddling with the 'port positions', See http://www.graphviz.org/content/attrs#kportPos

e.g. changing the last lines of your code to

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

gives a (slightly) better positioning of the connecting lines.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!