Path graph: keep node labels whole until they overflow the canvas

The fan-lane route graph clipped every label to a fixed 12-cell budget, so
node names past twelve characters ellipsized even with room to spare. Cap the
label at the physical canvas width instead: a name is kept whole unless it is
wider than the whole canvas (nowhere for the cells to go), and the placement
pass — which already slides an endpoint's label inward or drops a crowded
relay's — decides where it lands. Message-paths endpoints now read in full.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 4.8 committed 2026-07-15 15:50:56 -04:00
1 parent ccac419880
commit 4f78ba5a54
2 files changed
+29 -10

No files matched your search

+9 -7
View File
@@ -53,9 +53,6 @@ _CELL_MID_DOT = 1
#: Dot-space margin the endpoint markers keep from the canvas edges.
_GRAPH_PAD_DOTS = 6
#: The widest a node label may render on the graph before it is ellipsized.
_GRAPH_LABEL_W = 12
#: A node's graph marker: the glyph and its ``#rrggbb`` colour (the shared node-glyph
#: tuples from :mod:`~meshterm.ui.map_render` / :mod:`~meshterm.ui.widgets` fit as-is).
GlyphOf = Callable[[str], tuple[str, str]]
@@ -115,8 +112,8 @@ def render_path_graph(
width: Canvas width in character cells.
glyph_of: Marker glyph + colour per node id (endpoints keyed by
:data:`SRC_NODE` / :data:`DST_NODE`).
label_of: Label text per node id (``None``/``""`` = bare marker). Labels
longer than the widget's budget are ellipsized.
label_of: Label text per node id (``None``/``""`` = bare marker). A label is
kept whole unless it is wider than the canvas, when it is ellipsized to fit.
label_rgb_of: Label colour per node id.
min_rows: The fewest canvas rows to draw, however flat the fan.
max_rows: The most canvas rows to spend; a taller fan compresses its lane
@@ -218,8 +215,13 @@ def render_path_graph(
label = label_of(node)
if not label:
continue
if len(label) > _GRAPH_LABEL_W:
label = label[: _GRAPH_LABEL_W - 1] + "…"
# A name only shortens when it is wider than the whole canvas — there is
# physically nowhere for the extra cells to go. Anything that fits the width is
# kept whole and handed to the placement pass below, which slides an endpoint's
# label inward (or drops a crowded relay's) rather than pre-clipping a name that
# would have fit.
if len(label) > width:
label = label[: max(1, width - 1)] + "…"
rgb = label_rgb_of(node)
x, y = pos(node)
# An endpoint hugs a canvas edge, where a run centred on its marker falls
+20 -3
View File
@@ -78,7 +78,7 @@ def test_labels_follow_the_callback_only_self_named() -> None:
def test_endpoint_labels_may_leave_the_marker_row() -> None:
"""Endpoints now place like relays: the label lands even off the centre row."""
"""Endpoints place like relays: a long name lands whole, even off the centre row."""
layers = [PathLayer(tuple(f"{i:02x}" for i in range(6)), WHITE, 4)]
lines = _render(
layers,
@@ -87,5 +87,22 @@ def test_endpoint_labels_may_leave_the_marker_row() -> None:
else None,
)
plain = _ANSI.sub("", "\n".join(lines))
# The name is wider than the label budget: it must appear, ellipsized.
assert "VeryLongSta…" in plain
# The name fits the 60-cell canvas, so it is kept whole — no fixed label budget clips it.
assert "VeryLongStationName" in plain
assert "…" not in plain
def test_labels_ellipsize_only_when_wider_than_the_canvas() -> None:
"""A name shortens only when it physically cannot fit — wider than the whole canvas."""
name = "x" * 30
lines = render_path_graph(
[PathLayer(("aa",), WHITE, 4)],
20,
glyph_of=_glyph,
label_of=lambda node: name if node in (SRC_NODE, DST_NODE) else None,
label_rgb_of=lambda _node: WHITE,
)
plain = _ANSI.sub("", "\n".join(lines))
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