diff --git a/meshterm/ui/pathgraph.py b/meshterm/ui/pathgraph.py index 95ceea6..48f8ed3 100644 --- a/meshterm/ui/pathgraph.py +++ b/meshterm/ui/pathgraph.py @@ -568,10 +568,13 @@ def _place_labels( Endpoints first, then relays down the lanes, so the named ends win any contest for a cell. Each label is tried on the side away from the graph's middle first (spreading the - text outward off the busy centre), preferring a row the drawn lines don't already occupy; - an endpoint, hard against a canvas edge, slides its anchor inward far enough for the whole - name to land, and falls back to sitting beside its marker. A name is only ever shortened - when it is wider than the entire canvas. + text outward off the busy centre), preferring a row the drawn lines don't already occupy. + Any node hard against a canvas edge — an endpoint by construction, or a relay a balanced + rank pins near the origin or us — slides its centre anchor inward far enough for the whole + name to land, since a centred label overhanging the edge places nothing and would leave the + marker silently unlabelled. When both stacked rows are blocked the label falls back to + sitting beside its marker. A name is only ever shortened when it is wider than the entire + canvas. """ endpoints = [n for n in (DST_NODE, SRC_NODE) if n in pos] relays = sorted( @@ -586,11 +589,12 @@ def _place_labels( label = label[: max(1, width - 1)] + "…" rgb = label_rgb_of(node) x, y = pos[node] - anchor_x = x - if node in (SRC_NODE, DST_NODE): - half = len(label) // 2 - cx = min(max(x >> 1, half), max(half, width - (len(label) - half))) - anchor_x = cx * 2 + # Clamp the centre cell so the whole label fits between the canvas edges: a marker near + # an edge would otherwise centre its name off-canvas, place nothing, and be dropped. A + # marker with room to spare keeps its true centre (the clamp is a no-op there). + half = len(label) // 2 + cx = min(max(x >> 1, half), max(half, width - (len(label) - half))) + anchor_x = cx * 2 rows_out = (y - 4, y + 4) if y <= mid_y else (y + 4, y - 4) if any( canvas.place_label(anchor_x, sy, label, rgb, bold=True, avoid_dots=True) @@ -601,6 +605,7 @@ def _place_labels( canvas.place_label(anchor_x, sy, label, rgb, bold=True) for sy in rows_out ): continue - if node in (SRC_NODE, DST_NODE): - if not canvas.marker_label(x, y, label, rgb, avoid_dots=True): - canvas.marker_label(x, y, label, rgb) + # Both rows blocked: sit the label beside the marker (clear of the drawn lines if it + # can, else over them) rather than drop it. + if not canvas.marker_label(x, y, label, rgb, avoid_dots=True): + canvas.marker_label(x, y, label, rgb) diff --git a/tests/test_pathgraph.py b/tests/test_pathgraph.py index 5968bf6..212fd89 100644 --- a/tests/test_pathgraph.py +++ b/tests/test_pathgraph.py @@ -147,6 +147,26 @@ def test_every_label_shows_on_a_busy_graph() -> None: assert name in plain, f"{name} was dropped from the graph" +def test_edge_pinned_relay_labels_are_not_dropped() -> None: + """A relay a balanced rank pins near a canvas edge still shows its whole name. + + A long chain hung off ``cc`` drives its balanced rank hard against the origin and pushes + the shared ``bb`` hard against us, so both land near an edge where a *centred* long label + overhangs the canvas. Those anchors must slide inward — like an endpoint's — rather than + place nothing and leave the marker silently unlabelled. + """ + names = {"aa": "UpperStation", "bb": "RightEdgeStation", "cc": "LeftEdgeStation"} + tail = tuple(f"g{i}" for i in range(1, 13)) + layers = [ + PathLayer(("bb",), WHITE, 3), + PathLayer(("aa", "bb"), GREY, 2), + PathLayer(("cc", *tail, "bb"), GREY, 1), + ] + plain = _ANSI.sub("", "\n".join(_render(layers, label_of=lambda n: names.get(n)))) + for name in names.values(): + assert name in plain, f"{name} was dropped near a canvas edge" + + def test_a_subsumed_route_adds_no_duplicate_markers() -> None: """A route whose hops are all carried by a stronger one draws through them, not doubled.""" layers = [