Update app.py
Browse files
app.py
CHANGED
|
@@ -281,6 +281,7 @@ def make_figure(d: int,
|
|
| 281 |
show_bits: bool,
|
| 282 |
show_ints: bool,
|
| 283 |
mark_negations: bool,
|
|
|
|
| 284 |
node_r: int,
|
| 285 |
edge_w: int,
|
| 286 |
path: List[int],
|
|
@@ -292,6 +293,15 @@ def make_figure(d: int,
|
|
| 292 |
path = path or []
|
| 293 |
in_path = set(path)
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
# ---------- negations (vertices + edges) ----------
|
| 296 |
neg_set = set()
|
| 297 |
neg_edges = set()
|
|
@@ -406,6 +416,8 @@ def make_figure(d: int,
|
|
| 406 |
colors.append("#111") # endpoints
|
| 407 |
elif mark_negations and v in neg_set:
|
| 408 |
colors.append("red") # negation vertices
|
|
|
|
|
|
|
| 409 |
else:
|
| 410 |
colors.append("#222")
|
| 411 |
|
|
@@ -498,8 +510,16 @@ app.layout = html.Div(
|
|
| 498 |
options=[{"label": " Mark negations", "value": "neg"}],
|
| 499 |
value=[], # unchecked by default
|
| 500 |
style={"marginTop": "0px"},
|
| 501 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
]),
|
|
|
|
| 503 |
html.Div(), # empty cell just to keep the grid tidy
|
| 504 |
],
|
| 505 |
),
|
|
@@ -725,8 +745,9 @@ def update_path(clickData,
|
|
| 725 |
Input("show_labels", "value"),
|
| 726 |
Input("path_store", "data"),
|
| 727 |
Input("mark_negations", "value"),
|
|
|
|
| 728 |
)
|
| 729 |
-
def render(d, show_labels_vals, path, mark_vals):
|
| 730 |
labels_vals = show_labels_vals or []
|
| 731 |
show_bits = "bits" in labels_vals
|
| 732 |
show_ints = "ints" in labels_vals
|
|
@@ -734,11 +755,15 @@ def render(d, show_labels_vals, path, mark_vals):
|
|
| 734 |
mark_vals = mark_vals or []
|
| 735 |
mark_negations = "neg" in mark_vals
|
| 736 |
|
|
|
|
|
|
|
|
|
|
| 737 |
fig = make_figure(
|
| 738 |
d=int(d),
|
| 739 |
show_bits=show_bits,
|
| 740 |
show_ints=show_ints,
|
| 741 |
mark_negations=mark_negations,
|
|
|
|
| 742 |
node_r=DEFAULTS["node_radius"],
|
| 743 |
edge_w=DEFAULTS["edge_width"],
|
| 744 |
path=path or [],
|
|
|
|
| 281 |
show_bits: bool,
|
| 282 |
show_ints: bool,
|
| 283 |
mark_negations: bool,
|
| 284 |
+
mark_distances: bool,
|
| 285 |
node_r: int,
|
| 286 |
edge_w: int,
|
| 287 |
path: List[int],
|
|
|
|
| 293 |
path = path or []
|
| 294 |
in_path = set(path)
|
| 295 |
|
| 296 |
+
# ---------- neighbors of path vertices ----------
|
| 297 |
+
neighbor_set = set()
|
| 298 |
+
if mark_distances and path:
|
| 299 |
+
for v in in_path:
|
| 300 |
+
for bit in range(d):
|
| 301 |
+
u = v ^ (1 << bit)
|
| 302 |
+
if u not in in_path:
|
| 303 |
+
neighbor_set.add(u)
|
| 304 |
+
|
| 305 |
# ---------- negations (vertices + edges) ----------
|
| 306 |
neg_set = set()
|
| 307 |
neg_edges = set()
|
|
|
|
| 416 |
colors.append("#111") # endpoints
|
| 417 |
elif mark_negations and v in neg_set:
|
| 418 |
colors.append("red") # negation vertices
|
| 419 |
+
elif mark_distances and v in neighbor_set:
|
| 420 |
+
colors.append("yellow") # negation vertices
|
| 421 |
else:
|
| 422 |
colors.append("#222")
|
| 423 |
|
|
|
|
| 510 |
options=[{"label": " Mark negations", "value": "neg"}],
|
| 511 |
value=[], # unchecked by default
|
| 512 |
style={"marginTop": "0px"},
|
| 513 |
+
),
|
| 514 |
+
html.Div(style={"height": "4px"}), # small gap
|
| 515 |
+
dcc.Checklist(
|
| 516 |
+
id="mark_distances",
|
| 517 |
+
options=[{"label": " Mark distances", "value": "dist"}],
|
| 518 |
+
value=[], # unchecked by default
|
| 519 |
+
style={"marginTop": "0px"},
|
| 520 |
+
),
|
| 521 |
]),
|
| 522 |
+
|
| 523 |
html.Div(), # empty cell just to keep the grid tidy
|
| 524 |
],
|
| 525 |
),
|
|
|
|
| 745 |
Input("show_labels", "value"),
|
| 746 |
Input("path_store", "data"),
|
| 747 |
Input("mark_negations", "value"),
|
| 748 |
+
Input("mark_distances", "value"),
|
| 749 |
)
|
| 750 |
+
def render(d, show_labels_vals, path, mark_vals, mark_dist_vals):
|
| 751 |
labels_vals = show_labels_vals or []
|
| 752 |
show_bits = "bits" in labels_vals
|
| 753 |
show_ints = "ints" in labels_vals
|
|
|
|
| 755 |
mark_vals = mark_vals or []
|
| 756 |
mark_negations = "neg" in mark_vals
|
| 757 |
|
| 758 |
+
mark_dist_vals = mark_dist_vals or []
|
| 759 |
+
mark_distances = "dist" in mark_dist_vals
|
| 760 |
+
|
| 761 |
fig = make_figure(
|
| 762 |
d=int(d),
|
| 763 |
show_bits=show_bits,
|
| 764 |
show_ints=show_ints,
|
| 765 |
mark_negations=mark_negations,
|
| 766 |
+
mark_distances=mark_distances,
|
| 767 |
node_r=DEFAULTS["node_radius"],
|
| 768 |
edge_w=DEFAULTS["edge_width"],
|
| 769 |
path=path or [],
|