How to use the pydot.Graph 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 pydot / pydot / test / test_pydot.py View on Github external
def digraph():
    return pydot.Graph("testgraph", graph_type="digraph")
github kevinw / gitviz / gitviz.py View on Github external
tooltip=shortsha()
        )
    else:
        opts.update(
            shape='ellipse',
            label=q(repr(obj)),
            style='filled',
            fillcolor='#ffffff'
        )

    if 'label' in opts:
        opts['label'] = opts['label'].strip()

    return opts

graph = pydot.Graph(verbose=True) # TODO: globals are bad mmmmkay
graph.set_bgcolor('#00000000')

def vert_for_sha(objstore, sha, **opts):
    if isinstance(sha, pydot.Node):
        sha = sha.sha

    vert = vertices.get(sha)
    try:
        obj = objstore[sha]
    except KeyError:
        return None

    if vert is None:
        vertex_opts = vertex_opts_for_obj(obj)
        vert = vertices[sha] = pydot.Node(sha, **vertex_opts)
        vert.sha = sha
github vincenthEE / DotEditor / pydot.py View on Github external
def set_parent_graph(self, parent_graph):
    
        self.obj_dict['parent_graph'] = parent_graph
        
        for obj_list in self.obj_dict['nodes'].itervalues():
            for obj in obj_list:
                obj['parent_graph'] = parent_graph

        for obj_list in self.obj_dict['edges'].itervalues():
            for obj in obj_list:
                obj['parent_graph'] = parent_graph

        for obj_list in self.obj_dict['subgraphs'].itervalues():
            for obj in obj_list:
                Graph(obj_dict=obj).set_parent_graph(parent_graph)
github relentless-warrior / LTEInspector / model / MC / trace2dot.py View on Github external
#print (lines)
    #slice list at "->"
    index=0
    states=[]
    for item in lines:
        if item.startswith("->"):
            last=index
            index=lines.index(item)
            states.append(lines[last:index]) # the first state is empty
    states.append(lines[index:len(lines)])

    print (states)

    lines=False #free space!
   
    graph = pydot.Graph()

    loop=False #flag to finally add an additional dotted edge for loop

    assert states[1][0].startswith("-> State:") #starting with state!

    digraph = 'Digraph G{\n'
    digraph += 'rankdir=LR\n'
    stateVariablesDict = OrderedDict()
    counter = 0
    for item in states[1:]: #first item is header
        name= item[0].lstrip("-> ").rstrip(" <-\n")
        if (name.startswith("State")):
            state=name.lstrip("State: ")
            node=pydot.Node(state)
            props=name+'\\n' #to reach pydotfile: need double '\'
            digraph =  digraph + 'S' + str(counter) + '[shape=box,label=\"' + name + '\\n'
github vincenthEE / DotEditor / pydot.py View on Github external
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)



class Subgraph(Graph):

    """Class representing a subgraph in Graphviz's dot language.

    This class implements the methods to work on a representation
    of a subgraph in Graphviz's dot language.
    
    subgraph(graph_name='subG', suppress_disconnected=False, attribute=value, ...)
    
    graph_name:
        the subgraph's name
    suppress_disconnected:
        defaults to false, which will remove from the
        subgraph any disconnected nodes.
    All the attributes defined in the Graphviz dot language should
    be supported.
github f3at / feat / src / feat / simulation / simgui / core / driver.py View on Github external
def export_drv_to_dot(drv, agent_list=[]):
    shards = {}
    edges = []

    cluster_count = 0
    agency_count = 1

    graph = pydot.Graph()
    for agency in drv._agencies:
        agency_name = 'agency %d' %(agency_count)
        agency_dot = pydot.Subgraph(
            graph_name = 'cluster_%d' %(cluster_count),
            label = agency_name,
            style="filled",
            color="lightyellow")
        cluster_count += 1
        agency_count += 1
        agency_added = False
        for agent in agency._agents:
            desc = agent.get_descriptor()
            if desc.doc_id in agent_list:
                continue

            shard_name = desc.shard
github kevinw / gitviz / pydot.py View on Github external
Graph.__init__(self, graph_name=graph_name, obj_dict=obj_dict,
            suppress_disconnected=suppress_disconnected, simplify=simplify, **attrs)

        if obj_dict is None:

            self.obj_dict['type'] = 'subgraph'
            self.obj_dict['name'] = 'cluster_'+graph_name

        self.create_attribute_methods(CLUSTER_ATTRIBUTES)



   


class Dot(Graph):
    """A container for handling a dot language file.

    This class implements methods to write and process
    a dot language file. It is a derived class of
    the base class 'Graph'.
    """
    
    
     
    def __init__(self, *argsl, **argsd):
        Graph.__init__(self, *argsl, **argsd)

        self.shape_files = list()

        self.progs = None
github odoo / odoo / bin / addons / base / ir / workflow / pydot / dot_parser.py View on Github external
for element in toks:
        if  isinstance(element, ParseResults) or    \
            isinstance(element, tuple) or           \
            isinstance(element, list):
            
            element = element[0]

        if element == 'strict':
            attrs['strict'] = True
        elif element in ['graph', 'digraph']:
            attrs['graph_type'] = element
        elif type(element) == type(''):
            attrs['graph_name'] = element
        elif isinstance(element, pydot.Graph):
            g = pydot.Graph(**attrs)
            g.__dict__.update(element.__dict__)
            for e in g.get_edge_list():
                e.parent_graph = g
            for e in g.get_node_list():
                e.parent_graph = g
            for e in g.get_subgraph_list():
                e.set_graph_parent(g)

        elif isinstance(element, P_AttrList):
            attrs.update(element.attrs)
        else:
            raise ValueError, "Unknown element statement: %r " % element
    
    if g is not None:
        g.__dict__.update(attrs)
        return g
github kevinw / gitviz / pydot.py View on Github external
def set_parent_graph(self, parent_graph):
    
        self.obj_dict['parent_graph'] = parent_graph
        
        for obj_list in self.obj_dict['nodes'].itervalues():
            for obj in obj_list:
                obj['parent_graph'] = parent_graph

        for obj_list in self.obj_dict['edges'].itervalues():
            for obj in obj_list:
                obj['parent_graph'] = parent_graph

        for obj_list in self.obj_dict['subgraphs'].itervalues():
            for obj in obj_list:
                Graph(obj_dict=obj).set_parent_graph(parent_graph)