From 706632273c4bdd10b7a4bdf3a6a3c67823d31b91 Mon Sep 17 00:00:00 2001 From: Johannes Thorn Date: Mon, 18 Apr 2022 22:43:50 +0200 Subject: [PATCH] Add DomainStory library --- DomainStory/INFO | 2 + DomainStory/domainStory.puml | 332 +++++++++++++++++++++++++++++++++++ README.md | 29 +++ 3 files changed, 363 insertions(+) create mode 100644 DomainStory/INFO create mode 100644 DomainStory/domainStory.puml diff --git a/DomainStory/INFO b/DomainStory/INFO new file mode 100644 index 000000000..1769c15f3 --- /dev/null +++ b/DomainStory/INFO @@ -0,0 +1,2 @@ +VERSION=0.3 +SOURCE=https://github.com/johthor/DomainStory-PlantUML \ No newline at end of file diff --git a/DomainStory/domainStory.puml b/DomainStory/domainStory.puml new file mode 100644 index 000000000..e33f9cb37 --- /dev/null +++ b/DomainStory/domainStory.puml @@ -0,0 +1,332 @@ +' Default Styling +' ################################## + +!$textColor ?= "#0b0c10" + +!$actorStyle ?= "default" +!$actorScale ?= 1 +!$actorColor ?= "#1f2833" + +!$objectStyle ?= "default" +!$objectScale ?= 0.8 +!$objectColor ?= "#1f2833" + +!$boundaryColor ?= "#1f2833" + +!$activityColor ?= "#c5c6c7" + +!$stepColor ?= "#66fcf1" +!$stepFontSize ?= 16 +!$stepFontColor ?= $textColor + +!$noteColor ?= "#c5c6c7" +!$noteBorder ?= "#1f2833" + +hide stereotypes +skinparam Shadowing false +skinparam DefaultTextAlignment center +skinparam Padding 5 + +' agent nodes are used for the actors +skinparam agent { + FontColor $textColor + BackgroundColor none + BorderColor none +} + +' card nodes are used for the work objects +skinparam card { + FontColor $textColor + BackgroundColor none + BorderColor none +} + +skinparam rectangle<> { + FontColor $textColor + BackgroundColor none + BorderColor $boundaryColor + BorderStyle dashed + RoundCorner 15 +} + +skinparam Arrow { + FontColor $textColor + Color $activityColor +} + +skinparam note { + FontColor $textColor + BackgroundColor $noteColor + BorderColor $noteBorder +} + +' Layout +' ################################## + +left to right direction + +' in journeys with multiple stories the default top to down direction +' usually gives better results + +' Actors +' ################################## +!unquoted procedure Actor($kind, $sprite, $name, $label = "", $color = "", $scale = "", $note = "") + !if $label == "" + !$label = $name + !endif + !if $color == "" + !$color = $actorColor + !endif + !if $scale == "" + !$scale = $actorScale + !endif + agent "<$sprite{scale=$scale}>\r $label" as $name <<$kind>> + + $addNote($name, $note) +!endprocedure + +!if %not(%variable_exists("$personSprite")) + !if $actorStyle == "default" + !include + !global $personSprite = "$ma_account_outline" + !else + !include + !global $personSprite = "$ma_account" + !endif +!endif + +!unquoted procedure Person($name, $label = "", $color = "", $scale = "", $note = "") + Actor("Person", "$personSprite", $name, $label, $color, $scale, $note) +!endprocedure + +!if %not(%variable_exists("$groupSprite")) + !if $actorStyle == "default" + !include + !global $groupSprite = "$ma_account_multiple_outline" + !else + !include + !global $groupSprite = "$ma_account_multiple" + !endif +!endif + +!unquoted procedure Group($name, $label = "", $color = "", $scale = "", $note = "") + Actor("Group", "$groupSprite", $name, $label, $color, $scale, $note) +!endprocedure + +!include +!unquoted procedure System($name, $label = "", $color = "", $scale = "", $note = "") + Actor("System", "$ma_laptop", $name, $label, $color, $scale, $note) +!endprocedure + +' Work objects +' ################################## +!unquoted procedure Object($kind, $sprite, $name, $label = "", $color = "", $scale = "", $note = "") + !if $label == "" + !$label = $name + !endif + !if $color == "" + !$color = $objectColor + !endif + !if $scale == "" + !$scale = $objectScale + !endif + card "<$sprite{scale=$scale}>\r $label" as $name <<$kind>> + + $addNote($name, $note) +!endprocedure + +!if %not(%variable_exists("$documentSprite")) + !if $objectStyle == "default" + !include + !global $documentSprite = "$ma_file_document" + !else + !include + !global $documentSprite = "$ma_document" + !endif +!endif + +!unquoted procedure Document($name, $label = "", $color = "", $scale = "", $note = "") + Object("Document", "$documentSprite", $name, $label, $color, $scale, $note) +!endprocedure + +!if %not(%variable_exists("$folderSprite")) + !if $objectStyle == "default" + !include + !global $folderSprite = "$ma_folder_outline" + !else + !include + !global $folderSprite = "$ma_folder" + !endif +!endif + +!unquoted procedure Folder($name, $label = "", $color = "", $scale = "", $note = "") + Object("Folder", "$folderSprite", $name, $label, $color, $scale, $note) +!endprocedure + +!include +!unquoted procedure Call($name, $label = "", $color = "", $scale = "", $note = "") + Object("Call", "$ma_phone", $name, $label, $color, $scale, $note) +!endprocedure + +!if %not(%variable_exists("$emailSprite")) + !if $objectStyle == "default" + !include + !global $emailSprite = "$ma_at" + !else + !include + !global $emailSprite = "$ma_email" + !endif +!endif + +!unquoted procedure Email($name, $label = "", $color = "", $scale = "", $note = "") + Object("Email", "$emailSprite", $name, $label, $color, $scale, $note) +!endprocedure + +!if %not(%variable_exists("$conversationSprite")) + !if $objectStyle == "default" + !include + !global $conversationSprite = "$ma_message_outline" + !else + !include + !global $conversationSprite = "$ma_message" + !endif +!endif + +!unquoted procedure Conversation($name, $label = "", $color = "", $scale = "", $note = "") + Object("Conversation", "$conversationSprite", $name, $label, $color, $scale, $note) +!endprocedure + +!if %not(%variable_exists("$infoSprite")) + !if $objectStyle == "default" + !include + !global $infoSprite = "$ma_information_outline" + !else + !include + !global $infoSprite = "$ma_information" + !endif +!endif + +!unquoted procedure Info($name, $label = "", $color = "", $scale = "", $note = "") + Object("Info", "$infoSprite", $name, $label, $color, $scale, $note) +!endprocedure + +' Boundaries +' ################################## +!unquoted procedure Boundary($name, $label = "") + !if $label == "" + !$label = $name + !endif + rectangle "==$label" <> as $name +!endprocedure + +' Activities +' ################################## + +!global $stepCounter = 0 +!global $objectCounter = 0 + +!unquoted procedure activity($step, $subject, $predicate, $object, $post = "", $target = "", $objectArr = "", $targetArr = "", $color = "", $scale = "", $note = "") + ' ensure object exists / create one dynamically + !$object = $ensureObjectExists($object, $color, $scale) + + ' handle forward or backward activity + !if $objectArr == "" && $targetArr == "" + !$bwPosition = %strpos($step, "<") + !if $bwPosition > 0 + !$step = %substr($step, 0, $bwPosition) + !$objectArr = "<--" + !$targetArr = "<--" + !endif + !endif + + !if $objectArr == "" + !$objectArr = "-->" + !endif + + !if $targetArr == "" + !$targetArr = $objectArr + !endif + + ' create connecting arrows + $arrow($subject, $object, $objectArr) : $stepLabel($step) $predicate + + !if $post != "" && $post != "_" + !if $target != "" && $target != "_" + $arrow($object, $target, $targetArr) : $post + !else + $arrow($object, $post, $targetArr) + !endif + !endif + + $addNote($object, $note) +!endprocedure + +' Helper +' ################################## + +!procedure $addNote($target, $note) + !if $note != "" + !$noteDir = %substr($note, 0, 1) + !if $noteDir == "v" + note bottom of $target : %substr($note, 1) + !elseif $noteDir == "<" + note left of $target : %substr($note, 1) + !elseif $noteDir == "^" + note top of $target : %substr($note, 1) + !elseif $noteDir == ">" + note right of $target : %substr($note, 1) + !else + note right of $target : $note + !endif + !endif +!endprocedure + +!function $ensureObjectExists($object, $color = "", $scale = "") + !$objectName = $object + !$objectSeparator = %strpos($object, ":") + !if $objectSeparator > 0 + !$objectCounter = %intval($objectCounter) + 1 + !$objectKind = %substr($object, 0, $objectSeparator) + !$objectLabel = %substr($object, $objectSeparator + 1) + !$objectName = $objectKind + $objectCounter + %invoke_procedure($objectKind, $objectName, $objectLabel, $color, $scale) + !endif + !return $objectName +!endfunction + +!function $arrow($from, $to, $spec) + !if %substr($spec, 0, 1) == "<" + !return $to + " " + $spec + " " + $from + !else + !return $from + " " + $spec + " " + $to + !endif +!endfunction + +!function $computeStep($step) + !if $step == "_" + !$stepCounter = $stepCounter + 1 + !return $stepCounter + !elseif $step == "|" + !return $stepCounter + !elseif %substr($step, 0, 1) == "=" + !$stepCounter = %intval(%substr($step, 1)) + !return $stepCounter + !else + !return $step + !endif +!endfunction + +!function $stepLabel($step) + !$stepNum = $computeStep($step) + !$result = "(" + $stepNum + ")" + !if ($stepColor != "") + !$result = "" + $result + "" + !endif + !if ($stepFontColor != "") + !$result = "" + $result + "" + !endif + !if ($stepFontSize != "") + !$result = "" + $result + "" + !endif + !return $result +!endfunction diff --git a/README.md b/README.md index 9056f9066..912b75f58 100644 --- a/README.md +++ b/README.md @@ -257,6 +257,34 @@ MA_FOLDER_MOVE(Red, 1, dir, rectangle, "A label") This example renders the following image: ![Example](http://www.plantuml.com/plantuml/png/PSn12i8m40NGVK_nsqqL0k9U2eNMbRLGYjiIawa69faGKz7RUm3V0LxfWk7D4avUPqfEyy68znAQeiOiS3vAoiXFmYicbmchOy9NDdJZjPuHY2oo8B8s18sOQ7MViYZ_urNOKbgylAafYg5TpkEbwwTb66_zRYAhS5ImBYaaCbc71vD2rOBrdRZQ_m00 "Example") +## Domain Story library + +This library provides a set of macros to easily describe and document a domain story which was developed in +a [Domain Storytelling](http://www.domainstorytelling.org) workshop. + +For more usage instructions see [DomainStory-PlantUML](https://github.com/johthor/DomainStory-PlantUML). + +Example of usage: + +``` +@startuml +!include + +Boundary(System) { + Person(Alice) + Conversation(weather) + Person(Bob) +} + +activity(1, Alice, talks about the, weather, with, Bob) +@enduml +``` + +This example renders the following image: + +![Example](http://www.plantuml.com/plantuml/png/JSx1IWGn30RWUv-YtcPWdEBLqxfwL5XOV81C9zXg9rdQlxiCuhlR7GGtf_0bVyYkW3BgainT59_gp3O0f_BeNARB-14HwbGBPwy25enU5_Uf0K6pUz65eXoXURq_91AylxswAxdvVpAUhjVDNglCbDVkk1RmqjjlOriTE1ULxYb5p_qcpohdXeJO_CA4mBc_tTthr9iVOyWZdYFMxc6mMtwmeFHLB4rQOH4Q_ELR4n46kqLtB7DxwHS0 + "Example") + ## Notes When mixing sprites macros with other elements you may get a syntax error if, for example, trying to add a rectangle along with classes. @@ -290,5 +318,6 @@ This example renders the following image: * **tupadr3**: made by https://github.com/tupadr3/plantuml-icon-font-sprites * **Material Icons**: from https://github.com/Templarian/MaterialDesign * **Elastic Icons**: from https://github.com/Crashedmind/PlantUML-Elastic-icons +* **Domain Story**: from https://github.com/johthor/DomainStory-PlantUML You can create Pull Request to update or add some library here if you find it relevant.