Esempio n. 1
0
    def draw(self, path: str, format: str = "raw") -> None:

        node_aggr = {}
        for node in self._nodes:
            level = node.get_level()
            label = node.get_label()
            identifier = node.get_id()
            if node_aggr.get(level) is None:
                node_aggr[level] = {}
            if level != 0:
                gv_cluster = GVCluster(identifier)
                gv_cluster.set("label", label)
                node_aggr[level][identifier] = gv_cluster
            else:
                gv_node = GVNode(identifier)
                gv_node.set("label", label)
                node_aggr[level][identifier] = gv_node

        gv_dot = GVDot()
        gv_dot.set("ranksep", "1.0 equally")

        if self._lable is not None:
            gv_dot.set("label", self._lable)

        for node in self._nodes:
            level = node.get_level()
            parent = node.get_parent()
            parent_level = node.get_parent_level()
            identifier = node.get_id()
            if level != 0:
                if parent is not None:
                    node_aggr[parent_level][parent].add_subgraph(node_aggr[level][identifier])
                else:
                    gv_dot.add_subgraph(node_aggr[level][identifier])
            else:
                if parent is not None:
                    node_aggr[parent_level][parent].add_node(node_aggr[level][identifier])
                else:
                    gv_dot.add_node(node_aggr[level][identifier])

        for edge in self._edges:
            label = edge.get_label()
            gv_edge = GVEdge(edge.get_src(), edge.get_dst())
            if label is not None:
                gv_edge.set("label", edge.get_label())
            gv_dot.add_edge(gv_edge)

        gv_dot.write(path, format=format)