From 91b72408aba7a71628b4d4b77cdf402022607558 Mon Sep 17 00:00:00 2001 From: Mark Canlas Date: Wed, 27 Mar 2024 18:17:50 -0400 Subject: [PATCH] gray --- .../temporaldiagrams/demo/DemoDsl.scala | 58 ++++++++++++++----- .../demo/WriteDemoDslDiagrams.scala | 19 ++++-- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/DemoDsl.scala b/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/DemoDsl.scala index 26c13e52..3927a93b 100644 --- a/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/DemoDsl.scala +++ b/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/DemoDsl.scala @@ -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: @@ -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 @@ -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) diff --git a/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/WriteDemoDslDiagrams.scala b/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/WriteDemoDslDiagrams.scala index b9922433..b2dd15ec 100644 --- a/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/WriteDemoDslDiagrams.scala +++ b/temporal-diagrams-demo/src/main/scala/com/htmlism/temporaldiagrams/demo/WriteDemoDslDiagrams.scala @@ -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) =>