xflr6 / graphviz

Simple Python interface for Graphviz
https://graphviz.readthedocs.io
MIT License
1.63k stars 211 forks source link

Digraph.node() cannot merge nodes with the same name #192

Closed Leepay closed 1 year ago

Leepay commented 1 year ago

my code are:

from graphviz import Digraph
dot = Digraph(comment='test')
dot.node('A', shape="box")
dot.node('A', shape="box")
dot.node('A')
dot.node('A')
print(dot.source)

Output is:

// test
digraph {
    A [shape=box]
    A [shape=box]
    A
    A
}

But the expected output should be a digraph with only one node, which is 'A', isn't it?

My environment:

python 3.8.13
graphviz 2.50.0
xflr6 commented 1 year ago

But the expected output should be a digraph with only one node, which is 'A', isn't it?

No. DOT-building methods such as .node() and .edge() precisely add node-statements and edge-statements to the DOT instance (not sure if this should be more explicit in the documentation).

graphviz.Graph and graphviz.Digraph do not track the semantics of the statements added (e.g. which nodes have been added): Their sole purpose is to simply to generate DOT source line by line.

P.S.: If you are looking for a more complete OoO interface to all of Graphviz' semantics, maybe check out some of the alternatives: https://github.com/xflr6/graphviz#see-also