Skip to content

Commit

Permalink
gray
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanlas committed Mar 27, 2024
1 parent 64b898e commit 91b7240
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,22 @@ object DemoDsl:
case Database(name, numReplicas) =>
val replicas =
(1 to numReplicas)
.map(n => PlantUml.Database(s"replica-$n", None, Option.when(isBright)("Database"), xs = Set.empty))
.map: n =>
PlantUml.Database(s"replica-$n", None, Option.when(isBright)("Replica"), xs = Set.empty)
.toSet[PlantUml.Entity]

PlantUml.ComponentDiagram(
PlantUml.Package(
"Persistence",
replicas + PlantUml.Database(name, None, Option.when(isBright)("Database"), xs = Set.empty)
),
if isBright then skinPlantUmlYellow("database", "Database") else skinPlantUmlWhite("database")
)
val replicaSkin =
if isBright then skinPlantUmlGray("database", "Replica") else skinPlantUmlWhite("database")

PlantUml
.ComponentDiagram(
PlantUml.Package(
"Persistence",
replicas + PlantUml.Database(name, None, Option.when(isBright)("Database"), xs = Set.empty)
),
if isBright then skinPlantUmlYellow("database", "Database") else skinPlantUmlWhite("database"),
replicaSkin
)

case Title(s) =>
PlantUml.ComponentDiagram:
Expand Down Expand Up @@ -116,17 +122,28 @@ object DemoDsl:
Node.Simple(name, nodeClass = Option.when(isBright)("Service")) ::
skinMermaidBlue(isBright)

case Database(name, replicas) =>
case Database(name, numReplicas) =>
val replicas =
(1 to numReplicas)
.map: n =>
Node.WithShape(
s"replica-$n",
Node.Shape.Cylinder,
nodeClass = Option.when(isBright)("Database")
)
.toList

val primary =
Node.WithShape(name, Node.Shape.Cylinder, nodeClass = Option.when(isBright)("Database"))

MermaidDiagram.of:
Flowchart:
Subgraph(
id = "persistence",
text = "Persistence".some,
direction = None,
declarations =
(Node.WithShape(name, Node.Shape.Cylinder, nodeClass = Option.when(isBright)("Database")) ::
skinMermaidBlue(isBright)).toSet,
links = Set.empty
id = "persistence",
text = "Persistence".some,
direction = None,
declarations = ((replicas :+ primary) ::: skinMermaidBlue(isBright)).toSet,
links = Set.empty
)
case Title(s) =>
MermaidDiagram.empty
Expand Down Expand Up @@ -158,6 +175,15 @@ object DemoDsl:
.and("borderColor", "#AAA")
.and("borderThickness", "2")

private def skinPlantUmlGray(name: String, stereotype: String) =
PlantUml
.SkinParamGroup(name, stereotype)
.and("fontStyle", "bold")
.and("fontColor", "#333")
.and("backgroundColor", "white/#CCC")
.and("borderColor", "#888")
.and("borderThickness", "2")

private def skinPlantUmlRed(name: String, stereotype: String) =
PlantUml
.SkinParamGroup(name, stereotype)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,21 @@ class WriteDemoDslDiagrams[F[_]: Applicative: Parallel](out: FilePrinter[F]):

val toDatabase =
(n: Int) =>
Chain(
DemoDsl.Database("database", n).tag("persistence"),
WithMultiArrows.Destination("database-read", List("database"))
)
if n == 0 then
Chain(
DemoDsl.Database("database", n).tag("persistence"),
WithMultiArrows.Destination("database-read", List("database"))
)
else
val destinations =
(1 to n)
.map(m => s"replica-$m")
.toList

Chain(
DemoDsl.Database("database", n).tag("persistence"),
WithMultiArrows.Destination("database-read", destinations)
)

val toTitle =
(s: String) =>
Expand Down

0 comments on commit 91b7240

Please sign in to comment.