Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion diagramatron/mermaid_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package diagramatron
// MermaidConfig configures the mermaid diagram generation
type MermaidConfig struct {
MaxProperties int // max properties to show per class (default 20)
MaxSchemas int // max unique schemas traversed (default 500)
MaxRelationships int // max relationships retained (default 2000)
MaxDepth int // max recursive schema depth (default 100)
IncludePrivate bool // include private members
IncludeOperations bool // include operations/methods
ShowCardinality bool // show relationship cardinality
Expand All @@ -17,11 +20,14 @@ type MermaidConfig struct {
func DefaultMermaidConfig() *MermaidConfig {
return &MermaidConfig{
MaxProperties: 20,
MaxSchemas: 500,
MaxRelationships: 2000,
MaxDepth: 100,
IncludePrivate: true,
IncludeOperations: true,
ShowCardinality: true,
UseNamespaces: false,
SimplifyNames: true,
RenderTitledInlineSchema: true, // show inline schemas with titles as separate classes by default
}
}
}
32 changes: 23 additions & 9 deletions diagramatron/mermaid_diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type MermaidDiagram struct {
Classes map[string]*MermaidClass
Relationships []*MermaidRelationship
Warnings []error
Config *MermaidConfig
classOrder []string // maintain insertion order
}
Expand All @@ -24,6 +25,7 @@ func NewMermaidDiagram(config *MermaidConfig) *MermaidDiagram {
return &MermaidDiagram{
Classes: make(map[string]*MermaidClass),
Relationships: []*MermaidRelationship{},
Warnings: []error{},
Config: config,
classOrder: []string{},
}
Expand Down Expand Up @@ -81,6 +83,7 @@ func (md *MermaidDiagram) Render() string {
type MermaidClass struct {
ID string
Name string
DisplayName string
Type string // class, interface, abstract
Annotations []string
Properties []*MermaidMember
Expand Down Expand Up @@ -113,7 +116,18 @@ func (mc *MermaidClass) AddMethod(member *MermaidMember) {
func (mc *MermaidClass) Render(config *MermaidConfig) string {
var sb strings.Builder

sb.WriteString(fmt.Sprintf(" class %s {\n", mc.ID))
if mc.DisplayName != "" {
label := strings.NewReplacer(
`\`, `\\`,
`"`, `'`,
"]", "]",
"\r", " ",
"\n", " ",
).Replace(mc.DisplayName)
sb.WriteString(fmt.Sprintf(" class %s[\"%s\"] {\n", mc.ID, label))
} else {
sb.WriteString(fmt.Sprintf(" class %s {\n", mc.ID))
}

for _, annotation := range mc.Annotations {
sb.WriteString(fmt.Sprintf(" <<%s>>\n", annotation))
Expand Down Expand Up @@ -173,13 +187,13 @@ type MermaidRelationship struct {
type RelationType string

const (
RelationInheritance RelationType = "<|--" // inheritance
RelationComposition RelationType = "*--" // composition
RelationAggregation RelationType = "o--" // aggregation
RelationAssociation RelationType = "-->" // association
RelationDependency RelationType = "..>" // dependency
RelationRealization RelationType = "..|>" // realization
RelationNegation RelationType = "-.x" // negation (A is NOT B)
RelationInheritance RelationType = "<|--" // inheritance
RelationComposition RelationType = "*--" // composition
RelationAggregation RelationType = "o--" // aggregation
RelationAssociation RelationType = "-->" // association
RelationDependency RelationType = "..>" // dependency
RelationRealization RelationType = "..|>" // realization
RelationNegation RelationType = "-.x" // negation (A is NOT B)
)

// Render generates the mermaid syntax for this relationship
Expand Down Expand Up @@ -228,4 +242,4 @@ func sanitizeID(id string) string {
}

return string(result)
}
}
Loading
Loading