Trophy case: draw each record's walk on the shared route graph
A record's dialog showed its route only as a text line; add the fan-lane braille graph above it so a walk's shape reads at a glance — us starred at both ends, each relay marked and labelled by its first hash byte, the same presentation the Message paths dialog draws a delivery with. Extract that presentation into widgets.route_graph_style() — the glyph/label/ colour callbacks both screens hand render_path_graph — so the two graphs cannot drift; pass source==self_name to draw both ends as us for a walk. A route that revisits a node (a boomerang's mirrored return leg) collapses to distinct-in- order before drawing, since the depth graph can only seat a node once; the route line below still carries every hop. Move the shared _UNKNOWN marker down to map_render alongside _SELF/_NODE/_REPEATER so widgets can reach it without a cycle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f78ba5a54
commit
f1b06bf2e2
6 files changed
+154
-71
No files matched your search
@@ -51,7 +51,7 @@ from ..core.models import (
|
||||
utcnow,
|
||||
)
|
||||
from ..services.topology import Link, MeshTopology
|
||||
from .map_render import _NODE, _REPEATER, _SELF
|
||||
from .map_render import _NODE, _REPEATER, _SELF, _UNKNOWN
|
||||
from .mapcanvas import RGB, MapCanvas, parse_hex
|
||||
from .menus import fit_cells
|
||||
from .theme import name_style, snr_style
|
||||
@@ -123,9 +123,6 @@ _SNR_STOPS: tuple[tuple[float, RGB], ...] = (
|
||||
#: Edge colour for a link with no SNR reading at all (e.g. known only from a route).
|
||||
_NO_READING: RGB = (100, 116, 139)
|
||||
|
||||
#: Marker style for a node no contact matches — heard of, never identified.
|
||||
_UNKNOWN = ("○", "#94a3b8")
|
||||
|
||||
#: One-letter tags for the evidence classes backing a link, matching the path
|
||||
#: composer's: T(race), R(oute), P(acket log), N(eighbour table).
|
||||
_SOURCE_TAGS = {"trace": "T", "route": "R", "packet": "P", "neighbour": "N"}
|
||||
|
||||
@@ -53,10 +53,12 @@ class MapMarker:
|
||||
# Marker palette, shared across the whole app. The basemap is blue (water), green (parks) and
|
||||
# warm amber (roads), so markers use the hues a map never contains — pink/violet — to stand
|
||||
# out against it. Ordinary nodes are the loudest (bright pink); repeaters recede a step (a
|
||||
# calmer violet); our own node stays the fixed yellow star.
|
||||
# calmer violet); our own node stays the fixed yellow star; a node heard of but never
|
||||
# identified is a muted grey ring.
|
||||
_SELF = ("★", "#facc15")
|
||||
_REPEATER = ("▲", "#a78bfa")
|
||||
_NODE = ("●", "#f472b6")
|
||||
_UNKNOWN = ("○", "#94a3b8")
|
||||
|
||||
|
||||
# -- basemap styling ----------------------------------------------------------
|
||||
|
||||
@@ -32,16 +32,11 @@ from rich.text import Text
|
||||
|
||||
from ..core.models import ChatMessage
|
||||
from ..services.message_paths import Arrival
|
||||
from .atlas_screen import _UNKNOWN
|
||||
from .map_render import _NODE, _SELF
|
||||
from .mapcanvas import RGB, parse_hex
|
||||
from .pathgraph import DST_NODE as _DST
|
||||
from .pathgraph import SRC_NODE as _SRC
|
||||
from .pathgraph import PathLayer, render_path_graph
|
||||
from .theme import name_style, snr_style
|
||||
from .theme import snr_style
|
||||
from .tui.render import crop_cells, render_to_ansi
|
||||
from .tui.screen import Screen
|
||||
from .widgets import NodeResolver, path_text
|
||||
from .widgets import NodeResolver, path_text, route_graph_style
|
||||
|
||||
#: Cells one ←/→ press shifts the selected row by.
|
||||
_HSTEP = 4
|
||||
@@ -51,11 +46,6 @@ _EDGE_SELECTED = (255, 255, 255)
|
||||
_EDGE_UNUSED = (110, 110, 110)
|
||||
|
||||
|
||||
def _name_rgb(name: str) -> RGB:
|
||||
"""The RGB of a name's stable palette hue (``theme.name_style`` minus its bold)."""
|
||||
return parse_hex(name_style(name).split()[-1])
|
||||
|
||||
|
||||
class MessagePathsScreen(Screen):
|
||||
"""A floating dialog: one message's arrivals as a path graph over a row list."""
|
||||
|
||||
@@ -261,8 +251,9 @@ class MessagePathsScreen(Screen):
|
||||
The shared route-graph widget does the layout (lanes fanned from the centre
|
||||
in first-heard order, shared relays averaged together); this just maps each
|
||||
distinct path to a :class:`~meshterm.ui.pathgraph.PathLayer` — the selected
|
||||
one white on top, the rest gray beneath — and hands it the per-node glyph,
|
||||
hash-byte label, and name-hue callbacks.
|
||||
one white on top, the rest gray beneath — and hands it the shared route-graph
|
||||
callbacks (:func:`~meshterm.ui.widgets.route_graph_style`): endpoints named,
|
||||
relays marked and labelled by their first hash byte in the node's own hue.
|
||||
"""
|
||||
selected = self._arrivals[self._index].hops
|
||||
layers = [
|
||||
@@ -273,49 +264,10 @@ class MessagePathsScreen(Screen):
|
||||
)
|
||||
for path in self._paths()
|
||||
]
|
||||
return render_path_graph(
|
||||
layers,
|
||||
width,
|
||||
glyph_of=self._node_glyph,
|
||||
label_of=self._node_label,
|
||||
label_rgb_of=self._label_rgb,
|
||||
glyph_of, label_of, label_rgb_of = route_graph_style(
|
||||
resolve=self._resolve, self_name=self._self_name, source=self._source,
|
||||
)
|
||||
return render_path_graph(
|
||||
layers, width,
|
||||
glyph_of=glyph_of, label_of=label_of, label_rgb_of=label_rgb_of,
|
||||
)
|
||||
|
||||
def _node_glyph(self, node: str) -> tuple[str, str]:
|
||||
"""The graph marker for a node: us a star, named nodes dots, unknowns rings."""
|
||||
if node == _DST:
|
||||
return _SELF
|
||||
if node == _SRC:
|
||||
if self._source and self._self_name and self._source == self._self_name:
|
||||
return _SELF
|
||||
return _NODE if self._source else _UNKNOWN
|
||||
named = self._resolve(node)
|
||||
return _NODE if named and named != node else _UNKNOWN
|
||||
|
||||
def _node_label(self, node: str) -> str:
|
||||
"""A node's graph label: endpoints by name, relays by their first hash byte."""
|
||||
if node == _DST:
|
||||
return self._self_name or "you"
|
||||
if node == _SRC:
|
||||
return self._source or "?"
|
||||
return node[:2]
|
||||
|
||||
def _label_rgb(self, node: str) -> RGB:
|
||||
"""The colour a node's graph label is drawn in.
|
||||
|
||||
The marker keeps its type colour (a star for us, a dot for a named node), but
|
||||
the label beside/under it takes the node's *name* hue — the same per-name
|
||||
palette the rows and the rest of the app colour that node by — so the hash
|
||||
byte reads as the mesh name it stands for. Us is the pure-white ``you``; a
|
||||
node with no name to key a hue on falls back to its marker's own colour.
|
||||
"""
|
||||
if node == _DST:
|
||||
return (255, 255, 255)
|
||||
if node == _SRC:
|
||||
if self._source and self._source == self._self_name:
|
||||
return (255, 255, 255)
|
||||
return _name_rgb(self._source) if self._source else parse_hex(_UNKNOWN[1])
|
||||
named = self._resolve(node)
|
||||
if named and named != node:
|
||||
return _name_rgb(named)
|
||||
return parse_hex(self._node_glyph(node)[1])
|
||||
@@ -11,6 +11,7 @@ opened from the main menu. Every successful trace — a *Trace target* boomerang
|
||||
through THE path widget. A discipline holding records at more than one hash width tags
|
||||
each row with its width, since the widths are genuinely different games;
|
||||
* opening a record floats :class:`RecordDialog` — every stat the walk was measured by,
|
||||
the walk drawn on THE route graph (the Message paths dialog's shape, us at both ends),
|
||||
the full route and spec, and when/by which app version it was set. From there
|
||||
*Trace this path* reopens Trace path with the record's route prefilled, so a claim
|
||||
worth re-testing is one Enter from the air again;
|
||||
@@ -31,10 +32,11 @@ from ..persistence.repository import DiscoveredPath
|
||||
from ..services import trace_runner
|
||||
from ..services.records import CATEGORIES, CATEGORY_BY_ID, Category
|
||||
from .menus import back_rows, section_heading
|
||||
from .pathgraph import PathLayer, render_path_graph
|
||||
from .theme import snr_style
|
||||
from .tui.render import render_hanging, render_to_ansi
|
||||
from .tui.screen import Screen
|
||||
from .widgets import NodeResolver, path_text
|
||||
from .widgets import NodeResolver, path_text, route_graph_style
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..context import AppContext
|
||||
@@ -43,15 +45,20 @@ if TYPE_CHECKING:
|
||||
#: prose reads the same however wide the terminal is.
|
||||
_DESC_WRAP = 64
|
||||
|
||||
#: The colour a record's single walk draws in on the route graph. It is the only path
|
||||
#: on the canvas, so it needs no colour to set it apart — white just reads as "the walk".
|
||||
_WALK_EDGE = (255, 255, 255)
|
||||
|
||||
|
||||
class RecordDialog(Screen):
|
||||
"""One record's full story, floating over the screen beneath.
|
||||
|
||||
Every stat the walk was measured by, the route in full (wrapped, never
|
||||
truncated), and the record's provenance — when it was set and by which app
|
||||
Every stat the walk was measured by, the walk drawn on THE route graph (us at both
|
||||
ends, the same shape the Message paths dialog draws) over the route in full (wrapped,
|
||||
never truncated), and the record's provenance — when it was set and by which app
|
||||
version. Two actions besides Back: *Trace this path* reopens Trace path with the
|
||||
record's route prefilled (propagation shifts; a record is a claim worth
|
||||
re-testing), and *Delete…* removes this one record behind a confirm.
|
||||
record's route prefilled (propagation shifts; a record is a claim worth re-testing),
|
||||
and *Delete…* removes this one record behind a confirm.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -113,8 +120,36 @@ class RecordDialog(Screen):
|
||||
row.append_text(value)
|
||||
return row
|
||||
|
||||
def _graph_lines(self, width: int) -> list[str]:
|
||||
"""Draw the walked route as one path on THE route graph — us at both ends.
|
||||
|
||||
A scored walk leaves home and comes back, so it draws us (left) → its relays →
|
||||
us (right) as a single white path through the shared fan-lane widget
|
||||
(:func:`~meshterm.ui.pathgraph.render_path_graph`), the same shape the Message
|
||||
paths dialog draws a delivery over. Nodes the walk passed through more than once
|
||||
— a boomerang's mirrored return leg — collapse to their first appearance: the
|
||||
depth-ordered graph can only seat a node once, and the route line below still
|
||||
carries every hop, revisits and all.
|
||||
"""
|
||||
seen: set[str] = set()
|
||||
hops: list[str] = []
|
||||
for node in self._record.route:
|
||||
if node not in seen:
|
||||
seen.add(node)
|
||||
hops.append(node)
|
||||
glyph_of, label_of, label_rgb_of = route_graph_style(
|
||||
resolve=self._resolve,
|
||||
self_name=self._device_label,
|
||||
source=self._device_label,
|
||||
)
|
||||
return render_path_graph(
|
||||
[PathLayer(hops=tuple(hops), color=_WALK_EDGE, priority=3)],
|
||||
width,
|
||||
glyph_of=glyph_of, label_of=label_of, label_rgb_of=label_rgb_of,
|
||||
)
|
||||
|
||||
def render_body(self, width: int) -> list[str]:
|
||||
"""Score and stats lanes, the full route, provenance, then the actions."""
|
||||
"""Stats lanes, the route graph, the full route, provenance, then the actions."""
|
||||
record, category = self._record, self._category
|
||||
stats = record.stats
|
||||
lines: list[str] = []
|
||||
@@ -163,6 +198,11 @@ class RecordDialog(Screen):
|
||||
self._lane("round trip", Text(f"{rtt:.0f} ms")), width, no_wrap=True
|
||||
))
|
||||
|
||||
lines.append("")
|
||||
lines.extend(self._graph_lines(width))
|
||||
caption = Text("you → … → you · labels = hash byte", style="faint")
|
||||
lines.append(render_to_ansi(caption, width, no_wrap=True))
|
||||
|
||||
lines.append("")
|
||||
route = path_text(
|
||||
[None, *record.route, None],
|
||||
|
||||
+75
-1
@@ -37,7 +37,9 @@ from ..core.models import (
|
||||
TxOptResult,
|
||||
utcnow,
|
||||
)
|
||||
from .map_render import _NODE, _REPEATER, _SELF
|
||||
from .map_render import _NODE, _REPEATER, _SELF, _UNKNOWN
|
||||
from .mapcanvas import RGB, parse_hex
|
||||
from .pathgraph import DST_NODE, GlyphOf, LabelOf, LabelRgbOf, SRC_NODE
|
||||
from .theme import name_style, snr_style
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -390,6 +392,78 @@ def _shorten_hash(value: str, hash_bytes: Optional[int]) -> str:
|
||||
return raw[: hash_bytes * 2] if hash_bytes else raw
|
||||
|
||||
|
||||
#: The pure-white our-own-node hue, matching the ``you`` style — an endpoint that is us
|
||||
#: (and any relay resolving to our own name) takes it over its palette colour.
|
||||
_SELF_RGB: RGB = (255, 255, 255)
|
||||
|
||||
|
||||
def _name_rgb(name: str) -> RGB:
|
||||
"""The RGB of a name's stable palette hue (``theme.name_style`` minus its bold)."""
|
||||
return parse_hex(name_style(name).split()[-1])
|
||||
|
||||
|
||||
def route_graph_style(
|
||||
*,
|
||||
resolve: NodeResolver,
|
||||
self_name: Optional[str],
|
||||
source: Optional[str],
|
||||
) -> tuple[GlyphOf, LabelOf, LabelRgbOf]:
|
||||
"""Build the per-node callbacks that draw a route on THE route graph (``pathgraph``).
|
||||
|
||||
The shared presentation the Message paths dialog and the Trophy case both draw their
|
||||
graphs with: the two endpoints carry node names, every relay in between its marker
|
||||
plus the first byte of its hash, and each label takes its node's own name hue (us the
|
||||
pure-white ``you``) so a byte reads as the mesh name it stands for. It maps the graph's
|
||||
two endpoint sentinels — :data:`~meshterm.ui.pathgraph.SRC_NODE` on the left,
|
||||
:data:`~meshterm.ui.pathgraph.DST_NODE` (always us) on the right — plus every relay
|
||||
hash, to a glyph, a label, and a label colour.
|
||||
|
||||
Args:
|
||||
resolve: Maps a relay's hash to a friendly name when one is known.
|
||||
self_name: Our own node's name — the right endpoint's label, drawn white.
|
||||
source: The left endpoint's display name (a message's origin, or us for a walk
|
||||
that starts at home — pass ``self_name`` to draw both ends as us). ``None``
|
||||
reads as an unknown ``?`` origin.
|
||||
|
||||
Returns:
|
||||
The ``(glyph_of, label_of, label_rgb_of)`` triple to hand to
|
||||
:func:`~meshterm.ui.pathgraph.render_path_graph`.
|
||||
"""
|
||||
src_is_self = bool(source) and source == self_name
|
||||
|
||||
def glyph_of(node: str) -> tuple[str, str]:
|
||||
"""Us a star, a named node a dot, an unidentified node a ring."""
|
||||
if node == DST_NODE:
|
||||
return _SELF
|
||||
if node == SRC_NODE:
|
||||
return _SELF if src_is_self else (_NODE if source else _UNKNOWN)
|
||||
named = resolve(node)
|
||||
return _NODE if named and named != node else _UNKNOWN
|
||||
|
||||
def label_of(node: str) -> Optional[str]:
|
||||
"""Endpoints by name, relays by their first hash byte."""
|
||||
if node == DST_NODE:
|
||||
return self_name or "you"
|
||||
if node == SRC_NODE:
|
||||
return source or "?"
|
||||
return node[:2]
|
||||
|
||||
def label_rgb_of(node: str) -> RGB:
|
||||
"""A label's colour: its node's name hue, us pure white, an unknown its ring."""
|
||||
if node == DST_NODE:
|
||||
return _SELF_RGB
|
||||
if node == SRC_NODE:
|
||||
if src_is_self:
|
||||
return _SELF_RGB
|
||||
return _name_rgb(source) if source else parse_hex(_UNKNOWN[1])
|
||||
named = resolve(node)
|
||||
if named and named != node:
|
||||
return _name_rgb(named)
|
||||
return parse_hex(glyph_of(node)[1])
|
||||
|
||||
return glyph_of, label_of, label_rgb_of
|
||||
|
||||
|
||||
def _route_text(
|
||||
result: TraceResult,
|
||||
device_label: str = LOCAL_DEVICE_LABEL,
|
||||
|
||||
@@ -59,6 +59,24 @@ def test_record_dialog_shows_stats_route_and_the_trace_action() -> None:
|
||||
assert "Back" in body
|
||||
|
||||
|
||||
def test_record_dialog_draws_the_walk_as_a_route_graph() -> None:
|
||||
"""The walk is drawn on THE route graph — us starred at both ends, over a caption."""
|
||||
body = _plain(_dialog(_record()).render_body(60))
|
||||
assert body.count("★") == 2 # our node marks both endpoints of the round trip
|
||||
assert "labels = hash byte" in body # the graph's caption
|
||||
assert any("⠀" <= ch <= "⣿" for ch in body) # braille edges are drawn
|
||||
|
||||
|
||||
def test_record_graph_collapses_a_revisited_route_to_distinct_nodes() -> None:
|
||||
"""A boomerang that doubles back seats each node once — the depth graph can't stack a
|
||||
node on itself — so the revisiting route draws the same graph as its distinct one."""
|
||||
looping = _dialog(_record(route=(HUB_ID, FAR_ID, HUB_ID)))
|
||||
distinct = _dialog(_record(route=(HUB_ID, FAR_ID)))
|
||||
assert looping._graph_lines(60) == distinct._graph_lines(60)
|
||||
graph = _plain(looping._graph_lines(60))
|
||||
assert "3d" in graph and "f2" in graph # both distinct relays labelled, neither piled
|
||||
|
||||
|
||||
def test_record_dialog_title_names_the_discipline_and_rank() -> None:
|
||||
"""The title uses the plain discipline name and the board standing."""
|
||||
assert _dialog(_record(), rank=3).title == "Record — Most nodes #3"
|
||||
|
||||
Reference in new issue
Block a user