(self, graph: FlowGraph, nodes: list[FlowGraphNode])
| 26 | |
| 27 | class RandomLayout(FlowGraphLayout): |
| 28 | def layout(self, graph: FlowGraph, nodes: list[FlowGraphNode]): |
| 29 | min_x = 0 |
| 30 | max_x = 0 |
| 31 | min_y = 0 |
| 32 | max_y = 0 |
| 33 | |
| 34 | max_extent = len(nodes) * 50 |
| 35 | |
| 36 | # Place nodes |
| 37 | for node in nodes: |
| 38 | x = random.randint(0, max_extent) |
| 39 | y = random.randint(0, max_extent) |
| 40 | |
| 41 | min_x = min(x, min_x) |
| 42 | max_x = max(x + node.width, max_x) |
| 43 | |
| 44 | min_y = min(y, min_y) |
| 45 | max_y = max(y + node.height, max_y) |
| 46 | |
| 47 | node.x = x |
| 48 | node.y = y |
| 49 | |
| 50 | # Place edges |
| 51 | for node in nodes: |
| 52 | for edge_num,edge in enumerate(node.outgoing_edges): |
| 53 | points = [ |
| 54 | (node.x + node.width/2, node.y + node.height), |
| 55 | (edge.target.x + edge.target.width/2, edge.target.y + edge.target.height) |
| 56 | ] |
| 57 | node.set_outgoing_edge_points(edge_num, points) |
| 58 | |
| 59 | # Calculate graph size and node visibility |
| 60 | for node in nodes: |
| 61 | min_node_x = node.x |
| 62 | max_node_x = node.x + node.width |
| 63 | |
| 64 | min_node_y = node.y |
| 65 | max_node_y = node.y + node.height |
| 66 | for edge in node.outgoing_edges: |
| 67 | for point in edge.points: |
| 68 | px, py = point |
| 69 | min_x = min(min_x, px) |
| 70 | min_y = min(min_y, py) |
| 71 | |
| 72 | max_x = max(max_x, px + 1) |
| 73 | max_y = max(max_y, py + 1) |
| 74 | |
| 75 | min_node_x = min(min_node_x, px) |
| 76 | max_node_x = max(max_node_x, px+1) |
| 77 | |
| 78 | min_node_y = min(min_node_y, py) |
| 79 | max_node_y = max(max_node_y, py+1) |
| 80 | |
| 81 | node.set_visibility_region(int(min_node_x), int(min_node_y), int(max_node_x - min_node_x), int(max_node_y - min_node_y)) |
| 82 | |
| 83 | graph.width = int(max_x - min_x) + graph.horizontal_block_margin*2 |
| 84 | graph.height = int(max_y - min_y) + graph.vertical_block_margin*2 |
| 85 |
no test coverage detected