How to use the pydot.Cluster function in pydot

To help you get started, we’ve selected a few pydot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midonet / midonet / tests / tools / topoloviz / topoloviz.py View on Github external
if args.prompt_password:
            password = raw_input('Password for MidoNet API: ')
        dao = vta.MidoNetApi(args.midonet_url, args.username, password,
                             args.tenant_id)

    for tenant in dao.get_tenants():

        tenant_cluster = Cluster(get_tenant_cluster_id(tenant['id']),
                                 label=get_tenant_label(tenant['id']))

        for chain in dao.get_chains_by_tenant_id(tenant['id']):
            chain_node = Node(chain['id'],
                              label=get_device_label(chain, 'Chain'))


            chain_cluster = Cluster(chain['id'].replace('-', '_'),
                                    label=get_device_label(chain, 'Chain'))
            tenant_cluster.add_subgraph(chain_cluster)

            rules = dao.get_rules_by_chain_id(chain['id'])
            for rule in rules:
                rule_node = Node(rule['id'],
                                 label=get_rule_label(rule),
                                 shape='box')
                chain_cluster.add_node(rule_node)

        routers = dao.get_routers_by_tenant_id(tenant['id'])
        for router in routers:
            router_node = Node(get_device_id(router),
                                     label=get_device_label(router, 'Router'),
                                     shape='box')
            tenant_cluster.add_node(router_node)
github compmem / smile / smile / dag.py View on Github external
def _add_cluster(self, graph, cluster):
        # create the cluster
        name,cl_uname = get_class_name(cluster)
        clust = pydot.Cluster(cl_uname, label=name)

        # loop over children of cluster
        nodes = []
        for i,c in enumerate(cluster.children):
            if issubclass(c.__class__, ParentState):
                # call recursively
                uname,first_uname,last_uname = self._add_cluster(clust, c)

                # save in node list
                if not uname is None:
                    nodes.append({'uname':uname,
                                  'first_uname': first_uname,
                                  'last_uname': last_uname})
            else:
                # add the child node
                name,uname = get_class_name(c)
github cairis-platform / cairis / cairis / cairis / LocationModel.py View on Github external
def graph(self):
    locs = self.theLocs[2]
    edgeList = set([])

    for location in locs:
      locName = location[0]
      assetInstances = location[1]
      personaInstances = location[2]
      locLinks = location[3]

      for linkLoc in locLinks:
        if ((linkLoc,locName) not in edgeList) and ((locName,linkLoc) not in edgeList):
          edgeList.add((linkLoc,locName))
      
      locCluster = pydot.Cluster(locName,label=locName,URL='location#' + locName)
      locCluster.add_node(pydot.Node('point_' + locName,label='',shape="none",fontcolor="white",URL='location#' + locName))
      for inst in assetInstances:
        instName = inst[0]
        assetName = inst[1] 
        locCluster.add_node(pydot.Node(instName,URL='asset#' + assetName))

      for persona in personaInstances:
        instName = persona[0]
        personaName = persona[1] 
        locCluster.add_node(pydot.Node(instName,shape='circle',URL='persona#' + personaName))
      self.theGraph.add_subgraph(locCluster)

    for edges in edgeList:
      self.theGraph.add_edge(pydot.Edge('point_' + edges[0],'point_' + edges[1],arrowhead='none',arrowtail='none',dir='both'))

    edgeList.clear()
github compmem / smile / docs / examples / pdot_ex.py View on Github external
import pydot

g = pydot.Dot(graph_type='digraph',fontname="Verdana", compound='true')

c_exp = pydot.Cluster('exp',label='Experiment')


c_exp.add_node(pydot.Node('inst',label='Instructions'))

c_trial = pydot.Cluster('trial',label='Trial')
c_trial.add_node(pydot.Node('text',label='Text'))
c_trial.add_node(pydot.Node('resp',label='Response'))

c_exp.add_subgraph(c_trial)

c_exp.add_node(pydot.Node('debrief',label='Debrief'))

g.add_subgraph(c_exp)

g.add_edge(pydot.Edge('inst','text',lhead=c_trial.get_name()))
g.add_edge(pydot.Edge('text','resp'))
g.add_edge(pydot.Edge('resp','debrief',ltail=c_trial.get_name()))


g.write('ex_graph.pdf', prog = 'dot', format = 'pdf')
github ncbray / pystream / bin / analysis / cfgIR / dumpcfgir.py View on Github external
def cluster(self, node):
		if node not in self._cluster:
			c = pydot.Cluster(str(id(node)), **self.style(node))
			parent = self.cluster(node.parent)
			parent.add_subgraph(c)
			self._cluster[node] = c
		else:
			c = self._cluster[node]
		return c
github alegonz / baikal / baikal / plot.py View on Github external
def build_dot_from(model_, output_, container=None):
        if container is None:
            container = dot_graph

        parent_step = output_.step

        if parent_step in nodes_built:
            return

        if isinstance(parent_step, Model) and expand_nested:
            # Build nested model
            nested_model = parent_step
            cluster = pydot.Cluster(
                name=nested_model.name, label=nested_model.name, style="dashed"
            )

            for output_ in nested_model._internal_outputs:
                build_dot_from(nested_model, output_, cluster)
            container.add_subgraph(cluster)

            # Connect with outer model
            for input, internal_input in safezip2(
                nested_model.inputs, nested_model._internal_inputs
            ):
                build_edge(input.step, internal_input.step, input.name, container)

        else:
            # Build step
            if parent_step in [input.step for input in model_._internal_inputs]:
github odoo / odoo / bin / addons / base / ir / workflow / print_instance.py View on Github external
def graph_get(cr, graph, wkf_id, nested=False, workitem={}):
    import pydot
    cr.execute('select * from wkf_activity where wkf_id=%s', (wkf_id,))
    nodes = cr.dictfetchall()
    activities = {}
    actfrom = {}
    actto = {}
    for n in nodes:
        activities[n['id']] = n
        if n['subflow_id'] and nested:
            cr.execute('select * from wkf where id=%s', (n['subflow_id'],))
            wkfinfo = cr.dictfetchone()
            graph2 = pydot.Cluster('subflow'+str(n['subflow_id']), fontsize='12', label = """\"Subflow: %s\\nOSV: %s\"""" % ( n['name'], wkfinfo['osv']) )
            (s1,s2) = graph_get(cr, graph2, n['subflow_id'], nested,workitem)
            graph.add_subgraph(graph2)
            actfrom[n['id']] = s2
            actto[n['id']] = s1
        else:
            args = {}
            if n['flow_start'] or n['flow_stop']:
                args['style']='filled'
                args['color']='lightgrey'
            args['label']=n['name']
            if n['subflow_id']:
                args['shape'] = 'box'
            if n['id'] in workitem:
                args['label']+='\\nx '+str(workitem[n['id']])
                args['color'] = "red"
            graph.add_node(pydot.Node(n['id'], **args))
github odoo / odoo / openerp / addons / base / workflow / workflow_report.py View on Github external
def graph_get(cr, graph, wkf_ids, nested, workitem, processed_subflows):
    import pydot
    cr.execute('select * from wkf_activity where wkf_id in ('+','.join(['%s']*len(wkf_ids))+')', wkf_ids)
    nodes = cr.dictfetchall()
    activities = {}
    actfrom = {}
    actto = {}
    for n in nodes:
        activities[n['id']] = n
        if n['subflow_id'] and nested and n['subflow_id'] not in processed_subflows:
            processed_subflows.add(n['subflow_id']) # don't create multiple times the same cluster.
            cr.execute('select * from wkf where id=%s', (n['subflow_id'],))
            wkfinfo = cr.dictfetchone()
            graph2 = pydot.Cluster('subflow'+str(n['subflow_id']), fontsize='12', label = "\"Subflow: %s\\nOSV: %s\"" % ( n['name'], wkfinfo['osv']) )
            (s1,s2) = graph_get(cr, graph2, [n['subflow_id']], True, workitem, processed_subflows)
            graph.add_subgraph(graph2)
            actfrom[n['id']] = s2
            actto[n['id']] = s1
        else:
            args = {}
            if n['flow_start'] or n['flow_stop']:
                args['style']='filled'
                args['color']='lightgrey'
            args['label']=n['name']
            workitems = ''
            if n['id'] in workitem:
                workitems = '\\nx ' + str(workitem[n['id']])
                args['label'] += workitems
                args['color'] = "red"
                args['style']='filled'
github ros-visualization / qt_gui_core / qt_dotgraph / src / qt_dotgraph / pydotfactory.py View on Github external
rankdir='TB',
                              ranksep=0.2,
                              compound=True,
                              color=None,
                              shape='box',
                              style='bold',
                              subgraphlabel=None):
        """
        Create a cluster subgraph item for this factory, adds it to the graph.

        cluster name can vary from label but must always be same for the same node label.
        Most layouters require cluster names to start with cluster.
        """
        if subgraphname is None or subgraphname == '':
            raise ValueError('Empty subgraph name')
        g = pydot.Cluster(self.escape_name(subgraphname),
                          rank=rank, rankdir=rankdir, simplify=simplify)
        if 'set_style' in g.__dict__:
            g.set_style(style)
        if 'set_shape' in g.__dict__:
            g.set_shape(shape)
        if LooseVersion(pydot.__version__) > LooseVersion('1.0.10'):
            g.set_compound(compound)
            g.set_ranksep(ranksep)
        subgraphlabel = subgraphname if subgraphlabel is None else subgraphlabel
        subgraphlabel = self.escape_label(subgraphlabel)
        if subgraphlabel:
            g.set_label(subgraphlabel)
        if 'set_color' in g.__dict__:
            if color is not None:
                g.set_color(color)
        graph.add_subgraph(g)
github tryton / trytond / trytond / ir / model.py View on Github external
def fill_graph(cls, models, graph):
        'Fills pydot graph with models wizard.'
        import pydot
        pool = Pool()

        for record in models:
            Model = pool.get(record.model)

            if not issubclass(Model, Workflow):
                continue

            subgraph = pydot.Cluster('%s' % record.id, label=record.model)
            graph.add_subgraph(subgraph)

            state_field = getattr(Model, Model._transition_state)
            for state, _ in state_field.selection:
                node = pydot.Node(
                    '"%s"' % state, shape='octagon', label=state)
                subgraph.add_node(node)

            for from_, to in Model._transitions:
                edge = pydot.Edge('"%s"' % from_, '"%s"' % to,
                    arrowhead='normal')
                subgraph.add_edge(edge)