Update app.py
Browse files
app.py
CHANGED
|
@@ -279,7 +279,6 @@ def make_figure(d: int,
|
|
| 279 |
show_bits: bool,
|
| 280 |
show_ints: bool,
|
| 281 |
mark_negations: bool,
|
| 282 |
-
mark_distances: bool,
|
| 283 |
node_r: int,
|
| 284 |
edge_w: int,
|
| 285 |
path: List[int],
|
|
@@ -291,26 +290,6 @@ def make_figure(d: int,
|
|
| 291 |
path = path or []
|
| 292 |
in_path = set(path)
|
| 293 |
|
| 294 |
-
# ---------- Distances Logic (New) ----------
|
| 295 |
-
dist2_set = set()
|
| 296 |
-
if mark_distances and path:
|
| 297 |
-
# 1. Identify all nodes at distance 0 or 1 from the path
|
| 298 |
-
# (We want strict distance 2)
|
| 299 |
-
forbidden = set()
|
| 300 |
-
for p_v in path:
|
| 301 |
-
forbidden.add(p_v)
|
| 302 |
-
for bit in range(d):
|
| 303 |
-
forbidden.add(p_v ^ (1 << bit))
|
| 304 |
-
|
| 305 |
-
# 2. Identify neighbors of neighbors (potential dist 2)
|
| 306 |
-
# and filter out those in forbidden set
|
| 307 |
-
for p_v in path:
|
| 308 |
-
for b1 in range(d):
|
| 309 |
-
for b2 in range(b1 + 1, d):
|
| 310 |
-
neighbor2 = p_v ^ (1 << b1) ^ (1 << b2)
|
| 311 |
-
if neighbor2 not in forbidden:
|
| 312 |
-
dist2_set.add(neighbor2)
|
| 313 |
-
|
| 314 |
# ---------- negations (vertices + edges) ----------
|
| 315 |
neg_set = set()
|
| 316 |
neg_edges = set()
|
|
@@ -422,23 +401,10 @@ def make_figure(d: int,
|
|
| 422 |
sizes.append(base_size * (3 if v in in_path else 1))
|
| 423 |
|
| 424 |
if path and (v == path[0] or v == path[-1]):
|
| 425 |
-
|
| 426 |
-
colors.append("#111")
|
| 427 |
-
elif v in in_path:
|
| 428 |
-
sizes.append(base_size * 3)
|
| 429 |
-
colors.append("#222")
|
| 430 |
-
|
| 431 |
-
# --- INSERT THIS ELIF BLOCK ---
|
| 432 |
-
elif v in dist2_set:
|
| 433 |
-
sizes.append(base_size * 2.5) # Slightly larger
|
| 434 |
-
colors.append("#FFD700") # Gold color
|
| 435 |
-
# ------------------------------
|
| 436 |
-
|
| 437 |
elif mark_negations and v in neg_set:
|
| 438 |
-
|
| 439 |
-
colors.append("red")
|
| 440 |
else:
|
| 441 |
-
sizes.append(base_size)
|
| 442 |
colors.append("#222")
|
| 443 |
|
| 444 |
node_trace = go.Scatter(
|
|
@@ -532,13 +498,7 @@ app.layout = html.Div(
|
|
| 532 |
style={"marginTop": "0px"},
|
| 533 |
)
|
| 534 |
]),
|
| 535 |
-
html.Div(
|
| 536 |
-
dcc.Checklist(
|
| 537 |
-
id="mark_distances",
|
| 538 |
-
options=[{"label": " Mark dist=2", "value": "dist2"}],
|
| 539 |
-
value=[], style={"marginTop": "0px"},
|
| 540 |
-
)
|
| 541 |
-
]),
|
| 542 |
],
|
| 543 |
),
|
| 544 |
|
|
@@ -763,19 +723,20 @@ def update_path(clickData,
|
|
| 763 |
Input("show_labels", "value"),
|
| 764 |
Input("path_store", "data"),
|
| 765 |
Input("mark_negations", "value"),
|
| 766 |
-
Input("mark_distances", "value"),
|
| 767 |
)
|
| 768 |
-
def render(d, show_labels_vals, path, mark_vals
|
| 769 |
labels_vals = show_labels_vals or []
|
|
|
|
|
|
|
|
|
|
| 770 |
mark_vals = mark_vals or []
|
| 771 |
-
|
| 772 |
-
|
| 773 |
fig = make_figure(
|
| 774 |
d=int(d),
|
| 775 |
-
show_bits=
|
| 776 |
-
show_ints=
|
| 777 |
-
mark_negations=
|
| 778 |
-
mark_distances=("dist2" in dist_vals), # <--- Pass the boolean
|
| 779 |
node_r=DEFAULTS["node_radius"],
|
| 780 |
edge_w=DEFAULTS["edge_width"],
|
| 781 |
path=path or [],
|
|
|
|
| 279 |
show_bits: bool,
|
| 280 |
show_ints: bool,
|
| 281 |
mark_negations: bool,
|
|
|
|
| 282 |
node_r: int,
|
| 283 |
edge_w: int,
|
| 284 |
path: List[int],
|
|
|
|
| 290 |
path = path or []
|
| 291 |
in_path = set(path)
|
| 292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
# ---------- negations (vertices + edges) ----------
|
| 294 |
neg_set = set()
|
| 295 |
neg_edges = set()
|
|
|
|
| 401 |
sizes.append(base_size * (3 if v in in_path else 1))
|
| 402 |
|
| 403 |
if path and (v == path[0] or v == path[-1]):
|
| 404 |
+
colors.append("#111") # endpoints
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
elif mark_negations and v in neg_set:
|
| 406 |
+
colors.append("red") # negation vertices
|
|
|
|
| 407 |
else:
|
|
|
|
| 408 |
colors.append("#222")
|
| 409 |
|
| 410 |
node_trace = go.Scatter(
|
|
|
|
| 498 |
style={"marginTop": "0px"},
|
| 499 |
)
|
| 500 |
]),
|
| 501 |
+
html.Div(), # empty cell just to keep the grid tidy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
],
|
| 503 |
),
|
| 504 |
|
|
|
|
| 723 |
Input("show_labels", "value"),
|
| 724 |
Input("path_store", "data"),
|
| 725 |
Input("mark_negations", "value"),
|
|
|
|
| 726 |
)
|
| 727 |
+
def render(d, show_labels_vals, path, mark_vals):
|
| 728 |
labels_vals = show_labels_vals or []
|
| 729 |
+
show_bits = "bits" in labels_vals
|
| 730 |
+
show_ints = "ints" in labels_vals
|
| 731 |
+
|
| 732 |
mark_vals = mark_vals or []
|
| 733 |
+
mark_negations = "neg" in mark_vals
|
| 734 |
+
|
| 735 |
fig = make_figure(
|
| 736 |
d=int(d),
|
| 737 |
+
show_bits=show_bits,
|
| 738 |
+
show_ints=show_ints,
|
| 739 |
+
mark_negations=mark_negations,
|
|
|
|
| 740 |
node_r=DEFAULTS["node_radius"],
|
| 741 |
edge_w=DEFAULTS["edge_width"],
|
| 742 |
path=path or [],
|