Skip to content

Commit

Permalink
Implement aliasing in Mermaid diagram with unique IDs and custom disp…
Browse files Browse the repository at this point in the history
…lay names
  • Loading branch information
iurysza committed Apr 23, 2024
1 parent 2243a28 commit e57f069
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ internal object DigraphBuilder {
val groups = split(":")
if (groups.size == 1) return ""
return groups
.takeLast(2)
.take(1)
.joinToString("")
.dropLast(1)
.joinToString(":")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal object DigraphCodeBuilder {
)

private fun toMermaid(it: DigraphModel, linkText: LinkText): CharSequence = """
| ${it.source.name} ${linkText.toLinkString(it.target.config.value)} ${it.target.name}
| ${it.source.fullName} ${linkText.toLinkString(it.target.config.value)} ${it.target.fullName}
""".trimMargin()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal object NodeStyleBuilder {
fun build(digraphModel: List<DigraphModel>, options: GraphOptions): MermaidCode {
val distinctNodes = digraphModel
.flatMap { listOf(it.source, it.target) }
.distinctBy { it.name }
.distinctBy { it.fullName }
val focusedNodes = distinctNodes.filter { it.isFocused }

val pluginTypeStyling = applyStylingByPluginType(options, distinctNodes)
Expand Down Expand Up @@ -57,7 +57,7 @@ internal object NodeStyleBuilder {
}
""".trimMargin() + """
|
|${nodeList.joinToString("\n") { "class ${it.name} ${it.pluginClass()}" }}
|${nodeList.joinToString("\n") { "class ${it.fullName} ${it.pluginClass()}" }}
""".trimMargin()
} else {
""
Expand All @@ -82,7 +82,7 @@ internal object NodeStyleBuilder {
"""
|
|${defineStyleClass(FOCUS_CLASS_NAME, theme.focusColor())}
|${nodeList.joinToString("\n") { "class ${it.name} $FOCUS_CLASS_NAME" }}
|${nodeList.joinToString("\n") { "class ${it.fullName} $FOCUS_CLASS_NAME" }}
""".trimMargin()
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal object SubgraphBuilder {
subgraphModel: List<Pair<String, List<ModuleNode>>>,
): MermaidCode = MermaidCode(
subgraphModel.joinToString("\n") { (parent, children) ->
val childrenNames = children.joinToString("\n") { " ${it.name}" }
val childrenNames = children.joinToString("\n") { """ ${it.fullName}["${it.name}"]""" }
"""| subgraph $parent
|$childrenNames
| end
Expand All @@ -45,7 +45,7 @@ internal object SubgraphBuilder {
.flatMap { listOf(it.source, it.target) }
.filter { it.parent.isNotEmpty() }
.groupBy { it.parent }
.map { (parent, children) -> parent to children.distinctBy { it.name } }
.map { (parent, children) -> parent to children.distinctBy { it.fullName } }
.sortedBy { it.first }
.toList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class ModuleGraphPluginFunctionalTest {
}%%
graph RL
subgraph groupFolder
example2
subgraph :groupFolder
:groupFolder:example2["example2"]
end
example --> example2
:example --> :groupFolder:example2
```
""".trimIndent()
assertEquals(expectedOutput, readmeFile.readText())
Expand Down Expand Up @@ -151,10 +151,10 @@ class ModuleGraphPluginFunctionalTest {
}%%
graph LR
subgraph groupFolder
example2
subgraph :groupFolder
:groupFolder:example2["example2"]
end
example --> example2
:example --> :groupFolder:example2
```
""".trimIndent()
assertEquals(expectedOutput, readmeFile.readText())
Expand Down Expand Up @@ -267,12 +267,12 @@ class ModuleGraphPluginFunctionalTest {
}%%
graph RL
subgraph groupFolder
example2
example3
subgraph :groupFolder
:groupFolder:example2["example2"]
:groupFolder:example3["example3"]
end
example -- implementation --> example2
example -- runtimeOnly --> example3
:example -- implementation --> :groupFolder:example2
:example -- runtimeOnly --> :groupFolder:example3
```
""".trimIndent()
assertEquals(expectedOutput, readmeFile.readText())
Expand Down Expand Up @@ -372,10 +372,10 @@ class ModuleGraphPluginFunctionalTest {
}%%
graph RL
subgraph groupFolder
example2
subgraph :groupFolder
:groupFolder:example2["example2"]
end
example --> example2
:example --> :groupFolder:example2
```
""".trimIndent()
assertEquals(expectedOutput, readmeFile.readText())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class DigraphCodeBuilderTest {
)

val expectedMermaidCode = """
| alpha --> gama
| gama --> zeta
| :sample:alpha --> :sample:container:gama
| :sample:container:gama --> :sample:zeta
""".trimMargin()
assertEquals(expectedMermaidCode, mermaidCode.value)
}
Expand Down Expand Up @@ -51,26 +51,26 @@ class DigraphCodeBuilderTest {
)

val expectedMermaidCode = """
| footballinfo --> common
| match-day --> common
| match-day --> footballinfo
| match-day --> design-system
| match-day --> reddit
| match-thread --> webview-to-native-player
| match-thread --> common
| match-thread --> footballinfo
| match-thread --> design-system
| match-thread --> reddit
| playground --> webview-to-native-player
| playground --> match-thread
| playground --> design-system
| playground --> match-day
| reddit --> common
| webview-to-native-player --> common
| main --> match-thread
| main --> match-day
| main --> design-system
| main --> common
| :core:footballinfo --> :core:common
| :features:match-day --> :core:common
| :features:match-day --> :core:footballinfo
| :features:match-day --> :core:design-system
| :features:match-day --> :core:reddit
| :features:match-thread --> :core:webview-to-native-player
| :features:match-thread --> :core:common
| :features:match-thread --> :core:footballinfo
| :features:match-thread --> :core:design-system
| :features:match-thread --> :core:reddit
| :app:playground --> :core:webview-to-native-player
| :app:playground --> :features:match-thread
| :app:playground --> :core:design-system
| :app:playground --> :features:match-day
| :core:reddit --> :core:common
| :core:webview-to-native-player --> :core:common
| :app:main --> :features:match-thread
| :app:main --> :features:match-day
| :app:main --> :core:design-system
| :app:main --> :core:common
""".trimMargin()
assertEquals(expectedMermaidCode, mermaidCode.value)
}
Expand Down
Loading

0 comments on commit e57f069

Please sign in to comment.