Repository navigation
feat: sequence diagram — parse and render rect blocks - #170
Conversation
- Add `Metadata` dictionary to `Group` model - Parse `rect rgb(R,G,B)` / `rect rgba(R,G,B,A)` and `end` in MermaidSequenceParser - Layout: compute Group X/Y/Width/Height for sequence rect bands; adjacent bands meet exactly - Render sequence rect bands as semi-transparent colored full-width rectangles in SvgStructureWriter - Add 9 unit tests for rect block parsing in MermaidSequenceParserTests - Add snapshot fixture mermaid-sequence-rect with expected SVG baseline Agent-Logs-Url: https://github.com/jongalloway/DiagramForge/sessions/105be76e-e00b-4f8a-ae9d-01ea5b8ccb4e Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
…nsistency Agent-Logs-Url: https://github.com/jongalloway/DiagramForge/sessions/105be76e-e00b-4f8a-ae9d-01ea5b8ccb4e Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds end-to-end support for Mermaid sequence-diagram rect rgb(...) ... end / rect rgba(...) ... end background bands by extending the semantic model (Group metadata), parsing rect blocks into groups, laying them out after message positions are known, and rendering them as plain SVG <rect> elements.
Changes:
- Extend
Groupwith aMetadatadictionary so parsers/layout can tag group instances without subclassing. - Parse
rect rgb(...)/rect rgba(...)blocks inMermaidSequenceParserinto groups annotated withsequence:rect*metadata. - Lay out and render rect-band groups in the sequence layout engine and SVG writer; add parser unit tests and an E2E snapshot fixture/baseline.
Show a summary per file
| File | Description |
|---|---|
| tests/DiagramForge.Tests/Parsers/Mermaid/MermaidSequenceParserTests.cs | Adds unit tests validating rect parsing, metadata, and interaction with participant/message parsing. |
| tests/DiagramForge.E2ETests/Fixtures/mermaid-sequence-rect.input | New E2E input fixture covering both rgb() and rgba() rect bands. |
| tests/DiagramForge.E2ETests/Fixtures/mermaid-sequence-rect.expected.svg | New snapshot baseline verifying SVG output includes the background rect bands. |
| src/DiagramForge/Rendering/SvgStructureWriter.cs | Detects rect-band groups and renders them as simple semi-transparent <rect> elements. |
| src/DiagramForge/Parsers/Mermaid/MermaidSequenceParser.cs | Implements rect block parsing via a stack and attaches rect metadata to groups. |
| src/DiagramForge/Models/Group.cs | Adds Group.Metadata to match Node/Edge metadata patterns. |
| src/DiagramForge/Layout/DefaultLayoutEngine.Sequence.cs | Computes rect-band group bounds from per-message Y positions and canvas width. |
Copilot's findings
- Files reviewed: 6/7 changed files
- Comments generated: 1
| var groupId = $"sequence:rect:{rectIndex++}"; | ||
| var group = new Group(groupId, string.Empty); | ||
| group.FillColor = normalizedColor; | ||
| group.Metadata["sequence:rectGroup"] = true; | ||
| openRects.Push((group, messageIndex)); |
There was a problem hiding this comment.
SvgRenderer renders groups in a deterministic order using ThenBy(g => g.Id). With IDs like sequence:rect:0..10, lexicographic sorting will place ...:10 before ...:2, which can change z-order for overlapping/nested rect bands once there are >9 blocks. Consider zero-padding the numeric suffix (e.g., sequence:rect:0001) or storing a separate numeric metadata key for ordering.
There was a problem hiding this comment.
Fixed in cdfff2a by changing the group ID format to use D4 zero-padding (e.g., sequence:rect:0000, sequence:rect:0001, ..., sequence:rect:9999). This ensures ThenBy(g => g.Id, StringComparer.Ordinal) in SvgRenderer produces correct z-order for all realistic rect-block counts.
…ort issue Agent-Logs-Url: https://github.com/jongalloway/DiagramForge/sessions/13043ef8-b29c-4823-8897-5e634ff57d78 Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
…der-rect-blocks # Conflicts: # tests/DiagramForge.Tests/Parsers/Mermaid/MermaidSequenceParserTests.cs Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
Mermaid's
rect rgb(...)...end/rect rgba(...)...endsyntax was silently ignored. This adds full parse → layout → render support for coloured background bands in sequence diagrams.Changes
Model
Group: AddedMetadatadictionary (Dictionary<string, object>) matching the existingNode/Edgepattern, enabling parsers to annotate groups without subclassing.Parser (
MermaidSequenceParser)rect rgb(R,G,B)andrect rgba(R,G,B,A)opening lines andendclosing lines using a stack (handles nesting).GroupwithFillColorset andsequence:rectGroup=true/sequence:rectStartIndex/sequence:rectEndIndexstored in metadata.Layout (
DefaultLayoutEngine.Sequence)sequence:messageYpositions are finalised, rect-band groups receiveX=0,Width=canvasWidth, and Y-bounds computed so adjacent bands share a midpoint boundary (firstMsgY − halfRow→lastMsgY + rowH − halfRow) with no overlap.Renderer (
SvgStructureWriter)AppendGroupdetectssequence:rectGroupand delegates to a newAppendSequenceRectBandhelper: a plain<rect>spanning the full canvas width.rgb()colors getfill-opacity="0.2";rgba()colors use the embedded alpha directly.Example input
Tests
rgb/rgbaparsing, metadata, index bounds, empty blocks, and message count.mermaid-sequence-rectwith generated SVG baseline.