How to prohibit nodes merge in graphviz?

拟墨画扇 提交于 2019-12-11 04:17:09

问题


I use graphviz to draw commands tree. By default it's merging nodes with same name. How to prohibit this? Example: I have a code:

strict digraph 2 {
rankdir=LR;
SHOW_CONFIGURATION -> INTERFACES_eth;
SHOW_CONFIGURATION -> INTERFACES_vlan;
SHOW_CONFIGURATION -> INTERFACES_lag;
SHOW_CONFIGURATION -> INTERFACES_eth -> DESCRIPTION;
SHOW_CONFIGURATION -> INTERFACES_vlan -> DESCRIPTION;
SHOW_CONFIGURATION -> INTERFACES_lag -> DESCRIPTION;
SHOW_CONFIGURATION -> INTERFACES_eth -> IPV4;
SHOW_CONFIGURATION -> INTERFACES_vlan -> IPV4;
SHOW_CONFIGURATION -> INTERFACES_lag -> IPV4;
}

Result of drawing with command dot -Tsvg -o cli_tree.svg SHOW_CONFIGURATION.dot:

But i need to draw it without merging of same subcommand nodes, like in this image:

.

Please, help me to know how can i draw my graph like so.


回答1:


By default, graphviz uses the node id as label. If distinct nodes need to have the same label, the label has to be defined explicitely.

I also find it sometimes useful to define first all nodes, then the edges between those nodes.

strict digraph 2 {
rankdir=LR;
//Nodes
cfg [label="SHOW_CONFIGURATION"];
eth [label="INTERFACES_eth"];
vlan [label="INTERFACES_vlan"];
lag [label="INTERFACES_lag"];
node[label="DESCRIPTION"];
d1;d2;d3;
node[label="IPV4"];
i1;i2;i3;

// Edges
cfg -> {eth; vlan; lag;}
eth -> {d1; i1;}
vlan -> {d2; i2;}
lag -> {d3; i3}
}

In this example, the instruction node[...] defines default attributes for all new nodes after this instruction.



来源:https://stackoverflow.com/questions/45861379/how-to-prohibit-nodes-merge-in-graphviz

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