Skip to content

Commit

Permalink
dependency less works with links
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr.suwala committed Apr 17, 2024
1 parent 3d2a997 commit b236f20
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/kotlin/sh/hsp/techtree/graphviz/DSLConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import java.util.stream.Collectors

class DSLConverter {
fun convert(model: TreeModel): String {
val nodesAsDSL = model.nodes.stream()
val nodesAsDSL = model.nodes.stream()
.map { registerNode(it) }
.collect(Collectors.joining(" "))

return "digraph { graph [splines=\"ortho\"] node [shape=\"box\"] edge [dir=\"back\"] $nodesAsDSL }"
}

private fun registerNode(node: TreeNode): String {
if (node.requires != null) {
val pathsToChildren = node.requires.stream()
val pathsToChildren = node.requires?.apply {
stream()
.map { "${node.title.escaped()} -> ${it.escaped()}" }
.collect(Collectors.joining(" "))
return "${node.title.escaped()} ${node.link?.let { "[ href=\"$it\" fontcolor=blue]" } ?: ""} $pathsToChildren"
}

return node.title.escaped()
} ?: listOf()
return "${node.title.escaped()} ${node.link?.let { "[ href=${it.escaped()} fontcolor=blue]" } ?: ""} $pathsToChildren"
}

private fun String.escaped(): String = "\"$this\""
Expand Down

0 comments on commit b236f20

Please sign in to comment.