Skip to content

Commit 279a21d

Browse files
authored
Merge pull request #401 from kirchsth/feature/400_new_style
#400 support new visual style for C4 diagrams with `!NEW_C4_STYLE=1`
2 parents de66183 + 8999a31 commit 279a21d

23 files changed

+243
-44
lines changed

C4.puml

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
' C4-PlantUML
2-
2+
33
' Global pre-settings
44
' ##################################
5+
' NEW_C4_STYLE
6+
' If NEW_C4_STYLE is set BEFORE the first C4_* file is loaded, new C4 layout style is used
7+
' NEW_C4_STYLE can be set via
8+
' !NEW_C4_STYLE = 1
9+
' or with additional command line argument -DNEW_C4_STYLE=1
10+
!global NEW_C4_STYLE ?= 0
11+
512
' ENABLE_ALL_PLANT_ELEMENTS
613
' If ENABLE_ALL_PLANT_ELEMENTS is set BEFORE the first C4_* file is loaded, nearly "all" PlantUML elements can be used like
714
' Component(StorageA, "Storage A ", $baseShape="storage")
815
' ENABLE_ALL_PLANT_ELEMENTS can be set via
916
' !ENABLE_ALL_PLANT_ELEMENTS = 1
1017
' or with additional command line argument -DENABLE_ALL_PLANT_ELEMENTS=1
1118

19+
' NO_LAY_ROTATE
1220
' C4-PlantUML v2.12 fixed a missing rotation bug in Lay_* calls in combination with LAYOUT_LANDSCAPE() call
1321
' (details see https://github.com/plantuml-stdlib/C4-PlantUML/issues/376)
1422
' If older diagrams should remain unchanged the bugfix can be deactivated with following statement
@@ -73,6 +81,7 @@ rectangle C4VersionDetailsArea <<legendArea>> [
7381
!$LEGEND_NO_FONT_TEXT ?= "last text color"
7482
!$LEGEND_NO_BG_TEXT ?= "last back color"
7583
!$LEGEND_NO_LINE_TEXT ?= "last line color"
84+
!$LEGEND_SHARP_CORNER ?= "box"
7685
!$LEGEND_ROUNDED_BOX ?= "rounded box"
7786
!$LEGEND_EIGHT_SIDED ?= "eight sided"
7887
!$LEGEND_DOTTED_LINE ?= "dotted"
@@ -129,8 +138,14 @@ rectangle C4VersionDetailsArea <<legendArea>> [
129138
' internal
130139
' ##################################
131140

141+
!global $SHARP_CORNER = "sharpCorner"
132142
!global $ROUNDED_BOX = "roundedBox"
133143
!global $EIGHT_SIDED = "eightSided"
144+
!if (NEW_C4_STYLE == 1)
145+
!$DEFAULT_SHAPE ?= $ROUNDED_BOX
146+
!else
147+
!$DEFAULT_SHAPE ?= $SHARP_CORNER
148+
!endif
134149

135150
!global $DOTTED_LINE = "dotted"
136151
!global $DASHED_LINE = "dashed"
@@ -445,7 +460,10 @@ skinparam package {
445460
!endif
446461
' only rectangle supports shape(d corners), define both skinparam that overlays are working
447462
!if ($shape != "" && $element == "rectangle")
448-
!if ($shape == $ROUNDED_BOX)
463+
!if ($shape == $SHARP_CORNER)
464+
!$elementSkin = $elementSkin + " RoundCorner " + "0" + $bl()
465+
!$elementSkin = $elementSkin + " DiagonalCorner " + "0" + $bl()
466+
!elseif ($shape == $ROUNDED_BOX)
449467
!$elementSkin = $elementSkin + " RoundCorner " + $ROUNDED_BOX_SIZE+ $bl()
450468
!$elementSkin = $elementSkin + " DiagonalCorner " + "0" + $bl()
451469
!elseif ($shape == $EIGHT_SIDED)
@@ -744,10 +762,13 @@ $elementSkin
744762
!if ($shadowing == "false")
745763
!$tagDetails = $tagDetails + $LEGEND_NO_SHADOW_TEXT + ", "
746764
!endif
747-
!if ($shape == $ROUNDED_BOX)
765+
!if ($shape == $SHARP_CORNER && $shape != $DEFAULT_SHAPE)
766+
!$tagDetails = $tagDetails + $LEGEND_SHARP_CORNER + ", "
767+
!endif
768+
!if ($shape == $ROUNDED_BOX && $shape != $DEFAULT_SHAPE)
748769
!$tagDetails = $tagDetails + $LEGEND_ROUNDED_BOX + ", "
749770
!endif
750-
!if ($shape == $EIGHT_SIDED)
771+
!if ($shape == $EIGHT_SIDED && $shape != $DEFAULT_SHAPE)
751772
!$tagDetails = $tagDetails + $LEGEND_EIGHT_SIDED + ", "
752773
!endif
753774
!if ($fontColor == "" && $bgColor == "")
@@ -940,6 +961,11 @@ $line
940961
!endif
941962
!endprocedure
942963

964+
' normal rectangle
965+
!function SharpCornerShape()
966+
!return $SHARP_CORNER
967+
!endfunction
968+
943969
!function RoundedBoxShape()
944970
!return $ROUNDED_BOX
945971
!endfunction
@@ -966,6 +992,14 @@ $line
966992

967993
' used by new defined tags
968994
!unquoted procedure AddElementTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $sprite="", $techn="", $legendText="", $legendSprite="", $borderStyle="", $borderThickness="")
995+
996+
!if (NEW_C4_STYLE == 1)
997+
!$swap=$bgColor
998+
!$bgColor=$fontColor
999+
!$fontColor=$swap
1000+
!$borderColor=$swap
1001+
!endif
1002+
9691003
$defineSkinparams($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $borderStyle, $borderThickness)
9701004
!if ($sprite!="")
9711005
%set_variable_value("$" + $tagStereo + "ElementTagSprite", $sprite)
@@ -980,6 +1014,15 @@ $addTagToLegend($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $sha
9801014
!endprocedure
9811015

9821016
!unquoted procedure $addElementTagInclReuse($elementName, $tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $sprite="", $techn="", $legendText="", $legendSprite="", $borderStyle="", $borderThickness="")
1017+
1018+
'stored tags are already swapped (swap before comparing)
1019+
!if (NEW_C4_STYLE == 1)
1020+
!$swap=$bgColor
1021+
!$bgColor=$fontColor
1022+
!$fontColor=$swap
1023+
!$borderColor=$swap
1024+
!endif
1025+
9831026
!$bgColor=$restoreEmpty($elementName, "bgColor", $bgColor, %false())
9841027
!$fontColor=$restoreEmpty($elementName, "fontColor", $fontColor, %false())
9851028
!$borderColor=$restoreEmpty($elementName, "borderColor", $borderColor, %false())
@@ -993,6 +1036,14 @@ $addTagToLegend($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $sha
9931036
!$borderStyle=$restoreEmpty($elementName, "borderStyle", $borderStyle, %false())
9941037
!$borderThickness=$restoreEmpty($elementName, "borderThickness", $borderThickness, %false())
9951038

1039+
' swap back
1040+
!if (NEW_C4_STYLE == 1)
1041+
!$swap=$bgColor
1042+
!$bgColor=$fontColor
1043+
!$fontColor=$swap
1044+
!$borderColor=$swap
1045+
!endif
1046+
9961047
AddElementTag($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $techn, $legendText, $legendSprite, $borderStyle, $borderThickness)
9971048
!endprocedure
9981049

@@ -1014,6 +1065,14 @@ $addRelTagToLegend($tagStereo, $textColor, $lineColor, $lineStyle, $legendText,
10141065

10151066
' update the style of existing elements like person, ...
10161067
!unquoted procedure UpdateElementStyle($elementName, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $sprite="", $techn="", $legendText="", $legendSprite="", $borderStyle="", $borderThickness="")
1068+
1069+
!if (NEW_C4_STYLE == 1)
1070+
!$swap=$bgColor
1071+
!$bgColor=$fontColor
1072+
!$fontColor=$swap
1073+
!$borderColor=$swap
1074+
!endif
1075+
10171076
!$bgColor=$restoreEmpty($elementName, "bgColor", $bgColor, %true())
10181077
!$fontColor=$restoreEmpty($elementName, "fontColor", $fontColor, %true())
10191078
!$borderColor=$restoreEmpty($elementName, "borderColor", $borderColor, %true())
@@ -1534,6 +1593,14 @@ $getLegendArea($alias, $hideStereotype, $details)
15341593
' ##################################
15351594

15361595
!unquoted procedure UpdateBoundaryStyle($elementName="", $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $type="", $legendText="", $borderStyle="", $borderThickness="", $sprite="", $legendSprite="")
1596+
1597+
!if (NEW_C4_STYLE == 1)
1598+
!$swap=$bgColor
1599+
!$bgColor=$fontColor
1600+
!$fontColor=$swap
1601+
!$borderColor=$swap
1602+
!endif
1603+
15371604
!if ($elementName != "")
15381605
!$elementBoundary = $elementName + '_boundary'
15391606
UpdateElementStyle($elementBoundary, $bgColor, $fontColor, $borderColor, $shadowing, $shape, $sprite, $type, $legendText, $legendSprite, $borderStyle, $borderThickness)

C4_Component.puml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
' Styling
3232
' ##################################
3333

34-
UpdateElementStyle("component", $COMPONENT_BG_COLOR, $COMPONENT_FONT_COLOR, $COMPONENT_BORDER_COLOR, $legendText="$COMPONENT_LEGEND_TEXT")
35-
UpdateElementStyle("external_component", $EXTERNAL_COMPONENT_BG_COLOR, $EXTERNAL_COMPONENT_FONT_COLOR, $EXTERNAL_COMPONENT_BORDER_COLOR, $legendText="$EXTERNAL_COMPONENT_LEGEND_TEXT")
34+
UpdateElementStyle("component", $COMPONENT_BG_COLOR, $COMPONENT_FONT_COLOR, $COMPONENT_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$COMPONENT_LEGEND_TEXT")
35+
UpdateElementStyle("external_component", $EXTERNAL_COMPONENT_BG_COLOR, $EXTERNAL_COMPONENT_FONT_COLOR, $EXTERNAL_COMPONENT_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$EXTERNAL_COMPONENT_LEGEND_TEXT")
3636

3737
' shortcuts with default colors
3838
!unquoted procedure AddComponentTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $sprite="", $techn="", $legendText="", $legendSprite="", $borderStyle="", $borderThickness="")

C4_Container.puml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535

3636
' Styling
3737
' ##################################
38-
UpdateElementStyle("container", $CONTAINER_BG_COLOR, $CONTAINER_FONT_COLOR, $CONTAINER_BORDER_COLOR, $legendText="$CONTAINER_LEGEND_TEXT")
39-
UpdateElementStyle("external_container", $EXTERNAL_CONTAINER_BG_COLOR, $EXTERNAL_CONTAINER_FONT_COLOR, $EXTERNAL_CONTAINER_BORDER_COLOR, $legendText="$EXTERNAL_CONTAINER_LEGEND_TEXT")
38+
UpdateElementStyle("container", $CONTAINER_BG_COLOR, $CONTAINER_FONT_COLOR, $CONTAINER_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$CONTAINER_LEGEND_TEXT")
39+
UpdateElementStyle("external_container", $EXTERNAL_CONTAINER_BG_COLOR, $EXTERNAL_CONTAINER_FONT_COLOR, $EXTERNAL_CONTAINER_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$EXTERNAL_CONTAINER_LEGEND_TEXT")
4040

41-
UpdateBoundaryStyle("container", $bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontColor=$CONTAINER_BOUNDARY_COLOR, $borderColor=$CONTAINER_BOUNDARY_COLOR, $type="$CONTAINER_BOUNDARY_TYPE", $legendText="$CONTAINER_BOUNDARY_LEGEND_TEXT")
41+
UpdateBoundaryStyle("container", $bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontColor=$CONTAINER_BOUNDARY_COLOR, $borderColor=$CONTAINER_BOUNDARY_COLOR, $type="$CONTAINER_BOUNDARY_TYPE", $shape=$DEFAULT_SHAPE, $legendText="$CONTAINER_BOUNDARY_LEGEND_TEXT")
4242

4343
' shortcuts with default colors
4444
!unquoted procedure AddContainerTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $sprite="", $techn="", $legendText="", $legendSprite="", $borderStyle="", $borderThickness="")

C4_Context.puml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
' Styling
5555
' ##################################
5656

57-
UpdateElementStyle("person", $PERSON_BG_COLOR, $PERSON_FONT_COLOR, $PERSON_BORDER_COLOR, $legendText="$PERSON_LEGEND_TEXT")
58-
UpdateElementStyle("external_person", $EXTERNAL_PERSON_BG_COLOR, $EXTERNAL_PERSON_FONT_COLOR, $EXTERNAL_PERSON_BORDER_COLOR, $legendText="$EXTERNAL_PERSON_LEGEND_TEXT")
59-
UpdateElementStyle("system", $SYSTEM_BG_COLOR, $SYSTEM_FONT_COLOR, $SYSTEM_BORDER_COLOR, $legendText="$SYSTEM_LEGEND_TEXT")
60-
UpdateElementStyle("external_system", $EXTERNAL_SYSTEM_BG_COLOR, $EXTERNAL_SYSTEM_FONT_COLOR, $EXTERNAL_SYSTEM_BORDER_COLOR, $legendText="$EXTERNAL_SYSTEM_LEGEND_TEXT")
57+
UpdateElementStyle("person", $PERSON_BG_COLOR, $PERSON_FONT_COLOR, $PERSON_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$PERSON_LEGEND_TEXT")
58+
UpdateElementStyle("external_person", $EXTERNAL_PERSON_BG_COLOR, $EXTERNAL_PERSON_FONT_COLOR, $EXTERNAL_PERSON_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$EXTERNAL_PERSON_LEGEND_TEXT")
59+
UpdateElementStyle("system", $SYSTEM_BG_COLOR, $SYSTEM_FONT_COLOR, $SYSTEM_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$SYSTEM_LEGEND_TEXT")
60+
UpdateElementStyle("external_system", $EXTERNAL_SYSTEM_BG_COLOR, $EXTERNAL_SYSTEM_FONT_COLOR, $EXTERNAL_SYSTEM_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$EXTERNAL_SYSTEM_LEGEND_TEXT")
6161

62-
UpdateBoundaryStyle("system", $bgColor=$SYSTEM_BOUNDARY_BG_COLOR, $fontColor=$SYSTEM_BOUNDARY_COLOR, $borderColor=$SYSTEM_BOUNDARY_COLOR, $type="$SYSTEM_BOUNDARY_TYPE", $legendText="$SYSTEM_BOUNDARY_LEGEND_TEXT")
63-
UpdateBoundaryStyle("enterprise", $bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontColor=$ENTERPRISE_BOUNDARY_COLOR, $borderColor=$ENTERPRISE_BOUNDARY_COLOR, $type="$ENTERPRISE_BOUNDARY_TYPE", $legendText="$ENTERPRISE_BOUNDARY_LEGEND_TEXT")
62+
UpdateBoundaryStyle("system", $bgColor=$SYSTEM_BOUNDARY_BG_COLOR, $fontColor=$SYSTEM_BOUNDARY_COLOR, $borderColor=$SYSTEM_BOUNDARY_COLOR, $type="$SYSTEM_BOUNDARY_TYPE", $shape=$DEFAULT_SHAPE, $legendText="$SYSTEM_BOUNDARY_LEGEND_TEXT")
63+
UpdateBoundaryStyle("enterprise", $bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontColor=$ENTERPRISE_BOUNDARY_COLOR, $borderColor=$ENTERPRISE_BOUNDARY_COLOR, $type="$ENTERPRISE_BOUNDARY_TYPE", $shape=$DEFAULT_SHAPE, $legendText="$ENTERPRISE_BOUNDARY_LEGEND_TEXT")
6464

6565
' shortcuts with default colors
6666
!unquoted procedure AddPersonTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="", $sprite="", $legendText="", $legendSprite="", $type="", $borderStyle="", $borderThickness="")

C4_Deployment.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
!$NODE_TYPE_MAX_CHAR_WIDTH ?= 35
2828
!$NODE_DESCR_MAX_CHAR_WIDTH ?= 32
2929

30-
UpdateElementStyle("node", $bgColor=$NODE_BG_COLOR, $fontColor=$NODE_FONT_COLOR, $borderColor=$NODE_BORDER_COLOR, $legendText="$NODE_LEGEND_TEXT")
30+
UpdateElementStyle("node", $bgColor=$NODE_BG_COLOR, $fontColor=$NODE_FONT_COLOR, $borderColor=$NODE_BORDER_COLOR, $shape=$DEFAULT_SHAPE, $legendText="$NODE_LEGEND_TEXT")
3131
skinparam rectangle<<node>> {
3232
FontStyle normal
3333
}

C4_Sequence.puml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
!if ($LEGEND_DASHED_TRANSPARENT_BOUNDARY == "dashed")
3434
!$LEGEND_DASHED_TRANSPARENT_BOUNDARY = ""
3535
!endif
36-
UpdateBoundaryStyle("", $bgColor=$BOUNDARY_BG_COLOR, $fontColor=$BOUNDARY_COLOR, $borderColor=$BOUNDARY_COLOR)
37-
UpdateBoundaryStyle("enterprise", $bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontColor=$ENTERPRISE_BOUNDARY_COLOR, $borderColor=$ENTERPRISE_BOUNDARY_COLOR, $type="$ENTERPRISE_BOUNDARY_TYPE")
38-
UpdateBoundaryStyle("system", $bgColor=$SYSTEM_BOUNDARY_BG_COLOR, $fontColor=$SYSTEM_BOUNDARY_COLOR, $borderColor=$SYSTEM_BOUNDARY_COLOR, $type="$SYSTEM_BOUNDARY_TYPE")
39-
UpdateBoundaryStyle("container", $bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontColor=$CONTAINER_BOUNDARY_COLOR, $borderColor=$CONTAINER_BOUNDARY_COLOR, $type="$CONTAINER_BOUNDARY_TYPE")
36+
UpdateBoundaryStyle("", $bgColor=$BOUNDARY_BG_COLOR, $fontColor=$BOUNDARY_COLOR, $borderColor=$BOUNDARY_COLOR, $shape=$DEFAULT_SHAPE)
37+
UpdateBoundaryStyle("enterprise", $bgColor=$ENTERPRISE_BOUNDARY_BG_COLOR, $fontColor=$ENTERPRISE_BOUNDARY_COLOR, $borderColor=$ENTERPRISE_BOUNDARY_COLOR, $type="$ENTERPRISE_BOUNDARY_TYPE", $shape=$DEFAULT_SHAPE)
38+
UpdateBoundaryStyle("system", $bgColor=$SYSTEM_BOUNDARY_BG_COLOR, $fontColor=$SYSTEM_BOUNDARY_COLOR, $borderColor=$SYSTEM_BOUNDARY_COLOR, $type="$SYSTEM_BOUNDARY_TYPE", $shape=$DEFAULT_SHAPE)
39+
UpdateBoundaryStyle("container", $bgColor=$CONTAINER_BOUNDARY_BG_COLOR, $fontColor=$CONTAINER_BOUNDARY_COLOR, $borderColor=$CONTAINER_BOUNDARY_COLOR, $type="$CONTAINER_BOUNDARY_TYPE", $shape=$DEFAULT_SHAPE)
4040

4141
' Styling and Layout
4242
' ##################################

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ Additional tags/stereotypes can be added to the existing element stereotypes (co
678678
- `UpdateBoundaryStyle(?elementName, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText, ?borderStyle, ?borderThickness, ?sprite, ?legendSprite)`:
679679
This call updates the default style of the existing boundaries and creates no additional legend entry.
680680
If the element name is "" then it updates generic, enterprise, system and container boundary style in on call.
681+
- `SharpCornerShape()`: This call returns the name of the sharp corner shape and can be used as ?shape argument (default).
681682
- `RoundedBoxShape()`: This call returns the name of the rounded box shape and can be used as ?shape argument.
682683
- `EightSidedShape()`: This call returns the name of the eight sided shape and can be used as ?shape argument.
683684
- `DashedLine()`: This call returns the name of the dashed line and can be used as ?lineStyle or ?borderStyle argument.

0 commit comments

Comments
 (0)