Skip to content

Commit 8bb4a58

Browse files
committed
plantuml-stdlib#350 Boundaries support sprites which are defined via tags
If a sprite is defined then it displayed in the first line in front of the (with a smaller size, typically 50%) - AddBoundaryTag(..., ?sprite, ?legendSprite) - UpdateBoundaryStyle(..., ?sprite, ?legendSprite) - UpdateContainerBoundaryStyle(..., ?sprite, ?legendSprite) - UpdateSystemBoundaryStyle(..., ?sprite, ?legendSprite) - UpdateEnterpriseBoundaryStyle(..., ?sprite, ?legendSprite) Default sprite size can be changed via $BOUNDARY_IMAGE_SIZE_FACTOR
1 parent 315b477 commit 8bb4a58

5 files changed

+38
-32
lines changed

C4.puml

+24-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ rectangle C4VersionDetailsArea <<legendArea>> [
3434
!$BOUNDARY_COLOR ?= "#444444"
3535
!$BOUNDARY_BG_COLOR ?= "transparent"
3636
!$BOUNDARY_BORDER_STYLE ?= "dashed"
37+
' boundary symbols written in the same line, typically only 50% of the size in element
38+
!$BOUNDARY_IMAGE_SIZE_FACTOR ?= 0.5
3739

3840
!$LEGEND_TITLE_COLOR ?= "#000000"
3941
!$LEGEND_FONT_COLOR ?= "#FFFFFF"
@@ -595,13 +597,13 @@ $elementSkin
595597
!endfunction
596598

597599
' element symbols typically 4 times too big in legend
598-
!function $smallVersionSprite($sprite)
600+
!function $smallVersionSprite($sprite, $imageScale = $LEGEND_IMAGE_SIZE_FACTOR)
599601
' ,scale= ... has to be first (...,color=black,scale=0.25... is invalid too)
600602
!if (%strpos($sprite, "=") < 0)
601603
!if (%substr($sprite, 0, 4) == "img:")
602-
!$smallSprite = $sprite + "{scale=" + $LEGEND_IMAGE_SIZE_FACTOR + "}"
604+
!$smallSprite = $sprite + "{scale=" + $imageScale + "}"
603605
!else
604-
!$smallSprite = $sprite + ",scale=" + $LEGEND_IMAGE_SIZE_FACTOR
606+
!$smallSprite = $sprite + ",scale=" + $imageScale
605607
!endif
606608
!else
607609
!$smallSprite = $sprite
@@ -1373,22 +1375,22 @@ $getLegendArea($alias, $hideStereotype, $details)
13731375
' Boundaries
13741376
' ##################################
13751377

1376-
!unquoted procedure UpdateBoundaryStyle($elementName="", $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $type="", $legendText="", $borderStyle="", $borderThickness="")
1378+
!unquoted procedure UpdateBoundaryStyle($elementName="", $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $type="", $legendText="", $borderStyle="", $borderThickness="", $sprite="", $legendSprite="")
13771379
!if ($elementName != "")
13781380
!$elementBoundary = $elementName + '_boundary'
1379-
UpdateElementStyle($elementBoundary, $bgColor, $fontColor, $borderColor, $shadowing, $shape, "", $type, $legendText, "", $borderStyle, $borderThickness)
1381+
UpdateElementStyle($elementBoundary, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $type, $legendText, $legendSprite, $borderStyle, $borderThickness)
13801382
!else
1381-
UpdateElementStyle("boundary", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "", $type, $legendText, "", $borderStyle, $borderThickness)
1383+
UpdateElementStyle("boundary", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $type, $legendText, $legendSprite, $borderStyle, $borderThickness)
13821384
' simulate color inheritance
1383-
UpdateBoundaryStyle("enterprise", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "Enterprise", "", $borderStyle, $borderThickness)
1384-
UpdateBoundaryStyle("system", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "System", "", $borderStyle, $borderThickness)
1385-
UpdateBoundaryStyle("container", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "Container", "", $borderStyle, $borderThickness)
1385+
UpdateBoundaryStyle("enterprise", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "Enterprise", "", $borderStyle, $borderThickness, $sprite, $legendSprite)
1386+
UpdateBoundaryStyle("system", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "System", "", $borderStyle, $borderThickness, $sprite, $legendSprite)
1387+
UpdateBoundaryStyle("container", $bgColor, $fontColor, $borderColor, $shadowing, $shape, "Container", "", $borderStyle, $borderThickness, $sprite, $legendSprite)
13861388
!endif
13871389
!endprocedure
13881390

1389-
!unquoted procedure AddBoundaryTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $type="", $legendText="", $borderStyle="", $borderThickness="")
1391+
!unquoted procedure AddBoundaryTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $type="", $legendText="", $borderStyle="", $borderThickness="", $sprite="", $legendSprite="")
13901392
!$tagBoundary = $tagStereo + '_boundary'
1391-
AddElementTag($tagBoundary, $bgColor, $fontColor, $borderColor, $shadowing, $shape, "", $type, $legendText, "", $borderStyle, $borderThickness)
1393+
AddElementTag($tagBoundary, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $type, $legendText, $legendSprite, $borderStyle, $borderThickness)
13921394
!endprocedure
13931395

13941396
' add _boundary to all tags that short tag version can be used
@@ -1410,20 +1412,24 @@ $getLegendArea($alias, $hideStereotype, $details)
14101412
!return $boundaryTags
14111413
!endfunction
14121414

1413-
!function $getBoundary($label, $type)
1414-
!if ($type == "")
1415-
!return '== ' + $breakLabel($label)
1415+
!function $getBoundary($sprite, $label, $type)
1416+
!$line = '== '
1417+
!if ($sprite != "")
1418+
!$line = $line + $getSprite($smallVersionSprite($sprite, $BOUNDARY_IMAGE_SIZE_FACTOR)) + ' '
14161419
!endif
1417-
!if (type != "")
1418-
!return '== ' + $breakLabel($label) + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $type + ']</size>'
1420+
!$line = $line + $breakLabel($label)
1421+
!if ($type != "")
1422+
!$line = $line + '\n<size:' + $TECHN_FONT_SIZE + '>[' + $type + ']</size>'
14191423
!endif
1424+
!return $line
14201425
!endfunction
14211426

14221427
!unquoted procedure Boundary($alias, $label, $type="", $tags="", $link="")
14231428
!$boundaryTags = $addBoundaryPostfix($tags)
1424-
' nodes $type reuses $techn definition of $boundaryTags
1429+
' boundary $type reuses $techn definition of $boundaryTags
14251430
!$type=$toElementArg($type, $boundaryTags, "ElementTagTechn", "boundary")
1426-
rectangle "$getBoundary($label, $type)" $toStereos("boundary", $boundaryTags) as $alias $getLink($link)
1431+
!$sprite=$toElementArg("", $boundaryTags, "ElementTagSprite", "boundary")
1432+
rectangle "$getBoundary($sprite, $label, $type)" $toStereos("boundary", $boundaryTags) as $alias $getLink($link)
14271433
!endprocedure
14281434

14291435
' Boundary Styling

C4_Container.puml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ UpdateBoundaryStyle("container", $bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontCol
4040
$addElementTagInclReuse("external_container", $tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $techn, $legendText, $legendSprite, $borderStyle, $borderThickness)
4141
!endprocedure
4242

43-
!unquoted procedure UpdateContainerBoundaryStyle($bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontColor=$CONTAINER_BOUNDARY_COLOR, $borderColor=$CONTAINER_BOUNDARY_COLOR, $shadowing="", $shape="", $type="Container", $legendText="", $borderStyle="", $borderThickness="")
44-
UpdateBoundaryStyle("container", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $type, $legendText, $borderStyle, $borderThickness)
43+
!unquoted procedure UpdateContainerBoundaryStyle($bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontColor=$CONTAINER_BOUNDARY_COLOR, $borderColor=$CONTAINER_BOUNDARY_COLOR, $shadowing="", $shape="", $type="Container", $legendText="", $borderStyle="", $borderThickness="", $sprite="", $legendSprite="")
44+
UpdateBoundaryStyle("container", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $type, $legendText, $borderStyle, $borderThickness, $sprite, $legendSprite)
4545
!endprocedure
4646

4747
' Layout

C4_Context.puml

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ UpdateBoundaryStyle("enterprise", $bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontC
6262
$addElementTagInclReuse("external_system", $tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $type, $legendText, $legendSprite, $borderStyle, $borderThickness)
6363
!endprocedure
6464

65-
!unquoted procedure UpdateEnterpriseBoundaryStyle($bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontColor=$ENTERPRISE_BOUNDARY_COLOR, $borderColor=$ENTERPRISE_BOUNDARY_COLOR, $shadowing="", $shape="", $type="Enterprise", $legendText="", $borderStyle="", $borderThickness="")
66-
UpdateBoundaryStyle("enterprise", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $type, $legendText, $borderStyle, $borderThickness)
65+
!unquoted procedure UpdateEnterpriseBoundaryStyle($bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontColor=$ENTERPRISE_BOUNDARY_COLOR, $borderColor=$ENTERPRISE_BOUNDARY_COLOR, $shadowing="", $shape="", $type="Enterprise", $legendText="", $borderStyle="", $borderThickness="", $sprite="", $legendSprite="")
66+
UpdateBoundaryStyle("enterprise", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $type, $legendText, $borderStyle, $borderThickness, $sprite, $legendSprite)
6767
!endprocedure
68-
!unquoted procedure UpdateSystemBoundaryStyle($bgColor=$SYSTEM_BOUNDARY_BG_COLOR, $fontColor=$SYSTEM_BOUNDARY_COLOR, $borderColor=$SYSTEM_BOUNDARY_COLOR, $shadowing="", $shape="", $type="System", $legendText="", $borderStyle="", $borderThickness="")
69-
UpdateBoundaryStyle("system", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $type, $legendText, $borderStyle, $borderThickness)
68+
!unquoted procedure UpdateSystemBoundaryStyle($bgColor=$SYSTEM_BOUNDARY_BG_COLOR, $fontColor=$SYSTEM_BOUNDARY_COLOR, $borderColor=$SYSTEM_BOUNDARY_COLOR, $shadowing="", $shape="", $type="System", $legendText="", $borderStyle="", $borderThickness="", $sprite="", $legendSprite="")
69+
UpdateBoundaryStyle("system", $bgColor, $fontColor, $borderColor, $shadowing, $shape, $type, $legendText, $borderStyle, $borderThickness, $sprite, $legendSprite)
7070
!endprocedure
7171

7272
' Sprites

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,13 @@ Additional tags/stereotypes can be added to the existing element stereotypes (co
600600
Introduces a new element tag. The styles of the tagged elements are updated and the tag is displayed in the calculated legend.
601601
- `AddRelTag(tagStereo, ?textColor, ?lineColor, ?lineStyle, ?sprite, ?techn, ?legendText, ?legendSprite, ?lineThickness)`:
602602
Introduces a new Relationship tag. The styles of the tagged relationships are updated and the tag is displayed in the calculated legend.
603-
- `AddBoundaryTag(tagStereo, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?borderStyle, ?borderThickness)`:
603+
- `AddBoundaryTag(tagStereo, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?borderStyle, ?borderThickness, ?sprite, ?legendSprite)`:
604604
Introduces a new Boundary tag. The styles of the tagged boundaries are updated and the tag is displayed in the calculated legend.
605605
- `UpdateElementStyle(elementName, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?sprite, ?techn, ?legendText, ?legendSprite, ?borderStyle, ?borderThickness)`:
606606
This call updates the default style of the elements (component, ...) and creates no additional legend entry.
607607
- `UpdateRelStyle(textColor, lineColor)`:
608608
This call updates the default relationship colors and creates no additional legend entry.
609-
- `UpdateBoundaryStyle(?elementName, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness)`:
609+
- `UpdateBoundaryStyle(?elementName, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?sprite, ?legendSprite)`:
610610
This call updates the default style of the existing boundaries and creates no additional legend entry.
611611
If the element name is "" then it updates generic, enterprise, system and container boundary style in on call.
612612
- `RoundedBoxShape()`: This call returns the name of the rounded box shape and can be used as ?shape argument.
@@ -650,9 +650,9 @@ Following calls introduces new element tags with element specific default colors
650650

651651
Like the element specific tag definitions exist boundary specific calls with their default colors **and type**:
652652

653-
- `UpdateContainerBoundaryStyle(?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness)`
654-
- `UpdateSystemBoundaryStyle(?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness)`
655-
- `UpdateEnterpriseBoundaryStyle(?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness)`
653+
- `UpdateContainerBoundaryStyle(?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?sprite, ?legendSprite)`
654+
- `UpdateSystemBoundaryStyle(?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?sprite, ?legendSprite)`
655+
- `UpdateEnterpriseBoundaryStyle(?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?sprite, ?legendSprite)`
656656

657657
### Comments
658658

percy/TestBoundaryTagSupport.puml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml
77
!endif
88

9-
UpdateBoundaryStyle($bgColor="gold", $fontColor="brown", $borderColor="brown")
9+
UpdateBoundaryStyle($bgColor="gold", $fontColor="brown", $borderColor="brown", $sprite="person,scale=1", $legendSprite="person2,scale=0.5")
1010
' re-set $bgColor avoids '(no back color)' in legend
11-
UpdateSystemBoundaryStyle($bgColor="gold", $fontColor="white", $borderColor="white")
11+
UpdateSystemBoundaryStyle($bgColor="gold", $fontColor="white", $borderColor="white", $sprite=robot, $legendSprite="robot2")
1212

13-
AddBoundaryTag("specialSystem", $bgColor="green", $fontColor="white", $borderColor="blue", $shadowing="true", $shape = RoundedBoxShape(), $type="A SPECIAL SYSTEM BOUNDARY")
13+
AddBoundaryTag("specialSystem", $bgColor="green", $fontColor="white", $borderColor="blue", $shadowing="true", $shape = RoundedBoxShape(), $type="A SPECIAL SYSTEM BOUNDARY", $sprite="robot,scale=0.5,color=black", $legendSprite="robot2,scale=0.3,color=black")
1414
AddBoundaryTag("existingContainersBoundary", $bgColor="red", $fontColor="white", $borderColor="white", $type="Existing CONTAINER BOUNDARY", $legendText="container boundary with existing components")
1515

1616
System_Boundary(sb, "A System Boundary") {

0 commit comments

Comments
 (0)