Repository navigation
Add example code - #35
Conversation
WalkthroughThis pull request introduces several enhancements to the Mermaid diagram generation package, focusing on documentation updates and consistent formatting across various diagram types. The changes include adding example test files for different diagram types (architecture, entity-relationship, flowchart, pie chart, and sequence diagrams), updating the README to document new features, and standardizing string formatting across the package. The modifications primarily involve improving code readability and providing comprehensive documentation for the Mermaid diagram generation capabilities. Changes
Sequence DiagramsequenceDiagram
participant Package as Mermaid Package
participant README as Documentation
participant Examples as Example Tests
Package->>README: Add new feature documentation
Package->>Examples: Create comprehensive test examples
Examples-->>Package: Validate diagram generation
README-->>Package: Reflect new capabilities
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Code Metrics Report
Details | | main (09f9d46) | #35 (b21c6e4) | +/- |
|---------------------|----------------|---------------|------|
| Coverage | 92.6% | 92.6% | 0.0% |
| Files | 30 | 30 | 0 |
| Lines | 545 | 545 | 0 |
| Covered | 505 | 505 | 0 |
+ | Test Execution Time | 9s | 4s | -5s |Code coverage of files in pull request scope (100.0% → 100.0%)
Reported by octocov |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (8)
mermaid/piechart/examples_test.go (2)
1-2: Document build constraint rationale in package documentationWhile the function comment explains why Windows is excluded, it would be helpful to document this at the package level for better visibility.
Add a package comment explaining the build constraint:
//go:build linux || darwin +// Package piechart_test contains example tests that are skipped on Windows +// due to newline formatting differences in the expected output. package piechart_test
17-25: Consider adding validation for negative valuesThe pie chart creation looks good, but consider adding validation for negative values which wouldn't make sense in a pie chart context.
mermaid/flowchart/examples_test.go (2)
39-39: Fix comment formattingAs indicated by the static analysis tool, add a space after
//.-//```mermaid +// ```mermaid🧰 Tools
🪛 golangci-lint (1.62.2)
39-39: commentFormatting: put a space between
//and comment text(gocritic)
17-30: Consider grouping related nodes visuallyThe flowchart structure is clear, but consider adding visual grouping for related nodes to enhance diagram readability.
Example addition:
DatabaseNode("D", "Database"). + SubgraphStart("data_flow", "Data Flow"). LinkWithArrowHead("A", "B"). LinkWithArrowHeadAndText("B", "D", "send original data"). LinkWithArrowHead("B", "C"). DottedLinkWithText("C", "D", "send filtered data"). + SubgraphEnd().mermaid/sequence/examples_test.go (1)
17-35: Consider adding timing indicatorsThe sequence diagram effectively shows the flow but could benefit from timing indicators for certain operations.
Example enhancement:
LoopStart("until Subaru wake up"). + Note("right of David", "Waiting 5 minutes"). SyncRequest("David", "Subaru", "Wake up!").mermaid/er/examples_test.go (2)
17-95: Consider extracting entity definitions to helper functionsThe entity definitions are quite verbose and repetitive. Consider extracting common patterns into helper functions to improve readability and maintainability.
+ func newTeacherEntity() *er.Entity { + return er.NewEntity( + "teachers", + []*er.Attribute{ + {Type: "int", Name: "id", IsPrimaryKey: true, IsUniqueKey: true, Comment: "Teacher ID"}, + {Type: "string", Name: "name", Comment: "Teacher Name"}, + }, + ) + }
97-114: Add comments explaining relationship symbolsThe relationship symbols (
||,}o, etc.) are documented inline, but consider adding a comment block explaining all possible combinations for better documentation.+ // Relationship symbols: + // || : ExactlyOneRelationship + // }o : ZeroToMoreRelationship + // |} : OneToMoreRelationship + // -- : Identifying relationship + // .. : Non-identifying relationshipmermaid/flowchart/flowchart_test.go (1)
217-220: Simplify string concatenation.The current string concatenation using
fmt.Sprintfwith//nolint:gosimplecan be simplified.Consider using a raw string literal or string builder:
- want += fmt.Sprintf("C[\"`**Node C**`\"]\n") //nolint:gosimple - want += fmt.Sprintf(" D[\"`Node\n") //nolint:gosimple - want += "D`\"]" + want += `C[\"**Node C**\"] + D[\"Node +D\"]`
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
README.md(2 hunks)doc/architecture/generated.md(1 hunks)doc/er/generated.md(1 hunks)doc/flowchart/generated.md(1 hunks)mermaid/arch/examples_test.go(1 hunks)mermaid/er/entity.go(3 hunks)mermaid/er/entity_relationship_test.go(1 hunks)mermaid/er/examples_test.go(1 hunks)mermaid/flowchart/examples_test.go(1 hunks)mermaid/flowchart/flowchart_test.go(7 hunks)mermaid/flowchart/link.go(1 hunks)mermaid/flowchart/node.go(2 hunks)mermaid/piechart/examples_test.go(1 hunks)mermaid/sequence/examples_test.go(1 hunks)
✅ Files skipped from review due to trivial changes (6)
- doc/architecture/generated.md
- doc/flowchart/generated.md
- doc/er/generated.md
- mermaid/flowchart/link.go
- mermaid/flowchart/node.go
- mermaid/er/entity.go
🧰 Additional context used
🪛 golangci-lint (1.62.2)
mermaid/flowchart/examples_test.go
39-39: commentFormatting: put a space between // and comment text
(gocritic)
[low] 32-32: G104: Errors unhandled.
(gosec)
mermaid/arch/examples_test.go
101-101: commentFormatting: put a space between // and comment text
(gocritic)
[low] 94-94: G104: Errors unhandled.
(gosec)
mermaid/er/examples_test.go
123-123: commentFormatting: put a space between // and comment text
(gocritic)
[low] 116-116: G104: Errors unhandled.
(gosec)
🔇 Additional comments (6)
mermaid/sequence/examples_test.go (1)
16-16:
Function name doesn't match comment
The function comment refers to "ExampleSequence" but the function is named "ExampleDiagram".
Either update the comment or rename the function for consistency:
-// ExampleSequence skip this test on Windows.
+// ExampleDiagram skip this test on Windows.Likely invalid or redundant comment.
mermaid/arch/examples_test.go (1)
1-2: LGTM: Build tag correctly handles platform-specific test
The build tag appropriately restricts the test to Linux and Darwin platforms due to newline differences on Windows.
mermaid/er/entity_relationship_test.go (1)
136-154: LGTM: Output format is consistent and well-structured
The updated output format with consistent indentation improves readability while maintaining the correct entity relationships.
mermaid/flowchart/flowchart_test.go (2)
43-50: LGTM! Well-structured test case with proper indentation.
The expected output string correctly follows Mermaid syntax and uses consistent 4-space indentation.
74-74: LGTM! Clear and focused test case.
The test case properly validates the top-to-bottom orientation with correct Mermaid syntax.
README.md (1)
12-12: LGTM! Clear and comprehensive documentation update.
The changes effectively:
- Update the feature list to include architecture diagrams
- Clearly indicate the beta status of the feature
Also applies to: 39-39
mermaid/c4 builds the C4Context diagram: the people and the software systems around the one being described. Scope stays there on purpose, because mermaid marks its C4 support experimental and says the syntax may change; C4Container, C4Component, C4Dynamic, C4Deployment and the UpdateElementStyle family can each arrive later as a new method without changing anything that exists. A boundary is a pair of calls rather than a callback taking a nested builder: Boundary, EnterpriseBoundary and SystemBoundary open one and BoundaryEnd closes it, the way mermaid/treemap walks its own nesting with Section and Parent. A boundary left open is reported from Build, because mermaid refuses a diagram whose brace never closes and the whole drawing is lost. The escaping was measured against the renderer rather than reasoned about, and neither escape that looks obvious works. A backslash makes mermaid refuse the diagram; doubling the quote silently splits the argument, so Rel(a, b, "x""y") draws "y" as the technology rather than as part of the label. What C4 implements is its own entity form, so a quote becomes "#quot;" and a "#" becomes "#35;" ahead of it, or a label holding "#quot;" would come back as a character the caller never wrote. The title is the one place the text is unquoted: mermaid takes the rest of the line, quotes included, so quoting it would draw the quotation marks, and the escaped pair there is "#" and ";" instead. The render check learned to decode those escapes. It compares a declared title against the drawing, and mermaid decodes "#35;" before drawing it, so without this an escaped title reads as missing. Two fixtures pin both halves: one that must pass and one whose title really is lost. Closes #128
* feat(mermaid): add C4 context diagram support mermaid/c4 builds the C4Context diagram: the people and the software systems around the one being described. Scope stays there on purpose, because mermaid marks its C4 support experimental and says the syntax may change; C4Container, C4Component, C4Dynamic, C4Deployment and the UpdateElementStyle family can each arrive later as a new method without changing anything that exists. A boundary is a pair of calls rather than a callback taking a nested builder: Boundary, EnterpriseBoundary and SystemBoundary open one and BoundaryEnd closes it, the way mermaid/treemap walks its own nesting with Section and Parent. A boundary left open is reported from Build, because mermaid refuses a diagram whose brace never closes and the whole drawing is lost. The escaping was measured against the renderer rather than reasoned about, and neither escape that looks obvious works. A backslash makes mermaid refuse the diagram; doubling the quote silently splits the argument, so Rel(a, b, "x""y") draws "y" as the technology rather than as part of the label. What C4 implements is its own entity form, so a quote becomes "#quot;" and a "#" becomes "#35;" ahead of it, or a label holding "#quot;" would come back as a character the caller never wrote. The title is the one place the text is unquoted: mermaid takes the rest of the line, quotes included, so quoting it would draw the quotation marks, and the escaped pair there is "#" and ";" instead. The render check learned to decode those escapes. It compares a declared title against the drawing, and mermaid decodes "#35;" before drawing it, so without this an escaped title reads as missing. Two fixtures pin both halves: one that must pass and one whose title really is lost. Closes #128 * fix: decode a numeric mermaid entity as a code point mermaid rewrites "#123;" to the HTML reference "{" and lets the browser resolve it, so a character code truncates anything past U+FFFF: "#128512;" came out as U+F600 rather than as the emoji, and the render check would have called a title that is drawn missing. Decode through the DOM the way mermaid does, and put an astral escape in the fixture so the difference is what fails if it comes back. Also spell "color" the way the rest of the repository does.
Summary by CodeRabbit