pombreda / pydot

Automatically exported from code.google.com/p/pydot
MIT License
0 stars 0 forks source link

Adding edges to cluster sub-graphs does not always work #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Run the following code:

>>>>
import pydot

graph = pydot.Dot(graph_type='digraph')

cluster_a = pydot.Cluster('a', label='a')
graph.add_subgraph(cluster_a)
cluster_b = pydot.Cluster('b', label='b')
graph.add_subgraph(cluster_b)

node_a = pydot.Node('A')
cluster_a.add_node(node_a)
node_b = pydot.Node('B')
cluster_b.add_node(node_b)

# Broken
cluster_a.add_edge(pydot.Edge(node_a, node_b))

# Works
#cluster_b.add_edge(pydot.Edge(node_b, node_a))

# Works    
#cluster_b.add_edge(pydot.Edge(node_a, node_b))

# Works
#graph.add_edge(pydot.Edge(node_a, node_b))

# Works
#graph.add_edge(pydot.Edge(node_b, node_a))    

graph.write_png("clustertest.png")
<<<<

What is the expected output? What do you see instead?
Expect to see two clusters, 'a' and 'b', each with a node ('A' and 'B'), and an 
edge from A->B. The edge is displayed correctly, but both nodes have 
incorrectly been moved to cluster 'a'. For reference, any of the other 
(commented) lines produce the expected behaviour.

What version of the product are you using? On what operating system?
$Revision: 84174
OS: Win7 (64-Bit)

Please provide any additional information below.
Repro'd on Python 2.7.

Original issue reported on code.google.com by Symmetri...@gmail.com on 22 Sep 2011 at 2:31

GoogleCodeExporter commented 9 years ago
It appears to be something that graphviz chooses to interpret that way. IMHO I 
tend to think that to connect nodes within the two different clusters the edge 
should be added to graph, i.e. outside the clusters, so that the edge is not 
"owned" by any of them but by the graph parent to both clusters.
pydot adds the edge to cluster_a or cluster_b as indicated and seems to be 
graphviz that handles the layout differently, in one case leaving the edge 
entirely within a cluster and in the later case (when it knows about the 
existence of source and target) connecting the nodes in the two clusters.
I think that pydot is doing what it's being asked to do. If I'm pointed to 
graphviz grammar specs indicating otherwise I'll try to fix it.

Original comment by ero.carr...@gmail.com on 2 Jan 2012 at 7:18

GoogleCodeExporter commented 9 years ago
RE: Adding edges to clusters vs. nodes -- it depends what you're trying to 
represent. In the case in which I discovered this bug, there are multiple nodes 
in a cluster, and each may be connected to a node in another cluster. The 
logical elements at the cluster level do not have any linkages.

Given that there's a way to produce the correct graph, I am not going to 
attempt to learn the graphviz spec to figure this one out. If you have contacts 
at Graphviz I'd suggest you pass this on to them (I have no idea how one would 
go about getting the necessary diags from pydot).

Original comment by Symmetri...@gmail.com on 7 Jan 2012 at 7:02