From 18045826c4dfe407f34a3008b7768fb757a12ed4 Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Thu, 10 Nov 2022 21:07:04 +0100 Subject: [PATCH] #255 All $label and $techn supports line breaks --- C4.puml | 87 +++++++++++++----------------- C4_Component.puml | 4 +- C4_Container.puml | 4 +- C4_Context.puml | 16 +++--- C4_Deployment.puml | 44 +++------------ C4_Dynamic.puml | 4 +- percy/TestLabelsWithLineBreak.puml | 42 +++++++++++++++ 7 files changed, 100 insertions(+), 101 deletions(-) create mode 100644 percy/TestLabelsWithLineBreak.puml diff --git a/C4.puml b/C4.puml index 3b67cc92..c9eb8e16 100644 --- a/C4.puml +++ b/C4.puml @@ -812,72 +812,57 @@ $elementSkin !global $REL_TECHN_MAX_CHAR_WIDTH = 35 !global $REL_DESCR_MAX_CHAR_WIDTH = 32 -!unquoted function $breakDescr($descr, $widthStr) +!unquoted function $breakText($text, $usedNewLine, $widthStr="-1") !$width = %intval($widthStr) !$multiLine = "" -!if (%strpos($descr, "\n") >= 0) +!if (%strpos($text, "\n") >= 0) + !while (%strpos($text, "\n") >= 0) + !$brPos = %strpos($text, "\n") + !$multiLine = $multiLine + %substr($text, 0, $brPos) + $usedNewLine + !$text = %substr($text, $brPos+2) + !endwhile !else - !while (%strlen($descr) > $width) + !while ($width>0 && %strlen($text) > $width) !$brPos = $width - !while ($brPos > 0 && %substr($descr, $brPos, 1) != ' ') + !while ($brPos > 0 && %substr($text, $brPos, 1) != ' ') !$brPos = $brPos - 1 !endwhile !if ($brPos < 1) - !$brPos = %strpos($descr, " ") + !$brPos = %strpos($text, " ") !else !endif !if ($brPos > 0) - !$multiLine = $multiLine + %substr($descr, 0, $brPos) + "\n" - !$descr = %substr($descr, $brPos + 1) + !$multiLine = $multiLine + %substr($text, 0, $brPos) + $usedNewLine + !$text = %substr($text, $brPos + 1) !else - !$multiLine = $multiLine+ $descr - !$descr = "" + !$multiLine = $multiLine+ $text + !$text = "" !endif !endwhile !endif -!if (%strlen($descr) > 0) - !$multiLine = $multiLine + $descr +!if (%strlen($text) > 0) + !$multiLine = $multiLine + $text !endif !return $multiLine !endfunction -' $breakTechn() supports //...//; $breakNode() in C4_Deployment supports no //....// -!unquoted function $breakTechn($techn, $widthStr) -!$width = %intval($widthStr) -!$multiLine = "" -!if (%strpos($techn, "\n") >= 0) - !while (%strpos($techn, "\n") >= 0) - !$brPos = %strpos($techn, "\n") - !$multiLine = $multiLine + %substr($techn, 0, $brPos) + '//\n//' - !$techn = %substr($techn, $brPos+2) - !endwhile -!else - !while (%strlen($techn) > $width) - !$brPos = $width - !while ($brPos > 0 && %substr($techn, $brPos, 1) != ' ') - !$brPos = $brPos - 1 - !endwhile +!unquoted function $breakLabel($text) +!$usedNewLine = "\n== " +!$multiLine = $breakText($text, $usedNewLine) +!return $multiLine +!endfunction - !if ($brPos < 1) - !$brPos = %strpos($techn, " ") - !else - !endif +!unquoted function $breakDescr($text, $widthStr) + !$usedNewLine = "\n" + !return $breakText($text, $usedNewLine, $widthStr) +!endfunction - !if ($brPos > 0) - !$multiLine = $multiLine + %substr($techn, 0, $brPos) + '//\n//' - !$techn = %substr($techn, $brPos + 1) - !else - !$multiLine = $multiLine+ $techn - !$techn = "" - !endif - !endwhile -!endif -!if (%strlen($techn) > 0) - !$multiLine = $multiLine + $techn -!endif -!return $multiLine +' $breakTechn() supports //...//; $breakNode() in C4_Deployment supports no //....// +!unquoted function $breakTechn($text, $widthStr) + !$usedNewLine = '//\n//' + !return $breakText($text, $usedNewLine, $widthStr) !endfunction ' Element properties @@ -1139,10 +1124,10 @@ $getLegendArea($alias, $hideStereotype) !function $getBoundary($label, $type) !if ($type == "") - !return '==' + $label + !return '== ' + $breakLabel($label) !endif !if (type != "") - !return '==' + $label + '\n[' + $type + ']' + !return '== ' + $breakLabel($label) + '\n[' + $type + ']' !endif !endfunction @@ -1171,9 +1156,11 @@ UpdateBoundaryStyle("", $bgColor=$BOUNDARY_BG_COLOR, $fontColor=$BOUNDARY_COLOR, !$rel = $rel + $getSprite($sprite) + ' ' !endif !if ($link != "") - !$rel = $rel + '**[[' + $link + ' ' + $label + ']]**' + !$usedNewLine = ']]**\n**[[' + $link + ' ' + !$rel = $rel + '**[[' + $link + ' ' + $breakText($label, $usedNewLine) + ']]**' !else - !$rel = $rel + '**' + $label + '**' + !$usedNewLine = '**\n**' + !$rel = $rel + '**' + $breakText($label, $usedNewLine) + '**' !endif !if ($techn != "") ' line break is not deterministic, calculate it @@ -1192,10 +1179,10 @@ UpdateBoundaryStyle("", $bgColor=$BOUNDARY_BG_COLOR, $fontColor=$BOUNDARY_COLOR, !endfunction !unquoted procedure Rel_($alias1, $alias2, $label, $direction) -$alias1 $direction $alias2 : **$label** +$getRel($direction, $alias1, $alias2, $label, "", "", "", "", "") !endprocedure !unquoted procedure Rel_($alias1, $alias2, $label, $techn, $direction) -$alias1 $direction $alias2 : **$label**\n//[$techn]// +$getRel($direction, $alias1, $alias2, $label, $techn, "", "", "", "") !endprocedure !unquoted procedure Rel($from, $to, $label, $techn="", $descr="", $sprite="", $tags="", $link="") diff --git a/C4_Component.puml b/C4_Component.puml index dc9bbd34..4d09e94d 100644 --- a/C4_Component.puml +++ b/C4_Component.puml @@ -62,9 +62,9 @@ endlegend !if ($sprite != "") !$component = $component + $getSprite($sprite) + '\n' !endif - !$component = $component + '==' + $label + !$component = $component + '== ' + $breakLabel($label) !if ($techn != "") - !$component = $component + '\n//[' + $techn + ']//' + !$component = $component + '\n//[' + $breakTechn($techn, '-1') + ']//' !endif !if ($descr != "") !$component = $component + '\n\n' + $descr diff --git a/C4_Container.puml b/C4_Container.puml index 58997518..a6639fa1 100644 --- a/C4_Container.puml +++ b/C4_Container.puml @@ -63,9 +63,9 @@ endlegend !if ($sprite != "") !$container = $container + $getSprite($sprite) + '\n' !endif - !$container = $container + '==' + $label + !$container = $container + '== ' + $breakLabel($label) !if ($techn != "") - !$container = $container + '\n//[' + $techn + ']//' + !$container = $container + '\n//[' + $breakTechn($techn, '-1') + ']//' !endif !if ($descr != "") !$container = $container + '\n\n' + $descr diff --git a/C4_Context.puml b/C4_Context.puml index c4a601c2..50c5a1e1 100644 --- a/C4_Context.puml +++ b/C4_Context.puml @@ -326,31 +326,31 @@ UpdateElementStyle("person") !$sprite = $defaultPersonSprite !endif !if ($descr == "") && ($sprite == "") - !return '=='+$label + !return '== '+$breakLabel($label) !endif !if ($descr == "") && ($sprite != "") - !return $getSprite($sprite)+'\n=='+$label + !return $getSprite($sprite)+'\n== '+$breakLabel($label) !endif !if ($descr != "") && ($sprite == "") - !return '=='+$label+'\n\n '+$descr + !return '== '+$breakLabel($label)+'\n\n '+$descr !endif !if ($descr != "") && ($sprite != "") - !return $getSprite($sprite)+'\n=='+$label+'\n\n '+$descr + !return $getSprite($sprite)+'\n== '+$breakLabel($label)+'\n\n '+$descr !endif !endfunction !function $getSystem($label, $descr, $sprite) !if ($descr == "") && ($sprite == "") -!return '=='+$label +!return '== '+$breakLabel($label) !endif !if ($descr == "") && ($sprite != "") -!return $getSprite($sprite)+'\n=='+$label +!return $getSprite($sprite)+'\n== '+$breakLabel($label) !endif !if ($descr != "") && ($sprite == "") -!return '=='+$label+'\n\n '+$descr +!return '== '+$breakLabel($label)+'\n\n '+$descr !endif !if ($descr != "") && ($sprite != "") -!return $getSprite($sprite)+'\n=='+$label+'\n\n '+$descr +!return $getSprite($sprite)+'\n== '+$breakLabel($label)+'\n\n '+$descr !endif !endfunction diff --git a/C4_Deployment.puml b/C4_Deployment.puml index 2c12b65a..663c9ed5 100644 --- a/C4_Deployment.puml +++ b/C4_Deployment.puml @@ -42,40 +42,10 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy !global $NODE_TYPE_MAX_CHAR_WIDTH = 35 !global $NODE_DESCR_MAX_CHAR_WIDTH = 32 -!unquoted function $breakNode($type, $widthStr) -!$width = %intval($widthStr) -!$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) > $width) - !$brPos = $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 + 1) - !else - !$multiLine = $multiLine+ $type - !$type = "" - !endif - !endwhile -!endif -!if (%strlen($type) > 0) - !$multiLine = $multiLine + $type -!endif -!return $multiLine +' $breakTechn() in C4 supports //...//; $breakNode() in C4_Deployment supports no //....// +!unquoted function $breakNode($text, $widthStr) + !$usedNewLine = '\n' + !return $breakText($text, $usedNewLine, $widthStr) !endfunction ' Elements @@ -86,7 +56,7 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy !if ($sprite != "") !$nodeText = $nodeText + $getSprite($sprite) + '\n' !endif - !$nodeText = $nodeText + '==' + $label + !$nodeText = $nodeText + '== ' + $breakText($label, "\n== ") !if ($type != "") !$nodeText = $nodeText + '\n[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']' !endif @@ -101,7 +71,7 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy !if ($sprite != "") !$nodeText = $nodeText + $getSprite($sprite) + '\l' !endif - !$nodeText = $nodeText + '==' + $label + !$nodeText = $nodeText + '== ' + $breakText($label, "\l== ") !if ($type != "") !$nodeText = $nodeText + '\l[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']' !endif @@ -116,7 +86,7 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy !if ($sprite != "") !$nodeText = $nodeText + $getSprite($sprite) + '\r' !endif - !$nodeText = $nodeText + '==' + $label + !$nodeText = $nodeText + '== ' + $breakText($label, "\r== ") !if ($type != "") !$nodeText = $nodeText + '\r[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']' !endif diff --git a/C4_Dynamic.puml b/C4_Dynamic.puml index 1f2b9859..8633ec48 100644 --- a/C4_Dynamic.puml +++ b/C4_Dynamic.puml @@ -59,10 +59,10 @@ ' ################################## !unquoted procedure Rel_($e_index, $alias1, $alias2, $label, $direction) -$alias1 $direction $alias2 : **$e_index: $label** +$getRel($direction, $alias1, $alias2, $e_index + ": " + $label, "", "", "", "", "") !endprocedure !unquoted procedure Rel_($e_index, $alias1, $alias2, $label, $techn, $direction) -$alias1 $direction $alias2 : **$e_index: $label**\n//[$techn]// +$getRel($direction, $alias1, $alias2, $e_index + ": " + $label, $techn, "", "", "", "") !endprocedure !unquoted procedure Rel($from, $to, $label, $techn="", $descr="", $sprite="", $tags="", $link="") diff --git a/percy/TestLabelsWithLineBreak.puml b/percy/TestLabelsWithLineBreak.puml new file mode 100644 index 00000000..a794ca14 --- /dev/null +++ b/percy/TestLabelsWithLineBreak.puml @@ -0,0 +1,42 @@ +@startuml +' convert it with additional command line argument -DRELATIVE_INCLUDE="./.." to use locally +!if %variable_exists("RELATIVE_INCLUDE") + !include %get_variable_value("RELATIVE_INCLUDE")/C4_Component.puml + !include %get_variable_value("RELATIVE_INCLUDE")/C4_Deployment.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Deployment.puml +!endif + +Enterprise_Boundary(eb, "Enterprise\nBoundary") { + Person(p1, "Normal\nUser\nLabel", "Description\nLine\nBreak") + Container(c1, "Container\nLabel", "container techn\nwith line break", "Description\nLine\nBreak") + Component(c2, "Component\nLabel", component techn\nwith line break", "Description\nLine\nBreak") +} + +System_Ext(s1, "System Label\nWith\nLineBreak", "Description\nLine\nBreak") + +Rel_(p1, c1, "A relation\nwith custom direction", "o-DOWN->>") +Rel_(p1, c2, "A relation\nwith custom direction", "and technology\nwith LBs", "o-RIGHT-o") + +Rel(c1, c2, "A label\nwith\nline breaks", "and technology\nwith LBs") +Rel(c1, s1, "A linked label\nwith\nline breaks", "and technology\nwith LBs", $link = "http://www.plantuml.com") + +Node(n1, "A node label\nwith\nline breaks", "type with\nline break", "description\nwith line break") +Node(n2, "A node label", "PlantUML packages have no automatic line breaks, type breaks added", "PlantUML packages have no automatic line breaks, description breaks added") { + Container(cInNode, "A container in node") +} + +!if %variable_exists("RELATIVE_INCLUDE") + !include %get_variable_value("RELATIVE_INCLUDE")/C4_Dynamic.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Dynamic.puml +!endif + +Component(from, "From component") +Component(to, "To component") + +Rel_("pre1", from, to, "A custom dynamic relation\nwith custom direction", "o-DOWN->>") +Rel_("pre2", from, to, "A custom dynamic relation\nwith custom direction", "and technology\nwith LBs", "+--+") +Rel(from, to, "A dynamic relation\nwith line break") +@enduml \ No newline at end of file