How to prohibit nodes merge in graphviz?

2019-07-17 03:07发布

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: result_pic

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

what i want to see.

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

1条回答
三岁会撩人
2楼-- · 2019-07-17 03:36

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.

查看更多
登录 后发表回答