pombreda / pydot

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

Simplify throws NameError, and, as implemented, doesn't work #92

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. invoke set_simplify(true) on a graph
2. invoke method to_string() 
3. profit

What is the expected output? What do you see instead?
Extraneous edges removed from dot output

What version of the product are you using? On what operating system?
1.0.2

Please provide any additional information below.

This is a patch which both resolves the NameError and enables the desired 
behavior:
--- /usr/lib/python2.6/site-packages/pydot.py   2014-06-12 06:22:57.000000000 
+0400
+++ virtenv/lib/python2.6/site-packages/pydot.py    2014-06-12 06:28:42.515864719 
+0400
@@ -1455,11 +1455,11 @@

                 edge = Edge(obj_dict=obj)

-                if self.obj_dict.get('simplify', False) and elm in edges_done:
+                if self.obj_dict.get('simplify', False) and 
edge.obj_dict['points'] in edges_done:
                     continue
-
+
                 graph.append( edge.to_string() + '\n' )
-                edges_done.add(edge)
+                edges_done.add(edge.obj_dict['points'])

             else:

Original issue reported on code.google.com by TheSoup...@gmail.com on 12 Jun 2014 at 2:30

Attachments:

GoogleCodeExporter commented 9 years ago
Or if you prefer to retain encapsulation:
--- /usr/lib/python2.6/site-packages/pydot.py   2014-06-12 06:22:57.000000000 
+0400
+++ virtenv/lib/python2.6/site-packages/pydot.py    2014-06-12 06:58:20.478835432 
+0400
@@ -834,6 +834,11 @@

         return False

+    def __hash__(self):
+        if self.get_parent_graph().get_top_graph_type() == 'graph':
+            return hash(min(self.get_source(), self.get_destination())
+                    + max(self.get_source(), self.get_destination()))
+        return hash(self.get_source() + self.get_destination())

     def parse_node_ref(self, node_str):
@@ -1455,7 +1460,7 @@

                 edge = Edge(obj_dict=obj)

-                if self.obj_dict.get('simplify', False) and elm in edges_done:
+                if self.obj_dict.get('simplify', False) and edge in edges_done:
                     continue

                 graph.append( edge.to_string() + '\n' )

Original comment by TheSoup...@gmail.com on 12 Jun 2014 at 3:00

Attachments: