Skip to content

fix(diagram): keep edge labels off their arrowheads - #256

Merged
ionos-landgraf-vin merged 1 commit into
mainfrom
fix/edge-label-arrowhead
Nov 13, 2026
Merged

ionos-landgraf-vin merged 1 commit into
mainfrom
fix/edge-label-arrowhead

Conversation

@ionos-landgraf-vin

Copy link
Copy Markdown
Collaborator

Problem

On a short upward edge between two stacked nodes (40px, a stack with gap "40"), the label was drawn on top of the arrowhead. There were two causes:

  • a line shorter than 80px only tried its midpoint, and
  • the label's box sits above its anchor (y - 6), so on an upward line it reaches toward the tip.

The label placer didn't know about arrowheads at all.

Fix (Renderer::LabelPlacer)

  • place_label_along(..., arrow_start:, arrow_end:): the edge renderer passes the arrowhead length (MARKER_SIZE * EDGE_STROKE_WIDTH) for each end that has one (by direction); the dataflow renderer passes its end marker. A label box on an arrowhead (grown by 2px for the halo) costs as much as a covered node (ARROWHEAD_PENALTY).
  • Short lines now try 0.5, 0.35, 0.65, 0.25, 0.75, not just the midpoint. Node overlap is already scored, so a label still can't land on the nodes.
  • If no fixed position is clear and the line has arrowheads, spots stepping back from each arrowhead (2px steps, up to 120px) are scored the same way, and the first fully clear one wins. That's where a short line has its room.

The candidate scoring is extracted into best_candidate, unchanged otherwise (native and Ruby paths stay identical; native_test passes). Labels that were already clear don't move, so no existing test changed.

Before/after on the reported diagram: the short upward "publish" edge moves from on the arrowhead to the shaft below it, and a short downward "reads" edge that touched its source node moves 6px clear of it.

Test plan

  • New tests: a short upward line's label clears its arrowhead and both nodes; both arrowheads of a bidirectional line; an end-to-end render of a stack with an upward labelled edge
  • Full suite: 2786 runs, 0 failures; rubocop and steep clean

🤖 Generated with Claude Code

A label's box sits above its anchor, and a line shorter than 80px only
tried its midpoint, so on a short upward edge the text landed on the
arrowhead. The label placer now knows the arrowheads of a line
(edges: start/end per direction, dataflows: end) and scores a label on
one like a covered node, short lines try the moderate positions after
the midpoint, and when no fixed position is clear the spots right
behind each arrowhead are tried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ionos-landgraf-vin
ionos-landgraf-vin merged commit 7920a2e into main Nov 13, 2026
8 checks passed
@ionos-landgraf-vin
ionos-landgraf-vin deleted the fix/edge-label-arrowhead branch November 13, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant