fix: prevent participant box overlap in sequence diagrams#5
Merged
fasouto merged 4 commits intoJun 3, 2026
Merged
Conversation
When sequence diagrams have many participants with long names but few direct messages between adjacent ones, the gap between participant centers could be smaller than the combined half-widths of adjacent boxes, causing visual overlap in the header. This fix ensures the minimum gap between adjacent participant centers accounts for the actual box widths, preventing overlapping labels. Co-authored-by: Copilot <[email protected]>
- sequence.py: Remove hardcoded min width of 12; box width is now exactly label + padding_x + 2 (borders) - placement.py: Lower min content_height from 3 to 1 so padding_y=0 produces boxes with no extra vertical space Users can now get tight boxes with --padding-x 2 --padding-y 0. Default behavior (padding_x=4, padding_y=2) is unchanged. Co-authored-by: Copilot <[email protected]>
Contributor
Author
|
@fasouto please take a look at this PR |
Notes with position 'over' on the rightmost participant (or spanning to it) were not accounted for in the canvas width calculation, causing their right border to be clipped. Co-authored-by: Copilot <[email protected]>
Contributor
Author
|
@fasouto , friendly ping... |
Owner
|
Sorry, im on vacation right now. Will taka a look at this in 2 weeks.
Thanks for submitting a PR
El El mar, 19 may 2026 a las 2:55, Sergio ***@***.***>
escribió:
… *searleser97* left a comment (fasouto/termaid#5)
<#5?email_source=notifications&email_token=AABPNGCG6733GQWL4NRZMYT43NMCTA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINBYGA4TCNBRGEYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJNLQOJPWG33NNVSW45C7N5YGK3S7MNWGSY3L#issuecomment-4480914110>
@fasouto <https://github.com/fasouto> , friendly ping...
—
Reply to this email directly, view it on GitHub
<#5?email_source=notifications&email_token=AABPNGCG6733GQWL4NRZMYT43NMCTA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINBYGA4TCNBRGEYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJNLQOJPWG33NNVSW45C7N5YGK3S7MNWGSY3L#issuecomment-4480914110>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABPNGDOT2OYKFEX3LZSQH343NMCTAVCNFSM6AAAAACY42DOZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIOBQHEYTIMJRGA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The tighter participant boxes shrink the canvas, which exposed three layout regressions that the wider min-width-12 boxes had masked: - "over" notes on a left-positioned participant clipped on the right, because the layout reserved width from the unclamped note_x while the drawing clamps it to >= 0. Mirror the clamp in the width calc. - Nested block frames (loop/alt/opt) clipped on the right, because the canvas-width loop never accounted for block frames. Reserve their right edge via _block_frame_bounds. - Nested block frames lost their left indent (inner frames collapsed onto column 0), because the per-depth indent was inside the max(0, ..) clamp. Clamp only the depth-0 base, then add the indent. Regenerate the sequence snapshots: 7 reflect the intended tighter boxes, nested_blocks reflects the restored, fully-closed frames.
Owner
|
(back from holidays, thanks for your patience) I checked it and the overlap fix is an improvement, and sizing the participant boxes to their labels actually matches how Mermaid renders them, so I'm happy to move it in that direction. Aesthetically I like them all with the same size, but it's less practical so we will do that. I went ahead and pushed a follow-up commit (8d910ed) instead of sending it back and forth. Two things to flag:
Snapshots are regenerated and the full suite is green. Thanks for your PR @searleser97 !! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When sequence diagrams have many participants with long names but few direct messages between adjacent pairs, participant boxes overlap in the header row.
Example input:
sequenceDiagram participant A as AuthenticationService participant B as UserSessionManager participant C as TokenValidationMiddleware participant D as PermissionsEvaluator participant E as AuditLogService participant F as NotificationDispatcher A->>B: createSession(credentials) B->>C: validateToken()Why
--width Ndoesn't helpThe
--widthflag and auto-fit logic only compact a diagram (reduce gap/padding) when it exceeds the target width. They don't expand the initial layout. The overlap occurs because_MIN_GAP = 16(the floor for gap between participant centers) is smaller than the combined half-widths of adjacent boxes. This means boxes overlap in the initial layout calculation, before any compaction is applied.Tested with
--width 500 --no-auto-fit— the overlap persists because the layout algorithm never ensures gaps are wide enough for the actual box sizes.Fix
1. Prevent participant box overlap (commit dfef9be)
Added a constraint in
_compute_layout()that ensures the gap between adjacent participant centers is at least the sum of their half-box-widths plus 2 characters of spacing.2. Remove unnecessary minimum box size constraints (commit dd7f546)
label + padding_x + 2(borders), so boxes are only as wide as needed.content_heightfrom 3 to 1. When--padding-y 0is passed, flowchart nodes no longer have extra blank lines above/below the label.Users can now get tight boxes with
--padding-x 2 --padding-y 0. Default behavior (padding_x=4,padding_y=2) is unchanged.3. Expand canvas width for 'over' notes on rightmost participants (commit 1b25b6b)
Notes with
position == "over"on the rightmost participant (or spanning to it) were not accounted for in the canvas width calculation. This caused the right border of such note boxes to be clipped. The fix adds width calculation for "over" notes inmax_right.Visual comparison — Sequence diagram
Before (default
--padding-x 4, min box width 12):After (
--padding-x 2, no min width floor):Visual comparison — Flowchart
Before (default
--padding-x 4 --padding-y 2):After (
--padding-x 2 --padding-y 0):Tests
All existing sequence diagram tests pass. The snapshot failures are pre-existing (statediagram) and unrelated to these changes.