Graphviz DOT绘制ER图:自关联关系正交边设置异常求助
解决Graphviz 2.43.0中自关联ER图正交边渲染异常的问题
你的问题出在旧版本DOT对正交边(splines=ortho)的支持限制,加上强制指定端口(headport/tailport)干扰了布局引擎的路径计算逻辑。可以通过以下两种方案解决:
方案一:移除端口约束,让引擎自动处理
删除代码中headport和tailport的强制指定,配合布局参数让正交边正常生成:
graph [splines=ortho, rankdir=LR, nodesep=0.8, ranksep=0.8] edge [arrowhead = none] Entity [shape = box] Relationship [shape = diamond] Entity -> Relationship Relationship -> Entity }
rankdir=LR设置左右布局,帮助引擎生成规整的水平/垂直线段nodesep和ranksep增加节点间距,避免路径重叠导致的异常
方案二:保留端口约束并调整布局参数
如果必须固定端口方向,添加constraint=false解除路径的布局约束,同时调整间距:
graph [splines=ortho, rankdir=LR, nodesep=1.2] edge [arrowhead = none] Entity [shape = box] Relationship [shape = diamond] Entity -> Relationship [headport = w, tailport = w, constraint=false] Relationship -> Entity [headport = e, tailport = e] }
补充说明
Graphviz 2.43.0属于较旧版本,splines=ortho的逻辑存在一些兼容性问题,尤其是在强制指定端口时。如果后续有条件,升级到更晚的版本(如2.47.0及以上)可以获得更稳定的正交边支持。
内容的提问来源于stack exchange,提问作者August Karlstrom
相关产品推荐
相关产品推荐

