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)
def make_subgraph(path, parent_graph): subgraph = Cluster(path, label=split(path)[1], style='rounded, filled', fillcolor='#77777744') parent_graph.add_subgraph(subgraph) return subgraph
def __missing__(self, path): parent, label = split(path) subgraph = Cluster(path, label=label, style='rounded, filled', fillcolor='#77777744') self[parent].add_subgraph(subgraph) return subgraph
def __buildHierachy(self, obj_dict, clusters, nodes): """ Build Cluster and Node hierachy for pydot """ for ptr in obj_dict: obj = obj_dict[ptr] if ptr in (self.sysc_ports.keys()+self.sysc_prim_channels.keys()): continue if len(obj["children"].keys()) == 0: node = Node(obj["name"]) nodes[ptr] = node else: clust = Cluster(obj["name"].replace(".", "_"), color='red', label=obj["name"]) c_clusters = {} c_nodes = {} self.__buildHierachy(obj["children"], c_clusters, c_nodes) for sptr in c_clusters: clust.add_subgraph(c_clusters[sptr]) for sptr in c_nodes: clust.add_node(c_nodes[sptr]) clusters[ptr] = clust
def get_package_cluster(long_name, short_name, subtree, rank): ''' Return a cluster representing a package, populated with all its contained modules and packages. ''' cluster = Cluster( '"%s"' % (long_name,), label='""', style="filled", fontname='Arial', fontsize=20, color="white" if rank % 2 else "grey75", ) # pydot.Cluster has a bug. Workaround by putting the 'cluster_' # prefix on the inside of the quotes cluster.obj_dict['name'] = '"cluster_%s"' % (long_name,) add_nodes(cluster, subtree, prefix=long_name, rank=rank+1) # Add a node within the cluster to act both as a cluster label # and as an endpoint for edges which connect to the cluster cluster.add_node(get_package_node(long_name, short_name, rank)) return cluster
def __missing__(self, path): *parent, label = path subgraph = Cluster(sep.join(path), label=label, style='rounded, filled', fillcolor='#77777744') self[tuple(parent)].add_subgraph(subgraph) return subgraph
def _n2c(n): qn = str(n._qname) return Cluster(qn, id=qn, label=str(n._name))
def bipartite_cluster(cls, cluster_name, cluster_label, cluster_nodes, cluster_nlabels, node_color): cluster = Cluster(cluster_name) cluster.set_label(cluster_label) cluster.set_fillcolor('lightgrey') cluster.set_style('filled') cluster.set_rank('same') for n, label in zip(cluster_nodes, cluster_nlabels): cluster.add_node(cls.bipartite_node(n, label, node_color)) for first, second in zip(cluster_nodes, cluster_nodes[1:]): cluster.add_edge(cls.bipartite_edge(first, second)) return cluster