当前位置: 首页>>代码示例>>Python>>正文


Python Dot.add_subgraph方法代码示例

本文整理汇总了Python中pydot.Dot.add_subgraph方法的典型用法代码示例。如果您正苦于以下问题:Python Dot.add_subgraph方法的具体用法?Python Dot.add_subgraph怎么用?Python Dot.add_subgraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydot.Dot的用法示例。


在下文中一共展示了Dot.add_subgraph方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw

# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import add_subgraph [as 别名]
    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)
开发者ID:marvinHao,项目名称:DepAnalysis,代码行数:50,代码来源:main.py

示例2: SysCDiagramPlugin

# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import add_subgraph [as 别名]

#.........这里部分代码省略.........
    def showDiagram(self):
        self.action.commit()

    def update(self):
        if not self.ctx_found and self.ctx is None:
            self.__findSimContext()
            if self.ctx is None:
                return
        else:
            # don't try to analyze if elaboration is not done
            if not cpp2py(self.ctx["m_elaboration_done"].value):
                return

        # prepare for easy information collection
        object_vec = self.ctx["m_child_objects"]

        # find all relevant information
        self.__findSysCObjects(object_vec, self.object_type, self.sysc_objects)

        # if there are no objects to draw than skip the drawing part
        # this might happen if you set the breakpoint before any objects are
        # created. This is actually catched above, but there might also be a
        # design with no objects.
        if len(self.sysc_objects.keys()) == 0:
            return

        clusters = {}
        nodes = {}

        # build pydot hierachy and add all subgraphs and nodes to the main
        # graph
        self.__buildHierachy(self.sysc_objects, clusters, nodes)
        for sptr in clusters:
            self.block_diagram.add_subgraph(clusters[sptr])
        for sptr in nodes:
            self.block_diagram.add_node(nodes[sptr])

        self._file_obj.write(self.block_diagram.create_svg())
        self.signalproxy.inferiorStoppedNormally.disconnect(self.update)
        self.showDiagram()

    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 __findSysCObjects(self, obj_vec, obj_type, dst_dict):
开发者ID:dstoeg,项目名称:ricodebug,代码行数:70,代码来源:SysCDiagramPlugin.py

示例3: diskusage

# 需要导入模块: from pydot import Dot [as 别名]
# 或者: from pydot.Dot import add_subgraph [as 别名]

#.........这里部分代码省略.........
            bytes = int(table[3])
            tbsBytes += bytes
            tabList += [[tableName, bytes, numRows, avgRowLen]]

        if withIndexes:
            # Indexes from current tablespace
            if userName == db.getUsername().upper():
                indexes = db.executeAll(diskusageSql["IndexesFromTbs"], [tablespaceName])
            else:
                indexes = db.executeAll(diskusageSql["IndexesFromOwnerAndTbs"], [userName, tablespaceName])
            idxList = []
            print CYAN + _("Extracting %3d indexes from tablespace %s") % (len(indexes), tablespaceName) + RESET
            for index in indexes:
                indexName = index[0]
                if index[1] is None:
                    print RED + _("""Warning: index "%s" removed because no statistics have been found""") \
                            % (tablespaceName + "/" + indexName) + RESET
                    continue
                if index[1] == 0:
                    print RED + _("""Warning: index "%s" removed because it is empty""") \
                            % (tablespaceName + "/" + indexName) + RESET
                    continue
                numRows = int(index[1])
                distinctKeys = int(index[2])
                bytes = int(index[3])
                tabName = str(index[4])
                tbsBytes += bytes
                idxList += [[indexName, bytes, numRows, distinctKeys, tabName]]
        else:
            print CYAN + _("Not extracting indexes from tablespace %s (ignored)") % (tablespaceName) + RESET
            idxList = []
        tbsList += [[tablespaceName, tbsBytes, tabList, idxList]]

# Second step: objects drawing
    graph = Dot(label=userName, overlap="false", splines="true")

    for tbs in tbsList:
        tbsName = tbs[0]
        tbsBytes = tbs[1]
        tabList = tbs[2]
        idxList = tbs[3]
        subGraph = Subgraph("cluster_" + tbsName, bgcolor="palegreen", \
                          fontname=fontname, fontsize=str(fontsize - 1), \
                          label="%s\\n(%d %s)" % (tbsName, convert(tbsBytes, unit), unit.upper()))
        graph.add_subgraph(subGraph)

        print CYAN + _("Displaying %3d tables for tablespace %s") % (len(tabList), tbsName) + RESET
        for tab in tabList:
            name = tab[0]
            bytes = tab[1]
            numRows = tab[2]      # unused
            avgRowLen = tab[3]    # unused

            # Mathematics at work
            width = 0.2
            height = 0.2
            if percent:
                height += 10 * round(float(bytes) / tbsBytes, 4)
                label = "%s\\n(%.2f %s)" % (name, round(100 * float(bytes) / tbsBytes, 2), "%")

            else:
                height += round(sqrt(bytes) / 8192, 3)
                width += round(sqrt(bytes) / 8192, 3)
                label = "%s\\n(%3d %s)" % (name, convert(bytes, unit), unit.upper())
            subGraph.add_node(Node(name, label=label, shape="box", style="filled", \
                                   color="none", fillcolor=tablecolor, \
                                   fontname=fontname, fontcolor=fontcolor, fixedsize="false", \
                                   fontsize=str(fontsize - 2 - floor((len(label) - 7) / 15)), \
                                   nodesep="0.01", height=str(height), width=str(max(width, 1))))

        print CYAN + _("Displaying %3d indexes for tablespace %s") % (len(idxList), tbsName) + RESET
        for idx in idxList:
            name = idx[0]
            bytes = idx[1]
            numRows = idx[2]      # unused
            distinctKeys = idx[3] # unused
            tabName = idx[4]      # unused

            # Mathematics at work again)
            width = 0.2
            height = 0.2
            if percent:
                height += 10 * round(float(bytes) / tbsBytes, 4)
                label = "%s\\n(%.2f %s)" % (name, round(100 * float(bytes) / tbsBytes, 2), "%")
            else:
                height += round(sqrt(bytes) / 8192, 3)
                width += round(sqrt(bytes) / 8192, 3)
                label = "%s\\n(%3d %s)" % (name, convert(bytes, unit), unit.upper())

            subGraph.add_node(Node(name, label=label, shape="box", style="filled", \
                                color="none", fillcolor=indexcolor, \
                                fontname=fontname, fontcolor=fontcolor, fixedsize="false", \
                                fontsize=str(fontsize - 2 - floor((len(label) - 7) / 15)), \
                                nodesep="0.01", height=str(height), width=str(max(width, 1))))
            #Moving index near by its table (unused because it widens the graph)
            #subGraph.add_edge(Edge(src=name, dst=tabName, constraint="false", style="invis"))

    filename = "du_" + userName + "." + format
    generateImage(graph, filename, prog, format)
    viewImage(filename)
开发者ID:sdelcros,项目名称:pysql,代码行数:104,代码来源:pysqlgraphics.py


注:本文中的pydot.Dot.add_subgraph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。