From 1b5e399a9a35dbae39943304ffa12ec57a45befd Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Sat, 12 Dec 2020 17:59:36 +0100 Subject: [PATCH] #92-Deployment-Diagram-supports-(automatic-calculated)-line-breaks-of-type-labels --- C4_Deployment.puml | 55 ++++++++++++++++++- ...eployment Diagram Sample - bigbankplc.puml | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/C4_Deployment.puml b/C4_Deployment.puml index 7d65d84..4c8cf94 100644 --- a/C4_Deployment.puml +++ b/C4_Deployment.puml @@ -2,22 +2,71 @@ ' uncomment the following line and comment the first to use locally ' !include C4_Container.puml +' Colors +' ################################## + +!global $NODE_FONT_COLOR = "#000000" +!global $NODE_BORDER_COLOR = "#A2A2A2" + ' Styling ' ################################## skinparam rectangle<> { Shadowing false StereotypeFontSize 0 - FontColor #000000 - BorderColor #A2A2A2 + FontColor $NODE_FONT_COLOR + BorderColor $NODE_BORDER_COLOR BorderStyle solid } +' Special +' ################################## + +' PlantUML supports no automatic line breaks of "PlantUML containers" (C4 Deployment_Node is a "PlantUML container") +' therefore Deployment_Node() implements an automatic line break based on spaces (like in all other objects). +' If a $type contains \n then the these are used (and no automatic space based line breaks are done) +' $NODE_TYPE_MAX_CHAR_WIDTH defines the automatic line break position +!global $NODE_TYPE_MAX_CHAR_WIDTH = 35 + ' Elements ' ################################## !unquoted function Deployment_Node($alias, $label) !return 'rectangle "=='+$label+'" <> as '+$alias !endfunction + !unquoted function Deployment_Node($alias, $label, $type) -!return 'rectangle "=='+$label+'\n['+$type+']" <> as '+$alias +!$multiLine = "" +!if (%strpos($type, "\n") >= 0) + !while (%strpos($type, "\n") >= 0) + !$brPos = %strpos($type, "\n") + !$multiLine = $multiLine + %substr($type, 0, $brPos) + '\n' + !$type = %substr($type, $brPos+2) + !endwhile +!else + !while (%strlen($type)>$NODE_TYPE_MAX_CHAR_WIDTH) + !$brPos = $NODE_TYPE_MAX_CHAR_WIDTH + !while ($brPos>0 && %substr($type, $brPos, 1)!= ' ') + !$brPos = $brPos - 1 + !endwhile + + !if ($brPos < 1) + !$brPos = %strpos($type, " ") + !else + !endif + + !if ($brPos > 0) + !$multiLine = $multiLine + %substr($type, 0, $brPos) + '\n' + !$type = %substr($type, $brPos) + !else + !$multiLine = $multiLine+ $type + !$type = "" + !endif + !endwhile +!endif +!if (%strlen($type)>0) + !$multiLine = $multiLine + $type +!else +!endif +!return 'rectangle "=='+$label+'\n['+$multiLine+']" <> as '+$alias !endfunction + diff --git a/samples/C4_Deployment Diagram Sample - bigbankplc.puml b/samples/C4_Deployment Diagram Sample - bigbankplc.puml index fa8a740..7ca981f 100644 --- a/samples/C4_Deployment Diagram Sample - bigbankplc.puml +++ b/samples/C4_Deployment Diagram Sample - bigbankplc.puml @@ -36,7 +36,7 @@ Deployment_Node(mob, "Customer's mobile device", "Apple IOS or Android"){ } Deployment_Node(comp, "Customer's computer", "Mircosoft Windows of Apple macOS"){ - Deployment_Node(browser, "Web Browser", "Google Chrome, Mozilla Firefox"){ + Deployment_Node(browser, "Web Browser", "Google Chrome, Mozilla Firefox, Apple Safari or Microsoft Edge"){ Container(spa, "Single Page Application", "JavaScript and Angular", "Provides all of the Internet Banking functionality to customers via their web browser.") } }