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
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)
def draw_finite_state_machine(finite_state_machine: FiniteStateMachine, path: str): """Creates a directed non-strict multi graph image representation of the FSM.""" from pygraphviz import AGraph graph = AGraph(strict=False, directed=True) graph.add_nodes_from(finite_state_machine.state_set) for initial_state in finite_state_machine.initial_states: graph.get_node(initial_state).attr["color"] = "green" for element, transitions in finite_state_machine.transitions.items(): for from_state, to_states in transitions.items(): for to_state in to_states: graph.add_edge(from_state, to_state, label=element) for final_state in finite_state_machine.final_states: graph.get_node(final_state).attr["color"] = "red" graph.draw(path, prog="dot")
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)
def draw_graph(state_manager, filename): graph = AGraph() graph.node_attr["style"] = "filled" graph.node_attr["shape"] = "circle" graph.node_attr["fixedsize"] = "true" graph.node_attr["width"] = 0.5 graph.node_attr["height"] = 0.5 # we add all nodes (keys = ID) graph.add_nodes_from(state_manager.state.keys()) for var_id in state_manager.state: # and for each of these nodes, we change color node = graph.get_node(var_id) node.attr["fillcolor"] = get_color(state_manager.state[var_id]) # finally, we add edges for c in state_manager.constraints: e = c.list_vars graph.add_edge(e[0], e[1]) graph.write(filename)