mirror of
https://github.com/plantuml-stdlib/C4-PlantUML.git
synced 2022-10-18 01:14:54 +00:00
#126: C4 relationships use calculated line breaks (PlantUML internal line breaks are not deterministic)
This commit is contained in:
@@ -223,6 +223,84 @@ $defineSkinparams($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing)
|
||||
!$tagDefaultLegend = $tagStereoEntries
|
||||
!endprocedure
|
||||
|
||||
' Line breaks
|
||||
' ##################################
|
||||
|
||||
' PlantUML supports no DETERMINISTIC/automatic line breaks of "PlantUML line" (C4 Relashionships)
|
||||
' therefore Rel...() implements an automatic line break based on spaces (like in all other objects).
|
||||
' If a $type contains \n then these are used (and no automatic space based line breaks are done)
|
||||
' $REL_TECHN_MAX_CHAR_WIDTH defines the automatic line break position
|
||||
!global $REL_TECHN_MAX_CHAR_WIDTH = 35
|
||||
!global $REL_DESCR_MAX_CHAR_WIDTH = 32
|
||||
|
||||
!unquoted function $breakDescr($descr, $widthStr)
|
||||
!$width = %intval($widthStr)
|
||||
!$multiLine = ""
|
||||
!if (%strpos($descr, "\n") >= 0)
|
||||
!else
|
||||
!while (%strlen($descr)>$width)
|
||||
!$brPos = $width
|
||||
!while ($brPos>0 && %substr($descr, $brPos, 1)!= ' ')
|
||||
!$brPos = $brPos - 1
|
||||
!endwhile
|
||||
|
||||
!if ($brPos < 1)
|
||||
!$brPos = %strpos($descr, " ")
|
||||
!else
|
||||
!endif
|
||||
|
||||
!if ($brPos > 0)
|
||||
!$multiLine = $multiLine + %substr($descr, 0, $brPos) + "\n"
|
||||
!$descr = %substr($descr, $brPos + 1)
|
||||
!else
|
||||
!$multiLine = $multiLine+ $descr
|
||||
!$descr = ""
|
||||
!endif
|
||||
!endwhile
|
||||
!endif
|
||||
!if (%strlen($descr)>0)
|
||||
!$multiLine = $multiLine + $descr
|
||||
!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
|
||||
|
||||
!if ($brPos < 1)
|
||||
!$brPos = %strpos($techn, " ")
|
||||
!else
|
||||
!endif
|
||||
|
||||
!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
|
||||
!endfunction
|
||||
|
||||
' Element properties
|
||||
' ##################################
|
||||
|
||||
@@ -355,12 +433,12 @@ rectangle "$getBoundary($label, $type)" $toStereos("boundary", $tags) as $alias
|
||||
!endif
|
||||
!$rel = $rel + '**' + $label + '**'
|
||||
!if ($techn != "")
|
||||
' last version of plantuml server supports automatic line breaks (no $breakType() required)
|
||||
!$rel = $rel + '\n//<size:' + $TECHN_FONT_SIZE + '>[' + $techn + ']</size>//'
|
||||
' line break is not deterministic, calculate it
|
||||
!$rel = $rel + '\n//<size:' + $TECHN_FONT_SIZE + '>[' + $breakTechn($techn, $REL_TECHN_MAX_CHAR_WIDTH) + ']</size>//'
|
||||
!endif
|
||||
!if ($descr != "")
|
||||
' last version of plantuml server supports automatic line breaks (no $breakDescr() required)
|
||||
!$rel = $rel + '\n\n' + $descr
|
||||
' line break is not deterministic, calculate it
|
||||
!$rel = $rel + '\n\n' + $breakDescr($descr, $REL_DESCR_MAX_CHAR_WIDTH)
|
||||
!endif
|
||||
!return $rel
|
||||
!endfunction
|
||||
|
||||
+9
-40
@@ -28,20 +28,17 @@ skinparam rectangle<<node>> {
|
||||
' comment if node should not be added to legend. No dynamic legend extension required
|
||||
SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_system\nexternal_container\nnode")
|
||||
|
||||
' Special
|
||||
' Line breaks
|
||||
' ##################################
|
||||
|
||||
' 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)
|
||||
' therefore (Deployment_)Node() implements an automatic line break based on spaces (like in all other objects).
|
||||
' If a $type contains \n then 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
|
||||
!global $NODE_DESCR_MAX_CHAR_WIDTH=32
|
||||
|
||||
' Elements
|
||||
' ##################################
|
||||
|
||||
!unquoted function $breakType($type, $widthStr)
|
||||
!unquoted function $breakNode($type, $widthStr)
|
||||
!$width = %intval($widthStr)
|
||||
!$multiLine = ""
|
||||
!if (%strpos($type, "\n") >= 0)
|
||||
@@ -77,36 +74,8 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy
|
||||
!return $multiLine
|
||||
!endfunction
|
||||
|
||||
!unquoted function $breakDescr($descr, $widthStr)
|
||||
!$width = %intval($widthStr)
|
||||
!$multiLine = ""
|
||||
!if (%strpos($descr, "\n") >= 0)
|
||||
!else
|
||||
!while (%strlen($descr)>$width)
|
||||
!$brPos = $width
|
||||
!while ($brPos>0 && %substr($descr, $brPos, 1)!= ' ')
|
||||
!$brPos = $brPos - 1
|
||||
!endwhile
|
||||
|
||||
!if ($brPos < 1)
|
||||
!$brPos = %strpos($descr, " ")
|
||||
!else
|
||||
!endif
|
||||
|
||||
!if ($brPos > 0)
|
||||
!$multiLine = $multiLine + %substr($descr, 0, $brPos) + "\n"
|
||||
!$descr = %substr($descr, $brPos + 1)
|
||||
!else
|
||||
!$multiLine = $multiLine+ $descr
|
||||
!$descr = ""
|
||||
!endif
|
||||
!endwhile
|
||||
!endif
|
||||
!if (%strlen($descr)>0)
|
||||
!$multiLine = $multiLine + $descr
|
||||
!endif
|
||||
!return $multiLine
|
||||
!endfunction
|
||||
' Elements
|
||||
' ##################################
|
||||
|
||||
!function $getNode($label, $type, $descr, $sprite)
|
||||
!$nodeText = ""
|
||||
@@ -115,7 +84,7 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy
|
||||
!endif
|
||||
!$nodeText = $nodeText + '==' + $label
|
||||
!if ($type != "")
|
||||
!$nodeText = $nodeText + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $breakType($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
|
||||
!$nodeText = $nodeText + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
|
||||
!endif
|
||||
!if ($descr != "")
|
||||
!$nodeText = $nodeText + '\n\n' + $breakDescr($descr, $NODE_DESCR_MAX_CHAR_WIDTH)
|
||||
@@ -130,7 +99,7 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy
|
||||
!endif
|
||||
!$nodeText = $nodeText + '==' + $label
|
||||
!if ($type != "")
|
||||
!$nodeText = $nodeText + '\l<size:' + $TECHN_FONT_SIZE + '>[' + $breakType($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
|
||||
!$nodeText = $nodeText + '\l<size:' + $TECHN_FONT_SIZE + '>[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
|
||||
!endif
|
||||
!if ($descr != "")
|
||||
!$nodeText = $nodeText + '\l\l' + $breakDescr($descr, $NODE_DESCR_MAX_CHAR_WIDTH)
|
||||
@@ -145,7 +114,7 @@ SetDefaultLegendEntries("person\nsystem\ncontainer\nexternal_person\nexternal_sy
|
||||
!endif
|
||||
!$nodeText = $nodeText + '==' + $label
|
||||
!if ($type != "")
|
||||
!$nodeText = $nodeText + '\r<size:' + $TECHN_FONT_SIZE + '>[' + $breakType($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
|
||||
!$nodeText = $nodeText + '\r<size:' + $TECHN_FONT_SIZE + '>[' + $breakNode($type, $NODE_TYPE_MAX_CHAR_WIDTH) + ']</size>'
|
||||
!endif
|
||||
!if ($descr != "")
|
||||
!$nodeText = $nodeText + '\r\r' + $breakDescr($descr, $NODE_DESCR_MAX_CHAR_WIDTH)
|
||||
|
||||
Reference in New Issue
Block a user