diff --git a/meshterm/ui/node_detail_screen.py b/meshterm/ui/node_detail_screen.py index b30b609..ad146a8 100644 --- a/meshterm/ui/node_detail_screen.py +++ b/meshterm/ui/node_detail_screen.py @@ -97,7 +97,6 @@ from .pathgraph import ( LabelOf, LabelRgbOf, PathLayer, - _coalesce_prefixes, bidir_clusters, render_path_graph, ) @@ -895,7 +894,7 @@ class NodeDetailScreen(Screen): return self._stage_memo[1] # Priority is fixed by evidence order (route 0, the best-evidence route, is always the # spine) so the fan's geometry never moves as the selection changes — only emphasis - # (which route is drawn white and on top) and the label muting below follow the pick. + # (which route draws white and on top, and which nodes keep their hue) follows the pick. layers = [ PathLayer( hops=route.draw, @@ -905,19 +904,13 @@ class NodeDetailScreen(Screen): ) for i, route in enumerate(rv.routes) ] - # A node keeps its name hue only while it sits on the selected route (its endpoints - # always do); every other node in the fan fades its label to the same grey its line - # went, so the picture reads as *this* route rather than the whole tangle. - # Membership is decided in the graph's own id space: the widget folds a short hop - # into the wide id it can only be among these routes (a 1-byte trace hop beside the - # same relay's full contact id), so the raw draw hops would grey the very marker the - # selected line rides through. - on_route = set(_coalesce_prefixes(layers)[sel].hops) | {SRC_NODE, DST_NODE} - base_rgb = rv.label_rgb_of - assert base_rgb is not None - - def label_rgb_of(node: str): - return base_rgb(node) if node in on_route else _GREY + # A node keeps its hue only while it sits on the selected route, and everything off it + # — marker and label — recedes to grey. That is the widget's own rule now (see + # :func:`~meshterm.ui.pathgraph.render_path_graph`), decided in the graph's own id + # space, so a route reaching a relay by a short hash still lights the wide marker its + # hop is folded into. + label_rgb_of = rv.label_rgb_of + assert label_rgb_of is not None lines = list( render_path_graph( diff --git a/meshterm/ui/pathgraph.py b/meshterm/ui/pathgraph.py index bb0cb39..82aa104 100644 --- a/meshterm/ui/pathgraph.py +++ b/meshterm/ui/pathgraph.py @@ -82,6 +82,14 @@ over and then settles. Concretely: exactly once, however many routes share it; the one edge drawn as a bare vertical is a pair of nodes walked in *both* directions — a genuine two-way hop, the sole place a straight up-and-down line tells the truth; +* **the highlight recedes the rest** — where one layer is emphasised over the others, it is + the *only* path drawn in colour: every node it does not ride draws its marker and its label + in one dark grey (:data:`_OFF_ROUTE`), the same dim its unused lines already carry. A fan is + one route read against its alternatives, and full-hue markers strewn along the grey lines + argued with the very thing the emphasis was saying. The endpoints are never dimmed (every + path runs through them), and the glyphs keep their shapes — a repeater is still ``▲`` + off-route, only its ink recedes. With no emphasis to compare (a single path, or a fan whose + layers are all equal) nothing is faded and the caller's colours stand as given; * **labels** sit straight above or below their marker — pushed to the side away from the graph's middle, a spot clear of the drawn lines preferred — and endpoints slide their label inward from the canvas edge so a long name still lands by its marker. A caller that @@ -170,6 +178,16 @@ _BEND_K = 0.4 #: and marks the node → us direction without crowding the endpoint. _ARROW_GAP_DOTS = 2 +#: The dim every node *off* the highlighted path draws in — its marker and its label +#: alike, in both encodings the callbacks speak. A fan's whole point is one route read +#: against its alternatives, and the picture only says which route that is if everything +#: not on it recedes: the unused lines already draw grey, and a full-hue marker with a +#: full-hue label sitting on one is the loudest thing in the frame (JP, 2026-09-04). Any +#: value in this range folds to the console's dark-grey slot, so the rule survives the +#: 16-colour quantizer unchanged. +_OFF_ROUTE: RGB = (110, 110, 110) +_OFF_ROUTE_HEX = "#%02x%02x%02x" % _OFF_ROUTE + #: Most distinct paths the lane order is optimised over by exhaustive search. Beyond it the #: search space (``(n-1)!`` orders of the non-central lanes) is too large, so a barycentre #: heuristic seats the lanes instead. The widget's real inputs sit far under this. @@ -417,6 +435,46 @@ def _draw_rank(layer: PathLayer) -> int: return layer.priority + layer.emphasis * _EMPHASIS_BOOST +def _highlighted( + drawn: Sequence[PathLayer], seqs: Sequence[tuple[str, ...]] +) -> Optional[set[str]]: + """The nodes on the one emphasised path, or ``None`` when no single path is singled out. + + A highlight is a *comparison*, so it takes at least two paths and exactly one winner: a + lone path has nothing to be read against, and a fan whose layers all carry the same + emphasis (the default — a picture with no selection at all) has no route to fade toward. + Both cases return ``None``, and the caller's colours are then used exactly as given. + + The returned set carries the endpoints, since every path runs through them: the origin and + us are never the thing a selection distinguishes. + """ + if len(drawn) < 2: + return None + top = max(layer.emphasis for layer in drawn) + lit = [i for i, layer in enumerate(drawn) if layer.emphasis == top] + return set(seqs[lit[0]]) if len(lit) == 1 else None + + +def _dim_off_route( + glyph_of: GlyphOf, label_rgb_of: LabelRgbOf, lit: set[str] +) -> tuple[GlyphOf, LabelRgbOf]: + """Wrap the marker/label colour callbacks to draw everything outside ``lit`` grey. + + The caller's own callbacks are still asked for every node *on* the highlighted path, so + a node keeps whatever hue its screen gives it there; off it, neither callback is consulted + for a colour that would be thrown away. The glyph itself is untouched — a repeater is + still ``▲`` off-route, it is only the ink that recedes. + """ + def glyph(node: str) -> tuple[str, str]: + mark, colour = glyph_of(node) + return mark, (colour if node in lit else _OFF_ROUTE_HEX) + + def rgb(node: str) -> RGB: + return label_rgb_of(node) if node in lit else _OFF_ROUTE + + return glyph, rgb + + def render_path_graph( layers: Sequence[PathLayer], width: int, @@ -477,6 +535,15 @@ def render_path_graph( glyph_of, label_of, label_rgb_of = _unqualified(glyph_of, label_of, label_rgb_of) seqs = [(SRC_NODE, *layer.hops, DST_NODE) for layer in drawn] + # Where one path is emphasised over the rest, everything not on it recedes: the nodes + # the highlight rides keep their hue, every other marker and label draws :data:`_OFF_ROUTE` + # grey. Membership is tested in the graph's *own* id space — after the prefix coalesce, + # the identical-path collapse and the revisit split — so a relay the selected route reaches + # by a short hash still counts as ridden once it is folded into the wide marker drawn for it. + lit = _highlighted(drawn, seqs) + if lit is not None: + glyph_of, label_rgb_of = _dim_off_route(glyph_of, label_rgb_of, lit) + # First-appearance order for every node, so the layout is identical on every repaint: a # set of hash-seeded string ids would iterate in a run-varying order and let the passes # settle differently each time, making the graph jump between frames. diff --git a/tests/test_node_detail.py b/tests/test_node_detail.py index 2753dc9..7d3585c 100644 --- a/tests/test_node_detail.py +++ b/tests/test_node_detail.py @@ -951,14 +951,14 @@ def test_route_labels_light_through_a_coalesced_hop() -> None: Route evidence reaches the page at mixed hash widths — a 1-byte trace hop (``3d``) beside the same relay's full id on a sibling route. The graph coalesces the short id - into the one wide marker, so the label muting must test membership against the *drawn* - ids: keyed on the raw draw hops, the selected route's own relay rendered muted while - the white line rode straight through it (the TSFCT SUTTON-680M report). + into the one wide marker, so the off-route dimming must test membership against the + *drawn* ids: keyed on the raw draw hops, the selected route's own relay rendered muted + while the white line rode straight through it (the TSFCT SUTTON-680M report). """ lit: list[str] = [] def base_rgb(node: str) -> tuple[int, int, int]: - lit.append(node) # the stage's muting wrapper only consults us for on-route nodes + lit.append(node) # the widget only consults us for nodes on the selected route return (200, 200, 200) routes = _RoutesView( diff --git a/tests/test_pathgraph.py b/tests/test_pathgraph.py index 3340edf..07eebce 100644 --- a/tests/test_pathgraph.py +++ b/tests/test_pathgraph.py @@ -10,6 +10,7 @@ from meshterm.ui.pathgraph import ( DST_NODE, SRC_NODE, _GRAPH_PAD_DOTS, + _OFF_ROUTE as OFF_ROUTE, _LANE_PITCH_ROWS, _OCCURRENCE_SEP, PathLayer, @@ -790,3 +791,72 @@ def test_labels_ellipsize_only_when_wider_than_the_canvas() -> None: assert name not in plain # the full 30-cell name cannot fit a 20-cell canvas assert "…" in plain # so it is ellipsized to what fits assert all(len(_ANSI.sub("", ln)) <= 20 for ln in lines) # never overruns the width + + +def test_the_emphasised_path_is_the_only_one_drawn_in_colour() -> None: + """Off the highlighted path, every marker and label recedes to the off-route grey. + + The fan says *which* route it is about only if everything not on it dims: the unused + lines already draw grey, and a full-hue marker sitting on one is the loudest thing in + the picture. The endpoints are on every path, so they keep their colour. + """ + layers = [ + PathLayer(hops=("aa",), color=WHITE, priority=2, emphasis=1), + PathLayer(hops=("bb", "cc"), color=GREY, priority=1), + ] + body = "\n".join(render_path_graph( + layers, 60, + glyph_of=_glyph, + label_of=lambda node: "you" if node in (SRC_NODE, DST_NODE) else node, + label_rgb_of=lambda _node: GREEN, + )) + lit = [ln for ln in body.split("\n") if "aa" in _ANSI.sub("", ln)] + dim = [ln for ln in body.split("\n") if "bb" in _ANSI.sub("", ln)] + assert lit and _sgr(GREEN) in lit[0], "the selected route's label keeps its hue" + assert dim and _sgr(GREEN) not in dim[0] + assert _sgr(OFF_ROUTE) in dim[0], "an off-route label draws in the off-route grey" + # The marker recedes with the label: the relay glyph's own colour is drawn for the + # on-route node and never for the off-route one, which draws grey twice over (mark + label). + assert _sgr((0x65, 0x43, 0x21)) in body, "an on-route relay keeps its marker colour" + assert body.count(_sgr(OFF_ROUTE)) > 1 + + +def test_a_fan_with_nothing_emphasised_fades_nothing() -> None: + """No emphasis is no selection: with every layer equal there is no route to recede from, + and the caller's colours are used exactly as given.""" + layers = [ + PathLayer(hops=("aa",), color=WHITE, priority=2), + PathLayer(hops=("bb",), color=GREY, priority=1), + ] + body = "\n".join(render_path_graph( + layers, 60, glyph_of=_glyph, + label_of=lambda node: "you" if node in (SRC_NODE, DST_NODE) else node, + label_rgb_of=lambda _node: GREEN, + )) + assert _sgr(OFF_ROUTE) not in body + assert body.count(_sgr(GREEN)) >= 2 # both relays' labels keep the hue they were given + + +def test_a_lone_path_is_never_faded() -> None: + """One path has nothing to be read against, emphasised or not.""" + body = "\n".join(render_path_graph( + [PathLayer(hops=("aa",), color=WHITE, priority=1, emphasis=1)], 60, + glyph_of=_glyph, label_of=lambda node: node[:2], label_rgb_of=lambda _node: GREEN, + )) + assert _sgr(OFF_ROUTE) not in body + + +def test_the_highlight_lights_a_relay_reached_by_a_short_hash() -> None: + """Membership is decided in the graph's own id space, after the prefix coalesce: a route + that names a relay ``3d`` still lights the wide marker its hop is folded into.""" + layers = [ + PathLayer(hops=("3d63c6429436",), color=GREY, priority=2), + PathLayer(hops=("3d",), color=WHITE, priority=1, emphasis=1), + ] + body = "\n".join(render_path_graph( + layers, 60, glyph_of=_glyph, + label_of=lambda node: "you" if node in (SRC_NODE, DST_NODE) else node[:2], + label_rgb_of=lambda _node: GREEN, + )) + assert _sgr(OFF_ROUTE) not in body, "the one relay drawn is on the selected route" + assert _sgr(GREEN) in body