@@ -95,26 +95,45 @@ def generate_diff_graph(first_graph, second_graph):
95
95
graph .nodes .add (node )
96
96
97
97
for removed_edge in removed_edges :
98
- graph .edges .add (Edge (removed_edge .src , removed_edge .dest , "-del" ))
98
+ graph .edges .add (Edge (removed_edge .src , removed_edge .dest , "-" + removed_edge . label ))
99
99
for added_edge in added_edges :
100
- graph .edges .add (Edge (added_edge .src , added_edge .dest , "+add" ))
100
+ graph .edges .add (Edge (added_edge .src , added_edge .dest , "+" + added_edge . label ))
101
101
for edge in edges :
102
102
graph .edges .add (edge )
103
103
104
104
return graph
105
105
106
106
107
+ def remove_quotes (pydot_graph ):
108
+ """ For some reason, some pydot graph data is with quotes ('"name"', '"label"').
109
+ This function removes it."""
110
+
111
+ for node in pydot_graph .get_nodes ():
112
+ node .set_label (node .get_label ().replace ('"' , '' ))
113
+
114
+ for edge in pydot_graph .get_edges ():
115
+ edge .set_label (edge .get_label ().replace ('"' , '' ))
116
+
107
117
def from_dot (pydot_graph ):
108
118
"""Generated a graph from pydot graph."""
119
+ remove_quotes (pydot_graph )
109
120
graph = Graph ()
110
121
111
122
for node in pydot_graph .get_nodes ():
112
- graph .nodes .add (node .get_name ())
123
+ graph .nodes .add (node .get_label ())
113
124
114
125
for edge in pydot_graph .get_edges ():
115
- graph .edges .add (Edge (edge .get_source (), edge .get_destination ()))
116
- graph .nodes .add (edge .get_source ())
117
- graph .nodes .add (edge .get_destination ())
126
+ source_label = edge .get_source ()
127
+ source_nodes = pydot_graph .get_node (source_label )
128
+ if source_nodes :
129
+ source_label = source_nodes [0 ].get_label ()
130
+ dest_label = edge .get_destination ()
131
+ dest_nodes = pydot_graph .get_node (dest_label )
132
+ if dest_nodes :
133
+ dest_label = dest_nodes [0 ].get_label ()
134
+ graph .edges .add (Edge (source_label , dest_label , edge .get_label ()))
135
+ graph .nodes .add (source_label )
136
+ graph .nodes .add (dest_label )
118
137
return graph
119
138
120
139
0 commit comments