def monotone_draw(G, root, edge_length): """ take tree assign unique slope use tan-1 for slopes if path, may consider same slop run DFS """ i = 0 # starting with zero angle vertexmanager.setCoordinate(G.node[root], 0.0, 0.0) for e in nx.dfs_edges(G, root): u, v = e slp = math.atan(i) x_u, y_u = vertexmanager.getCoordinate(G.node[u]) x_v = x_u + math.cos(slp) y_v = y_u + math.sin(slp) vertexmanager.setCoordinate(G.node[v], x_v + edge_length, y_v + edge_length) i = i + 1 return G
def rotate(G, angle): angle = math.radians(angle) for currVertex in nx.nodes(G): x, y = vertexmanager.getCoordinate(G.node[currVertex]) x_rot = x * math.cos(angle) - y * math.sin(angle) y_rot = x * math.sin(angle) + y * math.cos(angle) vertexmanager.setCoordinate(G.node[currVertex], x_rot, y_rot) return G
def scale(G, scaling_factor): all_pos = nx.get_node_attributes(G, "pos").values() coo_x = sorted([float(p.split(",")[0]) for p in all_pos]) coo_y = sorted([float(p.split(",")[1]) for p in all_pos]) min_x = float(coo_x[0]) min_y = float(coo_y[0]) for currVertex in nx.nodes(G): v = G.node[currVertex] v_x, v_y = vertexmanager.getCoordinate(v) v_x_scaled = v_x * scaling_factor v_y_scaled = v_y * scaling_factor vertexmanager.setCoordinate(v, v_x_scaled, v_y_scaled) return G