Update my_pages/multiverse.py
Browse files- my_pages/multiverse.py +12 -6
my_pages/multiverse.py
CHANGED
|
@@ -43,15 +43,21 @@ def build_tree_and_trace_path(selected_path):
|
|
| 43 |
next_nodes = []
|
| 44 |
|
| 45 |
# For layout niceness: compute a span for children under each parent
|
| 46 |
-
for parent_idx in prev_nodes:
|
| 47 |
px, py = node_positions[parent_idx]
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
for opt_idx, opt in enumerate(options):
|
| 51 |
child_x = float(stage_idx)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
node_index = len(node_labels)
|
| 56 |
node_labels.append(opt)
|
| 57 |
node_positions.append((child_x, child_y))
|
|
|
|
| 43 |
next_nodes = []
|
| 44 |
|
| 45 |
# For layout niceness: compute a span for children under each parent
|
| 46 |
+
for parent_order, parent_idx in enumerate(prev_nodes):
|
| 47 |
px, py = node_positions[parent_idx]
|
| 48 |
+
|
| 49 |
+
# (2) give each parent its own block of vertical space
|
| 50 |
+
parent_block_size = len(options) * y_spacing_base * (1.5 ** stage_idx)
|
| 51 |
+
base_y = py + (parent_order - (len(prev_nodes) - 1) / 2.0) * parent_block_size
|
| 52 |
+
|
| 53 |
for opt_idx, opt in enumerate(options):
|
| 54 |
child_x = float(stage_idx)
|
| 55 |
+
|
| 56 |
+
# (1) scale spacing UP with depth
|
| 57 |
+
# (3) nonlinear spreading with exponential factor
|
| 58 |
+
offset = (opt_idx - (len(options) - 1) / 2.0) * (y_spacing_base * (1.5 ** stage_idx))
|
| 59 |
+
|
| 60 |
+
child_y = base_y + offset
|
| 61 |
node_index = len(node_labels)
|
| 62 |
node_labels.append(opt)
|
| 63 |
node_positions.append((child_x, child_y))
|