Update app.py
Browse files
app.py
CHANGED
|
@@ -431,7 +431,8 @@ def make_figure(d: int,
|
|
| 431 |
edge_w: int,
|
| 432 |
path: List[int],
|
| 433 |
scale_base: float,
|
| 434 |
-
subsel: dict | None = None,
|
|
|
|
| 435 |
layout_mode: str = "default"):
|
| 436 |
nodes, edges = build_hypercube(d)
|
| 437 |
pts, width, height = layout_positions(d, base=scale_base, mode=layout_mode)
|
|
@@ -450,7 +451,16 @@ def make_figure(d: int,
|
|
| 450 |
if sel_active and sel_s is not None and sel_e is not None and path:
|
| 451 |
selected_vertices = set(path[sel_s:sel_e + 1])
|
| 452 |
|
| 453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
|
| 455 |
# ---------- neighbors of path vertices ----------
|
| 456 |
#neighbor_set = set()
|
|
@@ -575,6 +585,24 @@ def make_figure(d: int,
|
|
| 575 |
)
|
| 576 |
)
|
| 577 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
|
| 579 |
# ---------- nodes ----------
|
| 580 |
xs = [pos[v][0] for v in nodes]
|
|
@@ -601,6 +629,8 @@ def make_figure(d: int,
|
|
| 601 |
# --- size ---
|
| 602 |
if sel_active and v in selected_vertices:
|
| 603 |
sizes.append(base_size * 2.6)
|
|
|
|
|
|
|
| 604 |
elif mark_distances and v in neighbor_set:
|
| 605 |
sizes.append(base_size * 1.4)
|
| 606 |
else:
|
|
@@ -609,6 +639,8 @@ def make_figure(d: int,
|
|
| 609 |
# --- color ---
|
| 610 |
if sel_active and v in selected_vertices:
|
| 611 |
colors.append("#2563EB") # strong blue for selection
|
|
|
|
|
|
|
| 612 |
elif path and (v == path[0] or v == path[-1]):
|
| 613 |
colors.append("#111")
|
| 614 |
elif mark_negations and v in neg_set:
|
|
@@ -1146,6 +1178,7 @@ def update_path(clickData,
|
|
| 1146 |
Input("mark_negations", "value"),
|
| 1147 |
Input("mark_distances", "value"),
|
| 1148 |
Input("subpath_select_store", "data"),
|
|
|
|
| 1149 |
Input("layout_mode_store", "data"),
|
| 1150 |
)
|
| 1151 |
def render(d, show_labels_vals, path, mark_vals, mark_dist_vals, subsel, layout_mode):
|
|
@@ -1170,7 +1203,8 @@ def render(d, show_labels_vals, path, mark_vals, mark_dist_vals, subsel, layout_
|
|
| 1170 |
path=path or [],
|
| 1171 |
scale_base=float(DEFAULTS["scale"]),
|
| 1172 |
subsel=subsel or {},
|
| 1173 |
-
|
|
|
|
| 1174 |
)
|
| 1175 |
return fig
|
| 1176 |
|
|
|
|
| 431 |
edge_w: int,
|
| 432 |
path: List[int],
|
| 433 |
scale_base: float,
|
| 434 |
+
subsel: dict | None = None,
|
| 435 |
+
switchsel: dict | None = None,
|
| 436 |
layout_mode: str = "default"):
|
| 437 |
nodes, edges = build_hypercube(d)
|
| 438 |
pts, width, height = layout_positions(d, base=scale_base, mode=layout_mode)
|
|
|
|
| 451 |
if sel_active and sel_s is not None and sel_e is not None and path:
|
| 452 |
selected_vertices = set(path[sel_s:sel_e + 1])
|
| 453 |
|
| 454 |
+
# ---------- selected vertices for switch-dims (3 consecutive vertices) ----------
|
| 455 |
+
switchsel = switchsel or {}
|
| 456 |
+
switch_active = bool(switchsel.get("active"))
|
| 457 |
+
sw_s = switchsel.get("start_idx")
|
| 458 |
+
sw_e = switchsel.get("end_idx")
|
| 459 |
+
|
| 460 |
+
switch_vertices = set()
|
| 461 |
+
if switch_active and sw_s is not None and sw_e is not None and path:
|
| 462 |
+
switch_vertices = set(path[sw_s:sw_e + 1])
|
| 463 |
+
|
| 464 |
|
| 465 |
# ---------- neighbors of path vertices ----------
|
| 466 |
#neighbor_set = set()
|
|
|
|
| 585 |
)
|
| 586 |
)
|
| 587 |
|
| 588 |
+
# ---------- highlight switch-dims selection edges ----------
|
| 589 |
+
if switch_active and sw_s is not None and sw_e is not None and sw_e > sw_s:
|
| 590 |
+
for i in range(sw_s, sw_e):
|
| 591 |
+
a, b = path[i], path[i + 1]
|
| 592 |
+
x1, y1 = pos[a]
|
| 593 |
+
x2, y2 = pos[b]
|
| 594 |
+
edge_traces.append(
|
| 595 |
+
go.Scatter(
|
| 596 |
+
x=[x1, x2],
|
| 597 |
+
y=[y1, y2],
|
| 598 |
+
mode="lines",
|
| 599 |
+
line=dict(width=max(2, edge_w * 3), color="#DC2626"),
|
| 600 |
+
opacity=1.0,
|
| 601 |
+
hoverinfo="skip",
|
| 602 |
+
name="switch dims selection",
|
| 603 |
+
)
|
| 604 |
+
)
|
| 605 |
+
|
| 606 |
|
| 607 |
# ---------- nodes ----------
|
| 608 |
xs = [pos[v][0] for v in nodes]
|
|
|
|
| 629 |
# --- size ---
|
| 630 |
if sel_active and v in selected_vertices:
|
| 631 |
sizes.append(base_size * 2.6)
|
| 632 |
+
elif switch_active and v in switch_vertices:
|
| 633 |
+
sizes.append(base_size * 2.6)
|
| 634 |
elif mark_distances and v in neighbor_set:
|
| 635 |
sizes.append(base_size * 1.4)
|
| 636 |
else:
|
|
|
|
| 639 |
# --- color ---
|
| 640 |
if sel_active and v in selected_vertices:
|
| 641 |
colors.append("#2563EB") # strong blue for selection
|
| 642 |
+
elif switch_active and v in switch_vertices:
|
| 643 |
+
colors.append("#DC2626") # red for switch selection
|
| 644 |
elif path and (v == path[0] or v == path[-1]):
|
| 645 |
colors.append("#111")
|
| 646 |
elif mark_negations and v in neg_set:
|
|
|
|
| 1178 |
Input("mark_negations", "value"),
|
| 1179 |
Input("mark_distances", "value"),
|
| 1180 |
Input("subpath_select_store", "data"),
|
| 1181 |
+
Input("switch_dims_store", "data"),
|
| 1182 |
Input("layout_mode_store", "data"),
|
| 1183 |
)
|
| 1184 |
def render(d, show_labels_vals, path, mark_vals, mark_dist_vals, subsel, layout_mode):
|
|
|
|
| 1203 |
path=path or [],
|
| 1204 |
scale_base=float(DEFAULTS["scale"]),
|
| 1205 |
subsel=subsel or {},
|
| 1206 |
+
switchsel=switchsel or {},
|
| 1207 |
+
layout_mode=layout_mode or "default",
|
| 1208 |
)
|
| 1209 |
return fig
|
| 1210 |
|