From e68bf9db4ca44115035a151af54e757156793422 Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Sat, 12 Nov 2022 01:17:53 +0100 Subject: [PATCH 1/4] #232 Legend details can be Small()==default, Normal() or None(); defined via SHOW_LEGEND($details=...) - if $legendText contains a `\n` then the part before is the label and the part behind the details --- C4.puml | 206 ++++++++++++++++++++--------- LayoutOptions.md | 75 ++++++++++- README.md | 4 +- percy/TestLegendDetailsNone.puml | 25 ++++ percy/TestLegendDetailsNormal.puml | 25 ++++ percy/TestLegendDetailsSmall.puml | 25 ++++ 6 files changed, 295 insertions(+), 65 deletions(-) create mode 100644 percy/TestLegendDetailsNone.puml create mode 100644 percy/TestLegendDetailsNormal.puml create mode 100644 percy/TestLegendDetailsSmall.puml diff --git a/C4.puml b/C4.puml index 3b67cc9..800ba06 100644 --- a/C4.puml +++ b/C4.puml @@ -37,19 +37,22 @@ rectangle C4VersionDetailsArea <> [ ' Labels ' ################################## -!global $LEGEND_SHADOW_TEXT = "(shadow) " -!global $LEGEND_NO_SHADOW_TEXT = "(no shadow) " -!global $LEGEND_NO_FONT_BG_TEXT = "(no text, no back color) " -!global $LEGEND_NO_FONT_TEXT = "(no text color) " -!global $LEGEND_NO_BG_TEXT = "(no back color) " -!global $LEGEND_NO_LINE_TEXT = "(no line color) " -!global $LEGEND_ROUNDED_BOX = "(rounded box) " -!global $LEGEND_EIGHT_SIDED = "(eight sided) " -!global $LEGEND_DOTTED_LINE = "(dotted) " -!global $LEGEND_DASHED_LINE = "(dashed) " -!global $LEGEND_BOLD_LINE = "(bold) " -!global $LEGEND_DASHED_BOUNDARY = "boundary (dashed) " -!global $LEGEND_DASHED_TRANSPARENT_BOUNDARY = "boundary (dashed, transparent) " +!global $LEGEND_SHADOW_TEXT = "shadow" +!global $LEGEND_NO_SHADOW_TEXT = "no shadow" +!global $LEGEND_NO_FONT_BG_TEXT = "last text and back color" +!global $LEGEND_NO_FONT_TEXT = "last text color" +!global $LEGEND_NO_BG_TEXT = "last back color" +!global $LEGEND_NO_LINE_TEXT = "last line color" +!global $LEGEND_ROUNDED_BOX = "rounded box" +!global $LEGEND_EIGHT_SIDED = "eight sided" +!global $LEGEND_DOTTED_LINE = "dotted" +!global $LEGEND_DASHED_LINE = "dashed" +!global $LEGEND_BOLD_LINE = "bold" +!global $LEGEND_BOUNDARY = "boundary" +!global $LEGEND_DASHED_BOUNDARY = "dashed" +' ignore transparent atm, that the legend is smaller +'!global $LEGEND_DASHED_TRANSPARENT_BOUNDARY = "dashed, transparent" +!global $LEGEND_DASHED_TRANSPARENT_BOUNDARY = "dashed" !global $SKETCH_FOOTER_WARNING = "Warning:" !global $SKETCH_FOOTER_TEXT = "Created for discussion, needs to be validated" @@ -61,6 +64,10 @@ rectangle C4VersionDetailsArea <> [ !global $ROUNDED_BOX_SIZE = 25 !global $EIGHT_SIDED_SIZE = 18 +!global $LEGEND_DETAILS_SMALL_SIZE = 10 +!global $LEGEND_DETAILS_NORMAL_SIZE = 14 +!global $LEGEND_DETAILS_SIZE = $LEGEND_DETAILS_SMALL_SIZE + !global $ROUNDED_BOX = "roundedBox" !global $EIGHT_SIDED = "eightSided" @@ -68,6 +75,10 @@ rectangle C4VersionDetailsArea <> [ !global $DASHED_LINE = "dashed" !global $BOLD_LINE = "bold" +!global $LEGEND_DETAILS_NONE = "none" +!global $LEGEND_DETAILS_NORMAL = "normal" +!global $LEGEND_DETAILS_SMALL = "small" + skinparam defaultTextAlignment center skinparam wrapWidth 200 @@ -473,7 +484,7 @@ $elementSkin !return $formatted !endfunction -!function $tagLegendEntry($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $legendText, $legendSprite) +!function $setTagLegendVariables($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $legendText, $legendSprite) !$bg = $bgColor !$fo = $fontColor !$bo = $borderColor @@ -514,6 +525,7 @@ $elementSkin !endif !$tagEntry = "|" + !$tagDetails = "(" !$tagEntry = $tagEntry + "<" + $colorWithHash($bg) +">" ' ..white rectangle !$tagEntry = $tagEntry + " " @@ -524,9 +536,11 @@ $elementSkin !if ($legendText == "") !if ($tagStereo == "boundary") !if ($bgColor == "#00000000" || %lower($bgColor) == "transparent") - !$tagEntry = $tagEntry + " " + $LEGEND_DASHED_TRANSPARENT_BOUNDARY + !$tagEntry = $tagEntry + " " + $LEGEND_BOUNDARY + " " + !$tagDetails = $tagDetails + $LEGEND_DASHED_TRANSPARENT_BOUNDARY + ", " !else - !$tagEntry = $tagEntry + " " + $LEGEND_DASHED_BOUNDARY + !$tagEntry = $tagEntry + " " + $LEGEND_BOUNDARY + " " + !$tagDetails = $tagDetails + $LEGEND_DASHED_BOUNDARY + ", " !endif !elseif (%strpos($tagStereo, "boundary") >= 0) ' if contains/ends with _boundary remove _boundary and add "boundary (dashed)" @@ -534,46 +548,68 @@ $elementSkin !if ($pos > 0) !$tagEntry = $tagEntry + " " + %substr($tagStereo, 0 ,$pos) !if ($bgColor == "#00000000" || %lower($bgColor) == "transparent") - !$tagEntry = $tagEntry + " " + $LEGEND_DASHED_TRANSPARENT_BOUNDARY + !$tagEntry = $tagEntry + " " + $LEGEND_BOUNDARY + " " + !$tagDetails = $tagDetails + $LEGEND_DASHED_TRANSPARENT_BOUNDARY + ", " !else - !$tagEntry = $tagEntry + " " + $LEGEND_DASHED_BOUNDARY + !$tagEntry = $tagEntry + " " + $LEGEND_BOUNDARY + " " + !$tagDetails = $tagDetails + $LEGEND_DASHED_BOUNDARY + ", " !endif !endif !else !$tagEntry = $tagEntry + " " + $tagStereo + " " !endif !if ($shadowing == "true") - !$tagEntry = $tagEntry + $LEGEND_SHADOW_TEXT + !$tagDetails = $tagDetails + $LEGEND_SHADOW_TEXT + ", " !endif !if ($shadowing == "false") - !$tagEntry = $tagEntry + $LEGEND_NO_SHADOW_TEXT + !$tagDetails = $tagDetails + $LEGEND_NO_SHADOW_TEXT + ", " !endif !if ($shape == $ROUNDED_BOX) - !$tagEntry = $tagEntry + $LEGEND_ROUNDED_BOX + !$tagDetails = $tagDetails + $LEGEND_ROUNDED_BOX + ", " !endif !if ($shape == $EIGHT_SIDED) - !$tagEntry = $tagEntry + $LEGEND_EIGHT_SIDED + !$tagDetails = $tagDetails + $LEGEND_EIGHT_SIDED + ", " !endif !if ($fontColor == "" && $bgColor == "") - !$tagEntry = $tagEntry + $LEGEND_NO_FONT_BG_TEXT + !$tagDetails = $tagDetails + $LEGEND_NO_FONT_BG_TEXT + ", " !else !if ($fontColor == "") - !$tagEntry = $tagEntry + $LEGEND_NO_FONT_TEXT + !$tagDetails = $tagDetails + $LEGEND_NO_FONT_TEXT + ", " !endif !if ($bgColor == "") - !$tagEntry = $tagEntry + $LEGEND_NO_BG_TEXT + !$tagDetails = $tagDetails + $LEGEND_NO_BG_TEXT + ", " !endif !endif + !if ($tagDetails=="(") + !$tagDetails = "" + !else + !$tagDetails = %substr($tagDetails, 0, %strlen($tagDetails)-2) + !$tagDetails = $tagDetails + ")" + !endif !else - !$tagEntry = $tagEntry + " " + $legendText + " " + !$brPos = %strpos($legendText, "\n") + !if ($brPos > 0) + !$tagEntry = $tagEntry + %substr($legendText, 0, $brPos) + " " + !$details = %substr($legendText, $brPos + 2) + !if ($details=="") + !$tagDetails = "" + !else + !$tagDetails = $tagDetails + $details + ")" + !endif + !else + !$tagEntry = $tagEntry + " " + $legendText + " " + !$tagDetails = "" + !endif !endif - !$tagEntry = $tagEntry + " " - !$tagEntry = $tagEntry + "|" + !$tagDetails = $tagDetails + " " + !$tagDetails = $tagDetails + "|" +%set_variable_value("$" + $tagStereo + "LegendEntry", $tagEntry) +%set_variable_value("$" + $tagStereo + "LegendDetails", $tagDetails) !return $tagEntry !endfunction -!function $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness) +!function $setTagRelLegendVariables($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness) !$tc = $textColor !$lc = $lineColor @@ -593,6 +629,7 @@ $elementSkin !endif !$tagEntry = "|" + !$tagDetails = "(" ' ..white line !$tagEntry = $tagEntry + " " !$tagEntry = $tagEntry + "" @@ -602,45 +639,60 @@ $elementSkin !if ($legendText == "") !$tagEntry = $tagEntry + " " + $tagStereo + " " !if ($textColor == "") - !$tagEntry = $tagEntry + $LEGEND_NO_FONT_TEXT + !$tagDetails = $tagDetails + $LEGEND_NO_FONT_TEXT + ", " !endif !if ($lineColor == "") - !$tagEntry = $tagEntry + $LEGEND_NO_LINE_TEXT + !$tagDetails = $tagDetails + $LEGEND_NO_LINE_TEXT + ", " !endif !if ($lineStyle != "") !if ($lineStyle == $DOTTED_LINE) - !$tagEntry = $tagEntry + $LEGEND_DOTTED_LINE + !$tagDetails = $tagDetails + $LEGEND_DOTTED_LINE + ", " !elseif ($lineStyle == $DASHED_LINE) - !$tagEntry = $tagEntry + $LEGEND_DASHED_LINE + !$tagDetails = $tagDetails + $LEGEND_DASHED_LINE + ", " !elseif ($lineStyle == $BOLD_LINE) - !$tagEntry = $tagEntry + $LEGEND_BOLD_LINE + !$tagDetails = $tagDetails + $LEGEND_BOLD_LINE + ", " !else - !$tagEntry = $tagEntry + "(" + $lineStyle + ") " + !$tagDetails = $tagDetails + $lineStyle + ", " !endif !endif !if ($lineThickness != "") - !$tagEntry = $tagEntry + "(thickness " + $lineThickness + ") " + !$tagDetails = $tagDetails + thickness " + $lineThickness + ") " !endif + !if ($tagDetails=="(") + !$tagDetails = "" + !else + !$tagDetails = %substr($tagDetails, 0, %strlen($tagDetails)-2) + !$tagDetails = $tagDetails + ")" + !endif !else - !$tagEntry = $tagEntry + " " + $legendText + " " + !$brPos = %strpos($legendText, "\n") + !if ($brPos > 0) + !$tagEntry = $tagEntry + " " + %substr($legendText, 0, $brPos) + " " + !$details = %substr($legendText, $brPos + 2) + !if ($details=="") + !$tagDetails = "" + !else + !$tagDetails = $tagDetails + $details + ")" + !endif + !else + !$tagEntry = $tagEntry + " " + $legendText + " " + !$tagDetails = "" + !endif !endif - !$tagEntry = $tagEntry + " " - !$tagEntry = $tagEntry + "|" + !$tagDetails = $tagDetails + " " + !$tagDetails = $tagDetails + "|" +%set_variable_value("$" + $tagStereo + "_LineLegendEntry", $tagEntry) +%set_variable_value("$" + $tagStereo + "_LineLegendDetails", $tagDetails) !return $tagEntry !endfunction -!global $LEGEND_DOTTED_LINE = "(dotted) " -!global $LEGEND_DASHED_LINE = "(dashed) " -!global $LEGEND_BOLD_LINE = "(bold) " - !unquoted procedure $addTagToLegend($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $legendText="", $legendSprite="") '' if a combined element tag is defined (e.g. "v1.0&v1.1") then it is typically a merged color, '' like a new $fontColor="#fdae61" therefore it should be added to the legend '' and the & combined tags will be not removed ' !if (%strpos($tagStereo, "&") < 0) - !$tagEntry = $tagLegendEntry($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $legendText, $legendSprite) -%set_variable_value("$" + $tagStereo + "LegendEntry", $tagEntry) + !$dummyAlreadyVariables = $setTagLegendVariables($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $legendText, $legendSprite) !$tagCustomLegend = $tagCustomLegend + $tagStereo + "\n" !$tagMask = $tagLegendMask( $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite) %set_variable_value("$" + $tagStereo + "LegendMask", $tagMask) @@ -655,9 +707,8 @@ $elementSkin '' be an inconsistency between the element tags and the rel tags and therefore '' & combined workaround tags are not removed too (and in unlikely cases the color itself could be changed) ' !if (%strpos($tagStereo, "&") < 0) - !$tagEntry = $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness) -%set_variable_value("$" + $tagStereo + "_LineLegendEntry", $tagEntry) - !$tagCustomLegend = $tagCustomLegend + $tagStereo + "_Line\n" + !$dummyAlreadyVariables = $setTagRelLegendVariables($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness) + !$tagCustomLegend = $tagCustomLegend + $tagStereo + "_Line\n" ' !endif !endprocedure @@ -668,13 +719,23 @@ $elementSkin !$allDefined = %substr($allDefined, $brPos+2) !$brPos = %strpos($allDefined, "\n") !if (%variable_exists("$" + $tagStereo + "Legend")) -%get_variable_value("$" + $tagStereo + "LegendEntry") + ' is part of legendDetails + !$part1 = %get_variable_value("$" + $tagStereo + "LegendEntry") + !$partSize = "" + !$part2 = %get_variable_value("$" + $tagStereo + "LegendDetails") + !$line = $part1 + $partSize + $part2 +$line !endif !endwhile !if (%strlen($allDefined) > 0) !$tagStereo = $allDefined !if (%variable_exists("$" + $tagStereo + "Legend")) -%get_variable_value("$" + $tagStereo + "LegendEntry") + ' is part of legendDetails + !$part1 = %get_variable_value("$" + $tagStereo + "LegendEntry") + !$partSize = "" + !$part2 = %get_variable_value("$" + $tagStereo + "LegendDetails") + !$line = $part1 + $partSize + $part2 +$line !endif !endif !endprocedure @@ -722,7 +783,8 @@ $addTagToLegend($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $sha !$shape=$restoreEmpty($elementName, "shape", $shape, %true()) !$sprite=$restoreEmpty($elementName, "sprite", $sprite, %true()) !$techn=$restoreEmpty($elementName, "techn", $techn, %true()) - !$legendText=$restoreEmpty($elementName, "legendText", $legendText, %true()) + ' new style should has its own legend text + ' !$legendText=$restoreEmpty($elementName, "legendText", $legendText, %true()) !$legendSprite=$restoreEmpty($elementName, "legendSprite", $legendSprite, %true()) AddElementTag($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $techn, $legendText, $legendSprite) @@ -765,8 +827,7 @@ $defineSkinparams($elementName, $bgColor, $fontColor, $borderColor, $shadowing, !if ($techn != "") %set_variable_value("$" + $elementName + "ElementTagTechn", $techn) !endif - !$tagEntry = $tagLegendEntry($elementName, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $legendText, $legendSprite) -%set_variable_value("$" + $elementName + "LegendEntry", $tagEntry) + !$dummyAlreadyVariables = $setTagLegendVariables($elementName, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $legendText, $legendSprite) ' default tags sets at least bgColor and fontColor !$tagMask = $tagLegendMask("CHANGED", "CHANGED", $borderColor, $shadowing, $shape, $sprite) %set_variable_value("$" + $elementName + "LegendMask", $tagMask) @@ -946,22 +1007,34 @@ SetPropertyHeader("Property","Value") ' Layout ' ################################## +!function $getLegendDetailsSize($detailsFormat) + !if $detailsFormat == $LEGEND_DETAILS_NONE + !$size = 0 + !elseif $detailsFormat == $LEGEND_DETAILS_SMALL + !$size = $LEGEND_DETAILS_SMALL_SIZE + !else + !$size = $LEGEND_DETAILS_NORMAL_SIZE + !endif + !return $size +!endfunction + !procedure $getHideStereotype($hideStereotype) !if ($hideStereotype == "true") hide stereotype !endif !endprocedure -!procedure $getLegendTable() +!procedure $getLegendTable($detailsFormat) +!global $LEGEND_DETAILS_SIZE = $getLegendDetailsSize($detailsFormat) <#00000000,#00000000>|**Legend** | $showActiveLegendEntries($tagDefaultLegend) $showActiveLegendEntries($tagCustomLegend) !endprocedure -!procedure $getLegendArea($areaAlias, $hideStereotype) +!procedure $getLegendArea($areaAlias, $hideStereotype, $details) $getHideStereotype($hideStereotype) rectangle $areaAlias<> [ -$getLegendTable() +$getLegendTable($details) ] !endprocedure @@ -1072,11 +1145,24 @@ left to right direction left to right direction !endprocedure +' legend details can displayed as Normal(), Small(), None() +!function None() +!return $LEGEND_DETAILS_NONE +!endfunction + +!function Normal() +!return $LEGEND_DETAILS_NORMAL +!endfunction + +!function Small() +!return $LEGEND_DETAILS_SMALL +!endfunction + ' has to be last call in diagram -!unquoted procedure SHOW_LEGEND($hideStereotype="true") +!unquoted procedure SHOW_LEGEND($hideStereotype="true", $details=Small()) $getHideStereotype($hideStereotype) legend right -$getLegendTable() +$getLegendTable($details) endlegend !endprocedure @@ -1093,8 +1179,8 @@ SHOW_LEGEND($hideStereotype) !endfunction ' enables that legend can be located in drawing area of the diagram. It has to be last call in diagram followed by Lay_Distance() -!unquoted procedure SHOW_FLOATING_LEGEND($alias=LEGEND(), $hideStereotype="true") -$getLegendArea($alias, $hideStereotype) +!unquoted procedure SHOW_FLOATING_LEGEND($alias=LEGEND(), $hideStereotype="true", $details=Normal()) +$getLegendArea($alias, $hideStereotype, $details) !endprocedure ' Boundaries diff --git a/LayoutOptions.md b/LayoutOptions.md index 301b538..84fc0fe 100644 --- a/LayoutOptions.md +++ b/LayoutOptions.md @@ -130,7 +130,7 @@ SHOW_LEGEND() ![LAYOUT_LANDSCAPE Sample](https://www.plantuml.com/plantuml/png/NOzFRvj04CNlV8gjUmYM75kfUkef5ApaG1nae55FQ0sJUANzizeTXAAgtxqpCNQiSa7lDxFllRcFA0EEHeio-_tSDbsPxOewpwgjgANn6f8lolPw740S4NtyiTa4EQtV51x7mnWXzCuYM5ptpcoybfQzRYCEMXqs-VVRYb7xL6wCZ0Y1K9VJ2waiXBMdtIJvFpXT9aa58JgRoi4eknABZFygOf3emcAPrEzaPhgVRhI33EzfVxSIDwU-Dqln9n7qNMBI2GwTz9vyNk0WCk-rwYKgPnU4ygyhaTNLUhTjw4a0yMrz9vv-vJpBj7PJ57nc5EW4tUWbhPXHew8iqKmA4O90PK1JLgHkV-TsAPw6v3ElqJ3PWpvVzLchZH0vxx5fgfgsUEao_RHv08maWN-lmPdh9-VGUhLWULOjIT7wAr8mATnahrZ9h8HNl69xPdlrTiIvTjTwSXTrouNPaHaRVT22A8kPiza7Bucpc3aRdWPx6bpiwyVdbwxSFcntHKho7kmm6lqF "LAYOUT_LANDSCAPE Sample") -## LAYOUT_WITH_LEGEND() or SHOW_LEGEND(?hideStereotype) +## LAYOUT_WITH_LEGEND() or SHOW_LEGEND(?hideStereotype, ?details) Colors can help to add additional information or simply to make the diagram more aesthetically pleasing. It can also help to save some space. @@ -157,12 +157,17 @@ Rel(web_app, twitter, "Gets tweets from", "HTTPS") ![LAYOUT_WITH_LEGEND Sample](https://www.plantuml.com/plantuml/png/PL1DJy905BplhrZnG4cm3SQJ9sebO0BOs2Bnr2pjKpRPh-o-sX3ZV_Sr89YubqdUp7ipizE0mcEh5L-cRy-Rije-bOjgEPlFre-y4DefO5VIrAfjWEyHNRXF4Y-w-4FYljsr0Nnj3OB1kBOw4OsNmdogrhL9TdUJAs5mirecIY04f56LaLf80pvsvChOVzjen5WEFbWJYKPBC-Q3j4SPq0kqVZ1YnI4WwEh1jgOH_X3Lap4V7jCEH_oBSNfdewY3NIMSepjRsF7KEILhWTAQ0Osowp5FYpnUpqfQyS1lumbVlMOzbofbky3xae6ZvTJG2PBeLg4aBrvs4X4yHwb1aLUWRD-dT14UIRfpaX79Na3zjhh4sWJQ95oKPLwGgXUTsSkPEI35wA27Ts_rtvKfc8R-ymS0 "LAYOUT_WITH_LEGEND Sample") -Instead of a static legend (activated with `LAYOUT_WITH_LEGEND()`) a calculated legend can be activated with `SHOW_LEGEND(?hideStereotype)`. +Instead of a static legend (activated with `LAYOUT_WITH_LEGEND()`) a calculated legend can be activated with `SHOW_LEGEND(?hideStereotype, ?details)`. The calculated legend has following differences: * only relevant elements are listed * custom tags/styles are supported * stereotypes can remain visible (with `SHOW_LEGEND(false)`) +* details can be displayed in different sizes via the `$details` argument + * `$details = Small()` .. default; details are displayed with a smaller size compared to the legend labels + * `$details = Normal()` .. details and labels are displayed with same size + * `$details = None()` .. only the labels are displayed + * if `$legendText` contains `\n` then the text before is the label and the text behind the details * **`SHOW_LEGEND()` has to be last call in the diagram** ```plantuml @@ -184,7 +189,71 @@ SHOW_LEGEND() ![SHOW_LEGEND Sample](https://www.plantuml.com/plantuml/png/JL5Dgzf05DtFhxYr2oDeWgMhhfgceWkreObr6IR9RHsOZs7cXY3b_VTtWpurcqlEn-4Svdia6MWm6ghThtEptsmtnvzGIUCrYa_ATdhe4Iv4FdxBiY37z9-Yoz0E4KFdBA6bj7CcyrhQAMOLgTUgpOglgtA2JeTzPcGa30mr1JkaiXXIpreXIWpHsKJsHjabpFBfgaX1aWkpXQYkR3JD3pVONePhqgsNCBzrco_Wlm3-7f79Y6qZlUUSCxQGUwzL9qavEsEe-Bo4l2hJuwPcIq3uagxXyAUOk5nhDqQO9aKW1xp7IvQOGPFo6g4U5H4686LGAukHkxtTsoLq8pddBcDI_4RziUfPwnJPoNTNrsN5gadqO9ynMwJ8lpYTly6PLujuUQLa8Tu1 "SHOW_LEGEND Sample") -## SHOW_FLOATING_LEGEND(?alias, ?hideStereotype) and LEGEND() +Legend labels and details can be defined via `\n` in `$legendTest` arguments too. + +```plantuml +@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_Container.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!endif +' $legendText with \n defines the label and details of the legend entry ("backend container" is label, "eight sided shape" is details) +AddElementTag("backendContainer", $fontColor=$ELEMENT_FONT_COLOR, $bgColor="#335DA5", $shape=EightSidedShape(), $legendText="backend container\neight sided shape") +' $legendText without \n defines only a label +AddRelTag("async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DashedLine(), $legendText="async call") +' if no $legendText defined, $tag is automatically the label and all additional displayed properties are the details +AddRelTag("sync/async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DottedLine()) + +System_Boundary(c1, "Internet Banking") { + Container(mobile_app, "Mobile App", "C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device") + Container(backend_api, "API Application", "Java, Docker Container", "Provides Internet banking functionality via API", $tags="backendContainer") +} +System_Ext(banking_system, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") + +Rel(mobile_app, backend_api, "Uses", "async, JSON/HTTPS", $tags="async") +Rel_Neighbor(backend_api, banking_system, "Uses", "sync/async, XML/HTTPS", $tags="sync/async") + +SHOW_LEGEND() +@enduml +``` + +![SHOW_LEGEND Sample, $legendText defines legend details](https://www.plantuml.com/plantuml/png/hLDHRo8t47xdLqpsSYf815HTxwKIqd6mxUL480BIzk4aDBiUm3gllR9dIL3L_zxnRjWIagelvG7js9xFt_VDvq-1qNDLcCuFa3jx8C-W6Hurxm6LqgoTHIDRHO5MWT6M0FskAiWot4oNwMoyllqjtTpE9xE7QJfA1iF1805sK0K2ut8qvjYvqbjuVq2lCJEqeISTE7IJo-Qarm6uqZOtbI9uloFUj3q7D1MzrJAS_BIPECiepFoWZ4gko0GwXzepb-7duT3Zus0dogfCoFbSkaJ5GBGDIuCskd0JM1cT2UZDVLnwk9iD2mnC_irxhD9RCUxQq4w-r_JqxDmt2ugsSZ80xmaCPcGW-gT804m0jsqswZuG5lu8tIJ3_7kiyzCz2UZGTFSX8RtRCmIjI47OOqbnzuJOWyvOgTHG7CmQTorOopdfm_LMYeappe-kqrbwbyxNcryMyZTPp1PBsSzspMxoxiE7ZzFnnzXJNpLAu-MhUFSgrjrU_rprw3NrR_OrtzuRNhcAp-rorXm16ysrf2MPMWw6eyqZ7wQdauRnShdulIKVi_cl6oi-6XfDCUn9pQI-5D3WGunhJLC2QzqBiWr35HdWBZgF5Ri2MTSHlvYpB9q_7wL3QV182ahlIlAiIVeznQxJ1C_5HYx3_qUnOpufxdKwgsDWAZQVNMKL-cCt_r62TMkPl2M6psY_QxjBUl1d1-JNPgTRk4mRsc1Polcxke1nMIPIJTxruGyiq6iRotll3bf5UM1qeJaElye2yIdpxMrPSnjiAvitFcaM7ntaLH1doGSuQ8mzsaD301GTT2v1kg3td3xXfuN2-FusaZCwnuWRMNt50_PXwkIO_wVldEz_yOfK13XfvXz6hzwNaFhhv6_wnDrdc4sebw9jScphiQ2Jpz2SZYnMx7pqp9YJJRaij5IaqVcYLWEOnIVJUjG7p7CP9yiNUxG1Qz9I4US38TMHKBsOtqkp7W85OT3almzVLulvyCjwVRzgbJPRWYH0ctbyrPcxiFn2Qujw5cG9oTti4laivp6SNoJ2i_JNT3xjzZgV1BqgpDy0 "SHOW_LEGEND Sample, $legendText defines legend details") + +Legend details can be deactivated via `SHOW_LEGEND($details=None())` + +```plantuml +@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_Container.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!endif +' $legendText with \n defines the label and details of the legend entry ("backend container" is label, "eight sided shape" is details) +AddElementTag("backendContainer", $fontColor=$ELEMENT_FONT_COLOR, $bgColor="#335DA5", $shape=EightSidedShape(), $legendText="backend container\neight sided shape") +' $legendText without \n defines only a label +AddRelTag("async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DashedLine(), $legendText="async call") +' if no $legendText defined, $tag is automatically the label and all additional displayed properties are the details +AddRelTag("sync/async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DottedLine()) + +System_Boundary(c1, "Internet Banking") { + Container(mobile_app, "Mobile App", "C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device") + Container(backend_api, "API Application", "Java, Docker Container", "Provides Internet banking functionality via API", $tags="backendContainer") +} +System_Ext(banking_system, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") + +Rel(mobile_app, backend_api, "Uses", "async, JSON/HTTPS", $tags="async") +Rel_Neighbor(backend_api, banking_system, "Uses", "sync/async, XML/HTTPS", $tags="sync/async") + +SHOW_LEGEND($details=None()) +@enduml +``` + +![SHOW_LEGEND Sample, hide details with $details=None()](https://www.plantuml.com/plantuml/png/hLDHZ-8s47xdLypczbIGM51rlPTAICT1sjiJ2ojWspwS54tY8LZds97ji8kg_lUE4nAbx5PzAGyeu_7CVDytdpyvZzPNXHhy09dH9x8Uf8TdwO-0GaWlZKR5gQ90BK19JO0shmhI7kwMstWrtz__5YVtwyNgQHdFeibqCed06wWSWJ8PAdKUtCW3l3-XbPWgIkX5Ek-6qNLnD1e0t4YTgKeGlC_99rtD2LL5RvLC5pyb2wCzCZ8xAGEJ6rAE-gsEtfVkv-dKulCaPsPLok1inbNCOiBSfgL27LIuSruecNBJkyTmzFImcXReFDatvsWX3opShQASl_VqSb7kcmP11xxfm1y95AQa8EWdY1ie1-PG9vewO1Js3CCenUnxYBDsJWJIDTLZY4ZcHmzE2XBWZbXIoBOTHp2O2n4h2elPOzurwp17OxWzSB0mojZPRRoA7-BrFlbbmt-BpMgpvNoQDzdetOSF7vVpZw6c7ZMBm_1TcBqByN0qxhEUlOR-JR_6Etf3ArFvlbn6gpDWmxccj2LLqq5trbd0u-cbvJ3VRZU_T-23D_yriVDdHRCbkYE95SVN19h-4EnQmsJ3QjE_SK4e0WBCW_9OULEWbxN5h_RCH_td8wHZXvr9G6bDITPBudfBeQhTO9zim3BzVnWRxrl6ey5WTtQUYkIpgRH0UnvcFxAnxhKdgyd3PzJVfSwZ4Vmv0FvrtXaM9fMA4YnBllzG1p0louYZnRin_845Mgb3-6ZDIOf03vGif0_Bhr97llLyDorjfi6XqbcZa_Iieu6iSgmiMGSdYQ56McW0WA2JpDX8L_0kxcDyaY7C7-y3E2Kp37q3ggzumZ4i3L-pqDNryVuNhW256qVD_jtirVjYK7-r-iOlVdXfaxZwACZ6rmuM2sfrXkPsGB7pnWRDb6fbolYWWyA5nXOr6y0qF9bEep5Wbl4wFNzvYzfX3PeZyjc4GGtOLFtzmJ_5UdBa647Z_p5ytMtMqo_x_UEkOzgak1CtIjRXLQVcIl9hhctNdf7P90-hgyvzdmTpVc4Bh-9Vu_LoU7jv5RErQQpxYOTLXVeR "SHOW_LEGEND Sample, hide details with $details=None()") + +## SHOW_FLOATING_LEGEND(?alias, ?hideStereotype, ?details) and LEGEND() `LAYOUT_WITH_LEGEND()` and SHOW_LEGEND(?hideStereotype)` adds the legend at the bottom right of the picture like below and additional whitespace is created. diff --git a/README.md b/README.md index 79242c9..83c360e 100644 --- a/README.md +++ b/README.md @@ -387,8 +387,8 @@ Lay_Distance(LEGEND(), db, 1) C4-PlantUML also comes with some layout options to make it easy and reusable to create nice and useful diagrams: * [LAYOUT_TOP_DOWN() or LAYOUT_LEFT_RIGHT() or LAYOUT_LANDSCAPE()](LayoutOptions.md#layout_top_down-or-layout_left_right-or-layout_landscape) -* [LAYOUT_WITH_LEGEND() or SHOW_LEGEND(?hideStereotype)](LayoutOptions.md#layout_with_legend-or-show_legend) -* [SHOW_FLOATING_LEGEND(?alias, ?hideStereotype) and LEGEND()](LayoutOptions.md#show_floating_legendalias-hidestereotype-and-legend) +* [LAYOUT_WITH_LEGEND() or SHOW_LEGEND(?hideStereotype, ?details)](LayoutOptions.md#layout_with_legend-or-show_legend) +* [SHOW_FLOATING_LEGEND(?alias, ?hideStereotype, ?details) and LEGEND()](LayoutOptions.md#show_floating_legendalias-hidestereotype-and-legend) * [LAYOUT_AS_SKETCH() and SET_SKETCH_STYLE(?bgColor, ?fontColor, ?warningColor, ?fontName, ?footerWarning, ?footerText)](LayoutOptions.md#layout_as_sketch) * [HIDE_STEREOTYPE()](LayoutOptions.md#hide_stereotype) diff --git a/percy/TestLegendDetailsNone.puml b/percy/TestLegendDetailsNone.puml new file mode 100644 index 0000000..f59d0d6 --- /dev/null +++ b/percy/TestLegendDetailsNone.puml @@ -0,0 +1,25 @@ +@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_Container.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!endif +' $legendText with \n defines the label and details of the legend entry ("backend container" is label, "eight sided shape" is details) +AddElementTag("backendContainer", $fontColor=$ELEMENT_FONT_COLOR, $bgColor="#335DA5", $shape=EightSidedShape(), $legendText="backend container\neight sided shape") +' $legendText without \n defines only a label +AddRelTag("async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DashedLine(), $legendText="async call") +' if no $legendText defined, $tag is automatically the label and all additional displayed properties are the details +AddRelTag("sync/async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DottedLine()) + +System_Boundary(c1, "Internet Banking") { + Container(mobile_app, "Mobile App", "C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device") + Container(backend_api, "API Application", "Java, Docker Container", "Provides Internet banking functionality via API", $tags="backendContainer") +} +System_Ext(banking_system, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") + +Rel(mobile_app, backend_api, "Uses", "async, JSON/HTTPS", $tags="async") +Rel_Neighbor(backend_api, banking_system, "Uses", "sync/async, XML/HTTPS", $tags="sync/async") + +SHOW_LEGEND($details=None()) +@enduml \ No newline at end of file diff --git a/percy/TestLegendDetailsNormal.puml b/percy/TestLegendDetailsNormal.puml new file mode 100644 index 0000000..48f479f --- /dev/null +++ b/percy/TestLegendDetailsNormal.puml @@ -0,0 +1,25 @@ +@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_Container.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!endif +' $legendText with \n defines the label and details of the legend entry ("backend container" is label, "eight sided shape" is details) +AddElementTag("backendContainer", $fontColor=$ELEMENT_FONT_COLOR, $bgColor="#335DA5", $shape=EightSidedShape(), $legendText="backend container\neight sided shape") +' $legendText without \n defines only a label +AddRelTag("async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DashedLine(), $legendText="async call") +' if no $legendText defined, $tag is automatically the label and all additional displayed properties are the details +AddRelTag("sync/async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DottedLine()) + +System_Boundary(c1, "Internet Banking") { + Container(mobile_app, "Mobile App", "C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device") + Container(backend_api, "API Application", "Java, Docker Container", "Provides Internet banking functionality via API", $tags="backendContainer") +} +System_Ext(banking_system, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") + +Rel(mobile_app, backend_api, "Uses", "async, JSON/HTTPS", $tags="async") +Rel_Neighbor(backend_api, banking_system, "Uses", "sync/async, XML/HTTPS", $tags="sync/async") + +SHOW_LEGEND($details=Normal()) +@enduml \ No newline at end of file diff --git a/percy/TestLegendDetailsSmall.puml b/percy/TestLegendDetailsSmall.puml new file mode 100644 index 0000000..e034874 --- /dev/null +++ b/percy/TestLegendDetailsSmall.puml @@ -0,0 +1,25 @@ +@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_Container.puml +!else + !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!endif +' $legendText with \n defines the label and details of the legend entry ("backend container" is label, "eight sided shape" is details) +AddElementTag("backendContainer", $fontColor=$ELEMENT_FONT_COLOR, $bgColor="#335DA5", $shape=EightSidedShape(), $legendText="backend container\neight sided shape") +' $legendText without \n defines only a label +AddRelTag("async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DashedLine(), $legendText="async call") +' if no $legendText defined, $tag is automatically the label and all additional displayed properties are the details +AddRelTag("sync/async", $textColor=$ARROW_COLOR, $lineColor=$ARROW_COLOR, $lineStyle=DottedLine()) + +System_Boundary(c1, "Internet Banking") { + Container(mobile_app, "Mobile App", "C#, Xamarin", "Provides a limited subset of the Internet banking functionality to customers via their mobile device") + Container(backend_api, "API Application", "Java, Docker Container", "Provides Internet banking functionality via API", $tags="backendContainer") +} +System_Ext(banking_system, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") + +Rel(mobile_app, backend_api, "Uses", "async, JSON/HTTPS", $tags="async") +Rel_Neighbor(backend_api, banking_system, "Uses", "sync/async, XML/HTTPS", $tags="sync/async") + +SHOW_LEGEND($details=Small()) +@enduml \ No newline at end of file From f1aa60f1ee357906778337b3dc40c6763f66c44d Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Sat, 12 Nov 2022 01:54:53 +0100 Subject: [PATCH 2/4] #232 Legend details (2 - fix tests) --- C4.puml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C4.puml b/C4.puml index 800ba06..aa0db07 100644 --- a/C4.puml +++ b/C4.puml @@ -656,7 +656,7 @@ $elementSkin !endif !endif !if ($lineThickness != "") - !$tagDetails = $tagDetails + thickness " + $lineThickness + ") " + !$tagDetails = $tagDetails + "thickness " + $lineThickness + ") " !endif !if ($tagDetails=="(") !$tagDetails = "" From 20e4dcdd18552c6ec7f7015653012a10c7299ba7 Mon Sep 17 00:00:00 2001 From: kirchsth Date: Tue, 15 Nov 2022 14:11:49 +0100 Subject: [PATCH 3/4] Add badges (#260) Add badges --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 83c360e..6191a71 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ +[![release][Release Badge]][Release Page] +[![license MIT][License Badge]][License Page] +       +[![commits since][Commits Since Badge]][Commit Page] +[![last commit][Last Commit Badge]][Commit Page] +[![build result][Tests Badge]][Tests Page] + +[Release Badge]: https://img.shields.io/github/v/release/plantuml-stdlib/C4-PlantUML?display_name=tag +[Release Page]: https://github.com/plantuml-stdlib/C4-PlantUML/releases/latest +[License Badge]: https://img.shields.io/github/license/plantuml-stdlib/C4-PlantUML +[License Page]: https://github.com/plantuml-stdlib/C4-PlantUML/blob/master/LICENSE + +[Commits Since Badge]: https://img.shields.io/github/commits-since/plantuml-stdlib/C4-PlantUML/latest?label=new%20unreleased%20changes +[Last Commit Badge]: https://img.shields.io/github/last-commit/plantuml-stdlib/C4-PlantUML?color=yellow +[Commit Page]: https://github.com/plantuml-stdlib/C4-PlantUML/commits +[Tests Badge]: https://github.com/plantuml-stdlib/C4-PlantUML/actions/workflows/run-percy-tests.yml/badge.svg +[Tests Page]: https://github.com/plantuml-stdlib/C4-PlantUML/actions/workflows/run-percy-tests.yml + # C4-PlantUML ![Container diagram for Internet Banking System](https://www.plantuml.com/plantuml/png/hLPlZzh64txFfvYGH0690_sKNzvKEYaSkCr5S4Snb_GT6di7UvNrhhkxvWvL_UwTDJO-k5IfrBu1x-pEypmxVyR-w3nQNnMgzmvIe_TaFKWFZzBdW498Bur6nLj5WLg0afe0RLOLf3rSpTVHOhgv_H9jR-zcYuTvTDqVzy4Rg1o1CYagTUYzaZjukqShCL6qfIVfl1lqBptxmnx0AwbJLGc2yMGydip-lvqPxP4vxRWC6b-HSlJyNEvzwNwQJ2m-ZZFMN2NCR5FsOdrZLZqf5UfmloldXP89WrwjWkbXkPWKw3pPx_9e8NUzNlpf_kjs5QtZ-xlj_SDcSNiN3OOSgGrc3bnLbiPwq0PSYIava1fyJg2n81Waw4Y0EPegBSXoyAJE872IyOUIt0WUSvdc88n-vrl05WtreJ2MXcDWnjlToMm9BFrU4UE8bb9Hnf97pJzuUcfoM3j1ZYva9I4Gj9EQH6ygHAGeP97lCkWdc7vZnrCO-YDui-F5p2XZhzz4YsWPtMssFz_pp-n-SR_c_IGxxlPVlt__OJxz47nSZYLTHpBBVIm5YJYi1qFUEIhRiB3hbWtIbWu655p01PzXVnZahKdLqj0TT1gm-LAjdkbwpObfXOIY_DkDs1yKNS_HvIGMKhEOC_G0FlblA8pt7KNFIwy8JW458J6pMC3EMBZLdgmc3pUeluMIY0_EKz7hhSWwemTfvRmfo8vWTdhgJw4rWzdLIK_OUtHCSraxegfjW6bgAkrTdtKSeRStR11e3uFqVunrAQ0_X3zw0D3f7JnIiiMovCDVAO5fMIgPOfW6VJPznZsE82vj4B_yCWksEIcvPncrDEVvR0fD8m9gKPjFl4bxyTMKHPupkn8PBkPjHLShp2YmjwnnQcNfHp3LMQNG1lFAchqKeJEK-ZxBhjBfSP19Vm1lE99r81ti9GONQO7l2uarZuxi2qM5IQIY9XpBi3XfchqUmMzO84VYN0ieMSZGeQvA77dEsJ_Mvbw8Eme0GNkPqgMyUJ8Gw37Ccv26vZ6eYNzTmDdQ6qiEmeW4IvbqtjOf1QcvB8lwUGHvtIk0bSyXjIH8UudAZK9PaNEWJCOBykduHQ2QnkP8oL2ngzll5yxSy37R-Pr5xWSH2a5XuBfRCNFNBqONY_hpLFRHanzGWL9jNMrWekXgoUkcvGBp9YUGDIagMChK6cTs7gAdD4UT4Hmz6VOPPgEjGsLClRDOq4LFTs4FvTbMGSg6zdxFWm-OcCft9J0wjV88l4Nji8v45_xUcjIpST4rxOCZ5xW_RJQhc0-UdtCb_l1CK_GTN4EtlGkpEZ7TYAZXkW7G8DN6yu9e2UjvEuBF_5gTrEHTDkkj1g5JyE-0jZVitCdkckKST4qe7EoiAUfvzMYb9mVU1AA6PtupOyWJvhDeNHHPpB0Ew2fOQunEo7azdccuzAiSrqT77oytAmOwoy6P-qLLTd7gtd8yhPQBorXrsmn__EXPHBz4T_F1iBSpnfC5OV5H7zyrxUSJxCVmDYHS6ZqOrZ7hFgx2BY-_jDkzZwooAjHV "Container diagram for Internet Banking System") From 8d0810054930240188396857e3f6e93ad10bc0a4 Mon Sep 17 00:00:00 2001 From: KIRCHSTH Date: Thu, 10 Nov 2022 21:07:04 +0100 Subject: [PATCH 4/4] #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 aa0db07..c89d556 100644 --- a/C4.puml +++ b/C4.puml @@ -873,72 +873,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 @@ -1225,10 +1210,10 @@ $getLegendArea($alias, $hideStereotype, $details) !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 @@ -1257,9 +1242,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 @@ -1278,10 +1265,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 dc9bbd3..4d09e94 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 5899751..a6639fa 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 c4a601c..50c5a1e 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 2c12b65..663c9ed 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 1f2b985..8633ec4 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 0000000..a794ca1 --- /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