Пример #1
0
def get_nodes_and_edges(name='my_graph'):
    graph = Graph(cleanup(name))
    edges = []
    for orm_node in Node.objects.select_related():
        graph.add_node(get_node(orm_node.name))
        for parent in orm_node.parent.iterator():
            edges.append((cleanup(parent.parent.name),cleanup(parent.child.name)))

        for child in orm_node.child.iterator():
            edges.append((cleanup(child.parent.name),cleanup(child.child.name)))            

    edges = list(set(edges)) # remove duplicates   
    for edge in edges:
        e = Edge(edge[0],edge[1])
        e.set_target('_parent')        
        e.set_arrowhead('vee')
        graph.add_edge(e)            
    return graph
Пример #2
0
def get_node_and_edges(name):
    graph = Graph(cleanup(name))
    orm_node = Node.objects.select_related().get(name=name)    
    other_nodes = [x for x in orm_node.parent.iterator()]
    other_nodes += [x for x in orm_node.child.iterator()]
    edges = []
    node_check = [] # used to make sure we don't add the same node twice
    for other_node in other_nodes:
        if other_node.parent.name not in node_check:
            graph.add_node(get_node(other_node.parent.name))
            node_check.append(other_node.parent.name)
        if other_node.child.name not in node_check:
            graph.add_node(get_node(other_node.child.name))        
            node_check.append(other_node.child.name)

        # edges are tuples
        edges.append((cleanup(other_node.parent.name),cleanup(other_node.child.name))) 

    edges = list(set(edges)) # remove duplicates
    for edge in edges:
        e = Edge(edge[0],edge[1])
        e.set_arrowhead('vee')
        graph.add_edge(e)
    return graph