How to use the pydot.Subgraph 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 tulip-control / dd / dd / bdd.py View on Github external
if roots is None:
        nodes = bdd._succ
        roots = list()
    else:
        nodes = bdd.descendants(roots)
    # show only levels in aggregate support
    levels = {bdd._succ[abs(u)][0] for u in nodes}
    assert bdd._succ[1][0] in levels
    g = pydot.Dot('bdd', graph_type='digraph')
    skeleton = list()
    subgraphs = dict()
    # layer for external BDD references
    layers = [-1] + sorted(levels)
    # add nodes for BDD levels
    for i in layers:
        h = pydot.Subgraph('', rank='same')
        g.add_subgraph(h)
        subgraphs[i] = h
        # add phantom node
        u = 'L{i}'.format(i=i)
        skeleton.append(u)
        if i == -1:
            # layer for external BDD references
            label = 'ref'
        else:
            # BDD level
            label = str(i)
        nd = pydot.Node(name=u, label=label, shape='none')
        h.add_node(nd)
    # auxiliary edges for ranking
    for i, u in enumerate(skeleton[:-1]):
        v = skeleton[i + 1]
github apache / subversion / tools / dev / mergegraph / mergegraph.py View on Github external
return None

    g = get_subgraph(graph, subg_name)
    if not g:
      g = pydot.Subgraph(subg_name, rank='same')
      graph.add_subgraph(g)

    ann_node = node + '_'
    while g.get_node(ann_node):
      ann_node = ann_node + '_'
    g.add_node(Node(ann_node, shape='box', style='filled', color=color,
                    label='"' + label + '"'))
    g.add_edge(Edge(ann_node, node, style='solid', color=color,
                    dir='none', constraint='false'))

class MergeSubgraph(MergeGraph, pydot.Subgraph):
  """"""
  def __init__(graph, **attrs):
    """"""
    MergeGraph.__init__(graph)
    pydot.Subgraph.__init__(graph, **attrs)

class MergeDot(MergeGraph, pydot.Dot):
  """
  # TODO: In the 'merges' input, find the predecessor automatically.
  """
  def __init__(graph, config_filename=None,
               filename=None, title=None, branches=None, changes=None,
               merges=[], annotations=[], **attrs):
    """Return a new MergeDot graph generated from a config file or args."""
    MergeGraph.__init__(graph)
    pydot.Dot.__init__(graph, **attrs)
github odoo / odoo / bin / addons / base / ir / workflow / pydot / dot_parser.py View on Github external
def push_graph_stmt(str, loc, toks):
    g = pydot.Subgraph()
    add_elements(g, toks)
    return g
github tulip-control / tulip-control / tulip / transys / export / graph2dot.py View on Github external
def _place_initial_states(trs_graph, pd_graph, tikz):
    init_subg = pydot.Subgraph('initial')
    init_subg.set_rank('source')

    for node in trs_graph.states.initial:
        pd_node = pydot.Node(make_str(node))
        init_subg.add_node(pd_node)

        phantom_node = 'phantominit' + str(node)
        pd_node = pydot.Node(make_str(phantom_node))
        init_subg.add_node(pd_node)

    pd_graph.add_subgraph(init_subg)
github micolous / cbus / cbus / toolkit / graph.py View on Github external
:param output: Output file name to write the graph to.
    :type output: str
    """
    networks = json.load(input)

    # warning: pydot has a bad case of the stupid and doesn't sanitise
    # inputs correctly.
    graph = pydot.Dot(output.replace('.', '_').replace('-', '_'),
                      graph_type='digraph')

    # create groups for networks
    for network_id, network in six.iteritems(networks):
        loads = set()

        subgraph = pydot.Subgraph('Network_%s' % network_id)
        # cluster = pydot.Cluster('Network %s' % network_id)

        for unit_id, unit in six.iteritems(network['units']):
            node = pydot.Node(unit['name'])
            subgraph.add_node(node)
            node.groups = unit['groups']
            [loads.add(x) for x in node.groups]
            for x in unit['groups']:
                if x == 255:
                    continue
                subgraph.add_edge(pydot.Edge(unit['name'], 'GA %s' % x))

        for group in loads:
            node = pydot.Node('GA %s' % group)

            subgraph.add_node(node)
github pydot / pydot / pydot.py View on Github external
def get_subgraph_list(self):
        """Get the list of Subgraph instances.

        This method returns the list of Subgraph instances
        in the graph.
        """

        sgraph_objs = list()

        for sgraph in self.obj_dict['subgraphs']:
                obj_dict_list = self.obj_dict['subgraphs'][sgraph]
                sgraph_objs.extend(
                    [Subgraph(obj_dict=obj_d)
                     for obj_d in obj_dict_list])

        return sgraph_objs
github pydot / pydot / pydot.py View on Github external
graph.append( node.to_string()+'\n' )

            elif obj['type'] == 'edge':

                edge = Edge(obj_dict=obj)

                if (self.obj_dict.get('simplify', False) and
                        edge in edges_done):
                    continue

                graph.append( edge.to_string() + '\n' )
                edges_done.add(edge)

            else:

                sgraph = Subgraph(obj_dict=obj)

                graph.append( sgraph.to_string()+'\n' )

        graph.append( '}\n' )

        return ''.join(graph)
github vincenthEE / DotEditor / pydot.py View on Github external
def get_subgraph_list(self):
        """Get the list of Subgraph instances.
        
        This method returns the list of Subgraph instances
        in the graph.
        """
        
        sgraph_objs = list()
        
        for sgraph, obj_dict_list in self.obj_dict['subgraphs'].iteritems():
                sgraph_objs.extend( [ Subgraph( obj_dict = obj_d ) for obj_d in obj_dict_list ] )
        
        return sgraph_objs