Skip to content

Add support for lineThickness in AddRelTag (based on #218, #235) #254

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 6 commits into from
Nov 3, 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
40 changes: 24 additions & 16 deletions C4.puml
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,24 @@ $tagSkin
!return $c
!endfunction

!unquoted procedure $defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle)
!unquoted procedure $defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle, $lineThickness)
!$elementSkin = "skinparam arrow<<" + $tagStereo + ">> {" + %newline()
!$elementSkin = $elementSkin + " Color "
!if ($lineColor != "")
!$elementSkin = $elementSkin + $colorWithoutHash($lineColor)
!endif
!if ($textColor != "")
!$elementSkin = $elementSkin + ";text:" + $colorWithoutHash($textColor)
!if ($lineColor != "") || ($textColor != "") || ($lineStyle != "")
!$elementSkin = $elementSkin + " Color "
!if ($lineColor != "")
!$elementSkin = $elementSkin + $colorWithoutHash($lineColor)
!endif
!if ($textColor != "")
!$elementSkin = $elementSkin + ";text:" + $colorWithoutHash($textColor)
!endif
!if ($lineStyle != "")
!$elementSkin = $elementSkin + ";line." + $lineStyle
!endif
!$elementSkin = $elementSkin + %newline()
!endif
!if ($lineStyle != "")
!$elementSkin = $elementSkin + ";line." + $lineStyle
!if ($lineThickness != "")
!$elementSkin = $elementSkin + " thickness " + $lineThickness + %newline()
!endif
!$elementSkin = $elementSkin + %newline()
!$elementSkin = $elementSkin + "}" + %newline()
$elementSkin
!endprocedure
Expand Down Expand Up @@ -568,7 +573,7 @@ $elementSkin
!return $tagEntry
!endfunction

!function $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite)
!function $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness)
!$tc = $textColor
!$lc = $lineColor

Expand Down Expand Up @@ -613,6 +618,9 @@ $elementSkin
!$tagEntry = $tagEntry + "(" + $lineStyle + ") "
!endif
!endif
!if ($lineThickness != "")
!$tagEntry = $tagEntry + "(thickness " + $lineThickness + ") "
!endif
!else
!$tagEntry = $tagEntry + " " + $legendText + " "
!endif
Expand All @@ -639,15 +647,15 @@ $elementSkin
' !endif
!endprocedure

!unquoted procedure $addRelTagToLegend($tagStereo, $textColor="", $lineColor="", $lineStyle="", $legendText="", $legendSprite="")
!unquoted procedure $addRelTagToLegend($tagStereo, $textColor="", $lineColor="", $lineStyle="", $legendText="", $legendSprite="", $lineThickness="")
'' Arrows have a bug with stereotype/skinparams and cannot combine text colors of one stereotype
'' and the line color of another stereotype. Therefore the text color of one tag and the line color
'' of another tag have to be combined via a "workaround" tag ("v1.0&v1.1").
'' This workaround tag could be theoretically removed in the legend but after that there would
'' 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)
!$tagEntry = $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness)
%set_variable_value("$" + $tagStereo + "_LineLegendEntry", $tagEntry)
!$tagCustomLegend = $tagCustomLegend + $tagStereo + "_Line\n"
' !endif
Expand Down Expand Up @@ -721,8 +729,8 @@ $addTagToLegend($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $sha
!endprocedure

' used by new defined rel tags
!unquoted procedure AddRelTag($tagStereo, $textColor="", $lineColor="", $lineStyle = "", $sprite="", $techn="", $legendText="", $legendSprite="")
$defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle)
!unquoted procedure AddRelTag($tagStereo, $textColor="", $lineColor="", $lineStyle="", $sprite="", $techn="", $legendText="", $legendSprite="", $lineThickness="")
$defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle, $lineThickness)
!if ($sprite != "")
%set_variable_value("$" + $tagStereo + "RelTagSprite", $sprite)
!if ($legendSprite == "")
Expand All @@ -733,7 +741,7 @@ $defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle)
!if ($techn != "")
%set_variable_value("$" + $tagStereo + "RelTagTechn", $techn)
!endif
$addRelTagToLegend($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite)
$addRelTagToLegend($tagStereo, $textColor, $lineColor, $lineStyle, $legendText, $legendSprite, $lineThickness)
!endprocedure

' update the style of existing elements like person, ...
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ Additional tags/stereotypes can be added to the existing element stereotypes (co

* `AddElementTag(tagStereo, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?sprite, ?techn, ?legendText, ?legendSprite)`:
Introduces a new element tag. The styles of the tagged elements are updated and the tag is displayed in the calculated legend.
* `AddRelTag(tagStereo, ?textColor, ?lineColor, ?lineStyle, ?sprite, ?techn, ?legendText, ?legendSprite)`:
* `AddRelTag(tagStereo, ?textColor, ?lineColor, ?lineStyle, ?sprite, ?techn, ?legendText, ?legendSprite, ?lineThickness)`:
Introduces a new Relationship tag. The styles of the tagged relationships are updated and the tag is displayed in the calculated legend.
* `AddBoundaryTag(tagStereo, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape, ?type, ?legendText)`:
Introduces a new Boundary tag. The styles of the tagged boundaries are updated and the tag is displayed in the calculated legend.
Expand Down Expand Up @@ -549,16 +549,16 @@ Like the element specific tag definitions exist boundary specific calls with the

### Comments

* `SHOW_LEGEND()` supports the customized stereotypes
(`LAYOUT_WITH_LEGEND()` cannot be used, if the custom tags/stereotypes should be displayed in the legend).
* `SHOW_LEGEND()` supports the customized stereotypes
(`LAYOUT_WITH_LEGEND()` cannot be used, if the custom tags/stereotypes should be displayed in the legend).
* `SHOW_LEGEND()` has to be last line in diagram.
* Don't use space between `$tags` and `=` (PlantUML does not support it).
* Don't use `,` as part of the tag names (PlantUML does not support it in combination with keyword arguments).
* If 2 tags define the same skinparam, the first definition is used.
* If specific skinparams have to be merged (e.g. 2 tags change the font color) an additional combined tag has to be defined. Use `&` as part of combined tag names.

* Colors of relationship tags cannot be automatically merged (PlantUML does not support it).
If one tag modifies the line color and the other the text color, an additional combined tag has to be defined and used.
* Automatically merging colors of relationship tags is not supported in PlantUML before v.1.2022
If an older version is used and one tag modifies the line color and the other the text color, an additional combined tag has to be defined and used.

### Sample with different tag combinations

Expand Down
7 changes: 4 additions & 3 deletions percy/TestLegend.puml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ AddRelTag("line1", $lineColor="green", $textColor="blue")
AddRelTag("line2", $lineColor="blue", $textColor="green")
AddRelTag("line3", $textColor="orange")
AddRelTag("line4", $lineColor="orange")
' PlantUML cannot combine line styles, a combination has to be added as workaround as first additional tag
' outdated: PlantUML cannot combine line styles, a combination has to be added as workaround as first additional tag
' fixed in meantime
AddRelTag("line3&line4", $lineColor="orange", $textColor="orange")
AddRelTag("unusedLine", $lineColor="red", $textColor="red")

Expand All @@ -57,8 +58,8 @@ Rel(allInOne, component, "uses line 1", $tags="line1")
Rel(allInOne, component, "uses line 2", $tags="line2")
Rel(allInOne, system1A, "uses line 3", $tags="line3")
Rel(allInOne, system1A, "uses line 4", $tags="line4")
Rel(allInOne, system2, "line 3+4 cannot be combined without workaround", $tags="line3+line4")
Rel(allInOne, system2, "line 3+4 with workaround", $tags="line3&line4+line3+line4")
Rel(allInOne, system2, "line 3+4 (merge fixed in meantime)", $tags="line3+line4")
Rel(allInOne, system2, "line 3+4 with workaround (obsolete in meantime)", $tags="line3&line4+line3+line4")

SHOW_LEGEND(false)
@enduml
43 changes: 43 additions & 0 deletions percy/TestRelationsTags.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@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
!else
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml
!endif

UpdateRelStyle(gray, gray)

AddRelTag("textColorBlue", $textColor=blue)
AddRelTag("textColorRed", $textColor="red")
AddRelTag("lineColorBlue", $lineColor="blue")
AddRelTag("lineStyleDashed", $lineStyle=DashedLine())
AddRelTag("lineStyleDotted", $lineStyle=DottedLine())
AddRelTag("lineStyleBold", $lineStyle=BoldLine())
AddRelTag("lineThickness", $lineThickness=5)
AddRelTag("bothSprites", $sprite="person2", $legendSprite="person2,scale=0.25")
AddRelTag("technAndLegendText", $techn="HTTPS", $legendText="Another text in legend (incl. techn. https)")

Person(person, "Person")

System(system1, "System 1")
System(system2, "System 2")
System(system3, "System 3")
System(system4, "System 3")

Rel_U(person, system1, "without a tag")
Rel_U(person, system1, "bothSprites", $tags="bothSprites")
Rel_U(person, system1, "technAndLegendText", $tags="technAndLegendText")
Rel_R(person, system2, "textColorBlue", $tags="textColorBlue")
Rel_R(person, system2, "lineColorBlue", $tags="lineColorBlue")
Rel_R(person, system2, "textColorRed+lineColorBlue", $tags="textColorRed+lineColorBlue")
Rel_R(person, system2, "textColorRed+textColorBlue (first wins)", $tags="textColorRed+textColorBlue")
Rel_D(person, system3, "lineStyleDashed", $tags="lineStyleDashed")
Rel_D(person, system3, "lineStyleDotted", $tags="lineStyleDotted")
Rel_D(person, system3, "lineStyleBold", $tags="lineStyleBold")
Rel_D(person, system3, "lineStyleDotted+lineThickness", $tags="lineStyleDotted+lineThickness")
Rel_L(person, system4, "textColorBlue+textColorRed+lineColorBlue+lineStyleDashed+lineThickness+bothSprites", $tags="textColorBlue+textColorRed+lineColorBlue+lineStyleDashed+lineThickness+bothSprites")
Rel_L(person, system4, "textColorBlue+textColorRed+lineColorBlue+lineStyleDashed+lineThickness+bothSprites+technAndLegendText", $tags="textColorBlue+textColorRed+lineColorBlue+lineStyleDashed+lineThickness+bothSprites+technAndLegendText")

SHOW_LEGEND()
@enduml