-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parse subgraphs recursively #72
Changes from 8 commits
d230494
fe12714
ee757c6
5922aac
2232620
b0364e3
8c24425
805b640
e5257c3
4fb8c3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,9 +236,13 @@ def addEdgeItem(self, edge, nodes, edges, highlight_level, same_label_siblings=F | |
edge_item.add_sibling_edge(sibling) | ||
sibling.add_sibling_edge(edge_item) | ||
|
||
if label not in edges: | ||
edges[label] = [] | ||
edges[label].append(edge_item) | ||
edge_name = source_node.strip('"\n"') + '_TO_' + destination_node.strip('"\n"') | ||
if label is not None: | ||
edge_name = edge_name + '_' + label | ||
|
||
if edge_name not in edges: | ||
edges[edge_name] = [] | ||
edges[edge_name].append(edge_item) | ||
|
||
def dotcode_to_qt_items(self, dotcode, highlight_level, same_label_siblings=False): | ||
""" | ||
|
@@ -256,15 +260,28 @@ def dotcode_to_qt_items(self, dotcode, highlight_level, same_label_siblings=Fals | |
#graph = pygraphviz.AGraph(string=self._current_dotcode, strict=False, directed=True) | ||
#graph.layout(prog='dot') | ||
|
||
nodes = self.parse_nodes(graph, highlight_level) | ||
edges = self.parse_edges(graph, nodes, highlight_level, same_label_siblings) | ||
return nodes, edges | ||
|
||
def parse_nodes(self, graph, highlight_level): | ||
''' | ||
Recursively searches all nodes inside the graph and all subgraphs | ||
''' | ||
|
||
# let pydot imitate pygraphviz api | ||
graph.nodes_iter = graph.get_node_list | ||
graph.edges_iter = graph.get_edge_list | ||
|
||
graph.subgraphs_iter = graph.get_subgraph_list | ||
|
||
num_subgraphs = len(graph.get_subgraph_list()) | ||
|
||
nodes = {} | ||
for subgraph in graph.subgraphs_iter(): | ||
subgraph_nodeitem = self.getNodeItemForSubgraph(subgraph, highlight_level) | ||
num_subgraphs = len(subgraph.get_subgraph_list()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is not used anywhere? |
||
|
||
nodes = dict(nodes, **self.parse_nodes(subgraph, highlight_level)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the following would be more readable and make the intention of the line clearer:
Same below for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dirk-thomas thanks for the really thorough review. I included the mentioned changes. |
||
|
||
# skip subgraphs with empty bounding boxes | ||
if subgraph_nodeitem is None: | ||
continue | ||
|
@@ -281,11 +298,23 @@ def dotcode_to_qt_items(self, dotcode, highlight_level, same_label_siblings=Fals | |
if node.get_name() in ('graph', 'node', 'empty'): | ||
continue | ||
nodes[node.get_name()] = self.getNodeItemForNode(node, highlight_level) | ||
return nodes | ||
|
||
edges = {} | ||
def parse_edges(self, graph, nodes, highlight_level, same_label_siblings): | ||
''' | ||
Recursively searches all edges inside the graph and all subgraphs | ||
''' | ||
|
||
# let pydot imitate pygraphviz api | ||
graph.subgraphs_iter = graph.get_subgraph_list | ||
graph.edges_iter = graph.get_edge_list | ||
|
||
edges = {} | ||
for subgraph in graph.subgraphs_iter(): | ||
subgraph.edges_iter = subgraph.get_edge_list | ||
|
||
edges = dict(edges, **self.parse_edges(subgraph, nodes, highlight_level, same_label_siblings)) | ||
|
||
for edge in subgraph.edges_iter(): | ||
self.addEdgeItem(edge, nodes, edges, | ||
highlight_level=highlight_level, | ||
|
@@ -295,5 +324,5 @@ def dotcode_to_qt_items(self, dotcode, highlight_level, same_label_siblings=Fals | |
self.addEdgeItem(edge, nodes, edges, | ||
highlight_level=highlight_level, | ||
same_label_siblings=same_label_siblings) | ||
return edges | ||
|
||
return nodes, edges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is not used anywhere?