Skip to content

Commit 34ba2d6

Browse files
authored
Merge pull request #160 from kirchsth/feature/relationLine
#159 Relation tags support line styles
2 parents 5986de1 + 32c482f commit 34ba2d6

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

C4.puml

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
!global $LEGEND_NO_LINE_TEXT = "(no line color) "
2828
!global $LEGEND_ROUNDED_BOX = "(rounded box) "
2929
!global $LEGEND_EIGHT_SIDED = "(eight sided) "
30+
!global $LEGEND_DOTTED_LINE = "(dotted) "
31+
!global $LEGEND_DASHED_LINE = "(dashed) "
32+
!global $LEGEND_BOLD_LINE = "(bold) "
3033

3134
' Styling
3235
' ##################################
@@ -38,6 +41,10 @@
3841
!global $ROUNDED_BOX = "roundedBox"
3942
!global $EIGHT_SIDED = "eightSided"
4043

44+
!global $DOTTED_LINE = "dotted"
45+
!global $DASHED_LINE = "dashed"
46+
!global $BOLD_LINE = "bold"
47+
4148
skinparam defaultTextAlignment center
4249

4350
skinparam wrapWidth 200
@@ -226,7 +233,7 @@ $tagSkin
226233
!return $c
227234
!endfunction
228235

229-
!unquoted procedure $defineRelSkinparams($tagStereo, $textColor, $lineColor)
236+
!unquoted procedure $defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle)
230237
!$elementSkin = "skinparam arrow<<" + $tagStereo + ">> {" + %newline()
231238
!$elementSkin = $elementSkin + " Color "
232239
!if ($lineColor!="")
@@ -235,6 +242,9 @@ $tagSkin
235242
!if ($textColor!="")
236243
!$elementSkin = $elementSkin + ";text:" + $colorWithoutHash($textColor)
237244
!endif
245+
!if ($lineStyle!="")
246+
!$elementSkin = $elementSkin + ";line." + $lineStyle
247+
!endif
238248
!$elementSkin = $elementSkin + %newline()
239249
!$elementSkin = $elementSkin + "}" + %newline()
240250
$elementSkin
@@ -398,7 +408,7 @@ $elementSkin
398408
!return $tagEntry
399409
!endfunction
400410

401-
!function $tagRelLegendEntry($tagStereo, $textColor, $lineColor)
411+
!function $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle)
402412
!$tc = $textColor
403413
!$lc = $lineColor
404414

@@ -428,11 +438,26 @@ $elementSkin
428438
!if ($lineColor == "")
429439
!$tagEntry = $tagEntry + $LEGEND_NO_LINE_TEXT
430440
!endif
441+
!if ($lineStyle != "")
442+
!if ($lineStyle == $DOTTED_LINE)
443+
!$tagEntry = $tagEntry + $LEGEND_DOTTED_LINE
444+
!elseif ($lineStyle == $DASHED_LINE)
445+
!$tagEntry = $tagEntry + $LEGEND_DASHED_LINE
446+
!elseif ($lineStyle == $BOLD_LINE)
447+
!$tagEntry = $tagEntry + $LEGEND_BOLD_LINE
448+
!else
449+
!$tagEntry = $tagEntry + "(" + $lineStyle + ") "
450+
!endif
451+
!endif
431452
!$tagEntry = $tagEntry + "</color> "
432453
!$tagEntry = $tagEntry + "|"
433454
!return $tagEntry
434455
!endfunction
435456

457+
!global $LEGEND_DOTTED_LINE = "(dotted) "
458+
!global $LEGEND_DASHED_LINE = "(dashed) "
459+
!global $LEGEND_BOLD_LINE = "(bold) "
460+
436461
!unquoted procedure $addTagToLegend($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="")
437462
'' if a combined element tag is defined (e.g. "v1.0&v1.1") then it is typically a merged color,
438463
'' like a new $fontColor="#fdae61" therefore it should be added to the legend
@@ -446,15 +471,15 @@ $elementSkin
446471
' !endif
447472
!endprocedure
448473

449-
!unquoted procedure $addRelTagToLegend($tagStereo, $textColor="", $lineColor="")
474+
!unquoted procedure $addRelTagToLegend($tagStereo, $textColor="", $lineColor="", $lineStyle="")
450475
'' Arrows have a bug with stereotype/skinparams and cannot combine text colors of one stereotype
451476
'' and the line color of another stereotype. Therefore the text color of one tag and the line color
452477
'' of another tag have to be combined via a "workaround" tag ("v1.0&v1.1").
453478
'' This workaround tag could be theoretically removed in the legend but after that there would
454479
'' be an inconsistency between the element tags and the rel tags and therefore
455480
'' & combined workaround tags are not removed too (and in unlikely cases the color itself could be changed)
456481
' !if (%strpos($tagStereo, "&")<0)
457-
!$tagEntry = $tagRelLegendEntry($tagStereo, $textColor, $lineColor)
482+
!$tagEntry = $tagRelLegendEntry($tagStereo, $textColor, $lineColor, $lineStyle)
458483
%set_variable_value("$" + $tagStereo + "_LineLegendEntry", $tagEntry)
459484
!$tagCustomLegend = $tagCustomLegend + $tagStereo + "_Line\n"
460485
' !endif
@@ -486,16 +511,28 @@ $elementSkin
486511
!return $EIGHT_SIDED
487512
!endfunction
488513

514+
!function DottedLine()
515+
!return $DOTTED_LINE
516+
!endfunction
517+
518+
!function DashedLine()
519+
!return $DASHED_LINE
520+
!endfunction
521+
522+
!function BoldLine()
523+
!return $BOLD_LINE
524+
!endfunction
525+
489526
' used by new defined tags
490527
!unquoted procedure AddElementTag($tagStereo, $bgColor="", $fontColor="", $borderColor="", $shadowing="", $shape="")
491528
$defineSkinparams($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape)
492529
$addTagToLegend($tagStereo, $bgColor, $fontColor, $borderColor, $shadowing, $shape)
493530
!endprocedure
494531

495532
' used by new defined rel tags
496-
!unquoted procedure AddRelTag($tagStereo, $textColor="", $lineColor="")
497-
$defineRelSkinparams($tagStereo, $textColor, $lineColor)
498-
$addRelTagToLegend($tagStereo, $textColor, $lineColor)
533+
!unquoted procedure AddRelTag($tagStereo, $textColor="", $lineColor="", $lineStyle = "")
534+
$defineRelSkinparams($tagStereo, $textColor, $lineColor, $lineStyle)
535+
$addRelTagToLegend($tagStereo, $textColor, $lineColor, $lineStyle)
499536
!endprocedure
500537

501538
' update the style of existing elements like person, ...

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ AddElementTag("v1.0", $borderColor="#d73027")
132132
AddElementTag("v1.1", $fontColor="#d73027")
133133
AddElementTag("backup", $fontColor="orange")
134134

135-
AddRelTag("backup", $textColor="orange", $lineColor="orange")
135+
AddRelTag("backup", $textColor="orange", $lineColor="orange", $lineStyle = DashedLine())
136136

137137
Person(user, "Customer", "People that need products")
138138
Person(admin, "Administrator", "People that administrates the products via the new v1.1 components", $tags="v1.1")
@@ -153,7 +153,7 @@ SHOW_LEGEND()
153153
@enduml
154154
```
155155

156-
![tags](https://www.plantuml.com/plantuml/png/bLJTJjjC4BtdAVRprukWGWBz4L8b9AA0IgNGfWJ49Hfx9ywswrrhPnpQj--COs884LMlTZLpPiwSsMEV4KFYfl9x_xbG-CQYMJBNz6aqIl0mB1qlcxmXJ4KCZ867HQn6jOUWDOV4rhjyDFbmEDFGxTLqL04n9WdTJwG2NC0qhBN_tjZQ2uyL1hw1Sf2jZeT7sO5vayTaCKsYZ-aq-z-Ul3zwTvBjxq0VAteXJV-6pQ7usTHRw9WWb2XWHL-Ztq8o_jf2Ij2xW2_APvWeXe7kvC1aauOuLfW4diqmrXuDBu5DGBIcJj4s1PEKTLLWAnS4EjRJ4IVW-A8M-YIIX73JoAmSj8603qPNOkGvwXX4ERKgeAJJTbT2kTd_W6eGYlbih4oYe_7Gajv8fqeWnWN6j82Y6q0PYaxOEWTA_Y1cQ2VedgwdEzgc6p_LQNOpmzCT_EC8cmMyeXfgfnFClYZX3rY1dfSGh4SouBqHNmkGoFXOki8Cz0COzgiLHs0W5mFjFnVxTflgF1_ON9gV0qCEX4fqvOeKAIxOpBzFM-ReBJs-v85fNMyWM56tYgv0EHSnLS32-5n7AfPkXQfbVSlqsbZ7EdZfGgc1ESSakZwQtmYfDqDdSJMkcBvpxTeFjuIabUttBW3DjnbPtExq_VLwgQtOQmHBexla6Blqexlxzz_DqQLV8vgkYNhf7O_SAYI24dTAd5z-kxkVNdo--7e-sDyxms3rp_C7 "tags")
156+
![tags](https://www.plantuml.com/plantuml/png/bLJTRjfC4BtFK-pdhnT6JN3I7qMgX1G4gAb4MWg9Sed6ti5ikzwrTjRGl7rdrn08jLBrQj7CcJbppeov8G_EDvK--q-PGZSInThxcZvbcODjlrH-tUGDeIkiyMXylx1LLcimeUQ2lDGgpqOVBcOXz70tpIeWZuv3on5NW3Be-dNeVpQKSgAnuYRtKAR9vgf_cPoBDxbr4jt8Qki6oV_o-ltbk-karu6-2kWLD_qRDeVYPrEVeAq3KoA30tgE-WJfyTS9aeEQf-yCBloJHZ4GOw0roYb7qXvtdg4ZQz9Wrxb8HWrvMw7ZecI6jkOAlmOl3A8KjREoAJmblNqLo4ePXWx3gyWxyFQFMZWaaJY4put4Ha4C6DoAu9RWJTNMi2aK1K99WsWZKpwl9gKQc68n6mOcbjXeYAJttAbYY536erj1qGuG6OgTi3O7WNpBTn8dY5izfhiyfHiUwnJTp73imR-Ei3VW5TLGgp31x4iW_04R2Eyj6AcH16Wj-EGPI2IqBLKXql1jz0_Myh6W8MKDzLwAVNjADSvJcNFpCNZ8WJ0GtQd2MR8hBnRVfv7PQadxJPwB-448deRLRQmgaD-LTHLuPdofmnLhjS6WfVsLX9-DL3uCNYfJXi22JMHT7yKJWZiSm_xw-N3dg7TNszx30o65olXNm82GZnashZkzdBUcHh5p14dPerCUT-dzTH_jlvkZJRz6D6s93j9RdW2ha0XAx9IukFtsk9nEFa--ZjFUsGqQsLJwDm00 "tags")
157157

158158

159159
## Supported Diagram Types
@@ -376,14 +376,17 @@ Additional tags/stereotypes can be added to the existing element stereotypes (co
376376

377377
* `AddElementTag(tagStereo, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape)`:
378378
Introduces a new element tag. The styles of the tagged elements are updated and the tag is displayed in the calculated legend.
379-
* `AddRelTag(tagStereo, ?textColor, ?lineColor)`:
379+
* `AddRelTag(tagStereo, ?textColor, ?lineColor, ?lineStyle)`:
380380
Introduces a new relation tag. The styles of the tagged relations are updated and the tag is displayed in the calculated legend.
381381
* `UpdateElementStyle(elementName, ?bgColor, ?fontColor, ?borderColor, ?shadowing, ?shape)`:
382382
This call updates the default style of the elements (component, ...) and creates no additional legend entry.
383383
* `UpdateRelStyle(textColor, lineColor)`:
384384
This call updates the default relationship colors and creates no additional legend entry.
385385
* `RoundedBoxShape()`: This call returns the name of the rounded box shape and can be used as ?shape argument.
386386
* `EightSidedShape()`: This call returns the name of the eight sided shape and can be used as ?shape argument.
387+
* `DashedLine()`: This call returns the name of the dashed line and can be used as ?lineStyle argument.
388+
* `DottedLine()`: This call returns the name of the dotted line and can be used as ?lineStyle argument.
389+
* `BoldLine()`: This call returns the name of the bold line and can be used as ?lineStyle argument.
387390

388391
Each element can be extended with one or multiple custom tags via the keyword argument `$tags="..."`, like `Container(spaAdmin, "Admin SPA", $tags="v1.1")`.
389392
Multiple tags can be combined with `+`, like `Container(api, "API", $tags="v1.0+v1.1")`.

0 commit comments

Comments
 (0)