print(graph_name) # Sub Graph to be added input_subgraph_name = os.path.basename(subgraphpath) subgraph_name = subgraphpath.split(".")[0] # Reading graph and subgraph G = nx_read_dot(graphpath) nx.set_edge_attributes(G, 'red', 'color') SubG = nx_read_dot(subgraphpath) commonVertices = set(set(G.nodes()) & set(SubG.nodes())) avg_edge_length = avg_edge_length(G) if len(crossings.count_crossings_single_graph(G)): print(graph_name + " has crossings.") print("exiting") sys.exit() v_counter = 0 for commonVertex in commonVertices: v_counter += 1 translation_dx, translation_dy = vertexmanager.getCoordinate( G.node[commonVertex]) translateGraph(G, -translation_dx, -translation_dy) a_counter = 0 # # Extract subcomponents, draw, sacle and attach it to the widest sector for currN in set(nx.all_neighbors(SubG, commonVertex)):
def remove_crossings(G): while len(crossings.count_crossings_single_graph(G)): crs = crossings.count_crossings_single_graph(G) current_crossing_edges = crs[0] G_copy = G.copy() # Removing edges to separate graph G_copy.remove_edges_from(current_crossing_edges) # Getting the smaller component to be scaled smaller_component_vertices = list([ c for c in sorted( nx.connected_components(G_copy), key=len, reverse=True) ][-1]) # print(smaller_component_vertices) main_edge = "" main_vertex = "" other_vertex = "" # Getting the edge connecting the main and the smaller component for curr_edge in current_crossing_edges: s = curr_edge[0] t = curr_edge[1] if s in smaller_component_vertices: main_vertex = t other_vertex = s main_edge = curr_edge break if t in smaller_component_vertices: main_vertex = s other_vertex = t main_edge = curr_edge break # print("main: " + main_vertex) # print("other: " + other_vertex) # print(main_edge) # Translating the graph for better scaling translation_dx, translation_dy = vertexmanager.getCoordinate( G.node[main_vertex]) translateGraph(G, -translation_dx, -translation_dy) subcomponet_vertices = smaller_component_vertices subcomponet_edges = G.subgraph(subcomponet_vertices).copy().edges() H = nx.Graph() H.add_nodes_from(list(subcomponet_vertices)) H.add_node(main_vertex) nx.set_node_attributes(H, nx.get_node_attributes(G, 'pos'), 'pos') H.add_edges_from(list(subcomponet_edges)) H.add_edge(main_vertex, other_vertex) # print(nx.info(H)) # print(nx.get_node_attributes(H, 'pos')) scale(H, 0.5) # print(nx.get_node_attributes(H, 'pos')) nx.set_node_attributes(G, nx.get_node_attributes(H, 'pos'), 'pos') # print("changed") print("crossings:" + str(len(crossings.count_crossings_single_graph(G)))) return G