Skip to content

Commit e9db8c3

Browse files
committed
feat(diff): expose --max-label to control edge-label truncation length
1 parent 951a729 commit e9db8c3

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

scripts/diff_to_mermaid.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def render_mermaid(
309309
node_padding: int | None = None,
310310
node_spacing: int | None = None,
311311
rank_spacing: int | None = None,
312+
max_label: int = _EDGE_LABEL_MAX,
312313
) -> tuple:
313314
"""Return (mermaid_text, meta). ``mermaid_text`` is None when there's nothing to draw.
314315
@@ -339,7 +340,7 @@ def emit_edges(rels: list, scope: _Scope, pad: str, force: str | None) -> None:
339340
dst = scope.resolve(rel.get("dst_id", ""), rel.get("dst_name", ""), present)
340341
if src is None or dst is None:
341342
continue # endpoint not drawn — skip, don't consume an edge index
342-
label = _esc(_truncate(rel.get("relation", ""))) if edge_labels else ""
343+
label = _esc(_truncate(rel.get("relation", ""), max_label)) if edge_labels else ""
343344
body.append(f'{pad}{src} -- "{label}" --> {dst}' if label else f"{pad}{src} --> {dst}")
344345
if status in edge_styles:
345346
edge_styles[status].append(counters["edges"])
@@ -423,6 +424,7 @@ def main() -> int:
423424
p.add_argument("--node-padding", type=int, default=None, help="Interior padding around each node label")
424425
p.add_argument("--node-spacing", type=int, default=None, help="Space between nodes in the same rank")
425426
p.add_argument("--rank-spacing", type=int, default=None, help="Space between ranks")
427+
p.add_argument("--max-label", type=int, default=_EDGE_LABEL_MAX, help="Max characters in an edge label before truncation")
426428
args = p.parse_args()
427429

428430
diff = build_diff(load_analysis(args.base), load_analysis(args.head))
@@ -436,6 +438,7 @@ def main() -> int:
436438
node_padding=args.node_padding,
437439
node_spacing=args.node_spacing,
438440
rank_spacing=args.rank_spacing,
441+
max_label=args.max_label,
439442
)
440443

441444
args.out.write_text(mermaid if mermaid is not None else "", encoding="utf-8")

0 commit comments

Comments
 (0)