如何在Graphviz中高亮D到E的边?解决边无法重叠显示问题
Graphviz实现D-E边黄色高亮(解决边并排问题)
要在Graphviz的K5图中高亮D到E的边,尝试叠加额外边时,Graphviz未让边重叠,反而将它们并排显示。以下是原代码及异常效果:
原代码
graph K5 { graph [splines = false, layout=circo]; edge [penwidth=3]; node [shape=circle]; A; B; C; D; E; { edge [color="red"]; A -- B; A -- C; C -- D; B -- D; C -- E; } { edge [color="blue"]; node [comment="Wildcard node added automatic in EG."]; D -- E; A -- E; B -- C; B -- E; A -- D; } { edge [color="#95a616aa" penwidth=5]; node [comment="Wildcard node added automatic in EG."]; E -- D; } }
异常效果

解决方法
要让高亮边与原边完全重叠,需给高亮边添加三个关键属性:
constraint=false:禁止这条边影响节点布局samehead/sametail:指定高亮边与原边使用相同的节点端口,强制两条边重叠
修改后的高亮边代码块如下:
{ edge [color="#95a616" penwidth=5 constraint=false samehead=D sametail=E]; E -- D; }
完整修改后代码
graph K5 { graph [splines = false, layout=circo]; edge [penwidth=3]; node [shape=circle]; A; B; C; D; E; { edge [color="red"]; A -- B; A -- C; C -- D; B -- D; C -- E; } { edge [color="blue"]; node [comment="Wildcard node added automatic in EG."]; D -- E; A -- E; B -- C; B -- E; A -- D; } { edge [color="#95a616" penwidth=5 constraint=false samehead=D sametail=E]; node [comment="Wildcard node added automatic in EG."]; E -- D; } }
修改后,黄色高亮边会与原蓝色D-E边完全重叠,实现预期的高亮效果。
内容的提问来源于stack exchange,提问作者OwlBandicoot
相关产品推荐
相关产品推荐

