ast_visualizer_4.py 593 B

123456789101112131415161718
  1. def render(self, data, *, label=None):
  2. # create the graph
  3. graphattrs = self.graphattrs.copy()
  4. if label is not None:
  5. graphattrs['label'] = self._escape_dot_label(label)
  6. graph = gv.Digraph(graph_attr = graphattrs, node_attr = self.nodeattrs, edge_attr = self.edgeattrs)
  7. # recursively draw all the nodes and edges
  8. self._graph = graph
  9. self._rendered_nodes = set()
  10. self._render_node(data)
  11. self._graph = None
  12. self._rendered_nodes = None
  13. # display the graph
  14. graph.format = "pdf"
  15. graph.view()
  16. subprocess.Popen(['xdg-open', "test.pdf"])