Skip to content

#255 All $label and $techn supports line breaks #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 37 additions & 50 deletions C4.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '</size>//\n//<size:'+$TECHN_FONT_SIZE+'>'
!$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) + '</size>//\n//<size:'+$TECHN_FONT_SIZE+'>'
!$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 = '</size>//\n//<size:'+$TECHN_FONT_SIZE+'>'
!return $breakText($text, $usedNewLine, $widthStr)
!endfunction

' Element properties
Expand Down Expand Up @@ -1139,10 +1124,10 @@ $getLegendArea($alias, $hideStereotype)

!function $getBoundary($label, $type)
!if ($type == "")
!return '==' + $label
!return '== ' + $breakLabel($label)
!endif
!if (type != "")
!return '==' + $label + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $type + ']</size>'
!return '== ' + $breakLabel($label) + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $type + ']</size>'
!endif
!endfunction

Expand Down Expand Up @@ -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
Expand All @@ -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//<size:$TECHN_FONT_SIZE>[$techn]</size>//
$getRel($direction, $alias1, $alias2, $label, $techn, "", "", "", "")
!endprocedure

!unquoted procedure Rel($from, $to, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
Expand Down
4 changes: 2 additions & 2 deletions C4_Component.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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//<size:' + $TECHN_FONT_SIZE + '>[' + $techn + ']</size>//'
!$component = $component + '\n//<size:' + $TECHN_FONT_SIZE + '>[' + $breakTechn($techn, '-1') + ']</size>//'
!endif
!if ($descr != "")
!$component = $component + '\n\n' + $descr
Expand Down
4 changes: 2 additions & 2 deletions C4_Container.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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//<size:' + $TECHN_FONT_SIZE + '>[' + $techn + ']</size>//'
!$container = $container + '\n//<size:' + $TECHN_FONT_SIZE + '>[' + $breakTechn($techn, '-1') + ']</size>//'
!endif
!if ($descr != "")
!$container = $container + '\n\n' + $descr
Expand Down
16 changes: 8 additions & 8 deletions C4_Context.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 7 additions & 37 deletions C4_Deployment.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '</size>\n<size:'+$TECHN_FONT_SIZE+'>'
!$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) + '</size>\n<size:'+$TECHN_FONT_SIZE+'>'
!$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 = '</size>\n<size:'+$TECHN_FONT_SIZE+'>'
!return $breakText($text, $usedNewLine, $widthStr)
!endfunction

' Elements
Expand All @@ -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<size:' + $TECHN_FONT_SIZE + '>[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
!endif
Expand All @@ -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<size:' + $TECHN_FONT_SIZE + '>[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
!endif
Expand All @@ -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<size:' + $TECHN_FONT_SIZE + '>[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
!endif
Expand Down
4 changes: 2 additions & 2 deletions C4_Dynamic.puml
Original file line number Diff line number Diff line change
Expand Up @@ -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//<size:$TECHN_FONT_SIZE>[$techn]</size>//
$getRel($direction, $alias1, $alias2, $e_index + ": " + $label, $techn, "", "", "", "")
!endprocedure

!unquoted procedure Rel($from, $to, $label, $techn="", $descr="", $sprite="", $tags="", $link="")
Expand Down
42 changes: 42 additions & 0 deletions percy/TestLabelsWithLineBreak.puml
Original file line number Diff line number Diff line change
@@ -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