def construct_directed_graph(collections_data: List[CollectionData]) -> AGraph:

    graph = AGraph(directed=True, fontzise=10, fontname='Verdana')
    graph.node_attr['fontname'] = 'Verdana'
    graph.node_attr['shape'] = 'record'

    collection_direction_order_ids = [
        collection.id for collection in collections_data
    ]
    collection_names = [collection.name for collection in collections_data]

    # draw "y axe" with tree ordering
    graph.add_nodes_from(collection_names, shape='plaintext', fontsize=14)
    graph.add_edges_from(zip(collection_names, collection_names[1:]))
    graph.add_subgraph(collection_names)

    # combine all pages in one graph
    for collection_data in collections_data:
        for page in collection_data.pages:
            node = get_node(page)
            graph.add_node(node, label=page.title)
            # don't include reversed relations:
            edges = get_edges(page, collection_direction_order_ids)
            graph.add_edges_from(edges)

        # align all nodes for one level in one line (include element from "y" line for alignment)
        one_level_nodes = [collection_data.name] + [
            get_node(page) for page in collection_data.pages
        ]
        graph.add_subgraph(one_level_nodes, None, rank='same')

    return graph
Beispiel #2
0
def build_graph(ts):
    g = AGraph(directed=True)
    g.add_edges_from(ts.ts.todok().keys())
    g.graph_attr['overlap'] = 'scalexy'
    for n, s in zip(g.nodes(), ts._pwa.states):
        n.attr['label'] = s
    return g
Beispiel #3
0
def gen_graph_bundle_dep(exp_file, idx_map):
    G = AGraph(directed=True, strict=True)
    G.graph_attr['splines'] = 'true'
    G.graph_attr['overlap'] = 'false'
    #G.graph_attr['ordering'] = 'out'
    #G.graph_attr['concentrate'] = 'false'
    keys = [key for key in idx_map.keys()]
    values = []
    for lst in idx_map.values():
        for item in lst:
            if not item in values:
                values.append(item)
    kvp_list = []
    for key in idx_map.keys():
        for val in idx_map[key]:
            kvp_list.append((key, val))

    G.add_nodes_from(keys, color='green', style='filled')
    for val in values:
        if val.count('#exist'):
            G.add_node(val, color='yellow', style='filled')
        elif val.count('#miss'):
            G.add_node(val, color='red', style='filled')
    #G.add_nodes_from(values, color = 'red', style = 'filled')
    G.add_edges_from(kvp_list, color='blue')
    G.layout(prog='sfdp')
    G.draw(exp_file)
Beispiel #4
0
    def networkx_visualize(self, filename):
        dgraph = AGraph(strict=False, directed=True)

        for n in self.subgraph.get_nodes():
            self.subgraph._add_nx_subgraph(dgraph, n)

        dgraph.add_edges_from(self.subgraph.get_viz_edge_list())

        dgraph.layout("dot")
        dgraph.draw(f"{filename}.pdf", format="pdf")
Beispiel #5
0
def gen_graph_res_idx(exp_file, idx_map):
    keys = [key for key in idx_map.keys()]
    values = []
    for val in idx_map.values():
        if not val in values:
            values.append(val)

    G = AGraph(directed=True, strict=True)
    G.graph_attr['splines'] = 'true'
    G.graph_attr['overlap'] = 'false'
    #G.graph_attr['ordering'] = 'out'
    #G.graph_attr['concentrate'] = 'false'
    G.add_nodes_from(keys, color='green', style='filled')
    G.add_nodes_from(values, color='red', style='filled')
    G.add_edges_from(idx_map.items(), color='blue')
    G.layout(prog=GRAPH_PROG)
    G.draw(exp_file)
Beispiel #6
0
def draw_graph(sparse, f):
    g = AGraph(directed=True)
    g.add_edges_from(sparse.todok().keys())
    g.draw(f, prog='neato')