C4-PlantUML icon indicating copy to clipboard operation
C4-PlantUML copied to clipboard

Ability to add styles for System_Boundary, Container_Boundary

Open vellala2000 opened this issue 2 years ago • 1 comments

Add support to style System_Boundary, Container_Boundary

vellala2000 avatar Jun 04 '22 17:06 vellala2000

Styling all boundaries

The style of all boundaries can already be changed by using skinparam and the <<boundary>> stereotype:

@startuml
!include <C4/C4_Container>

skinparam rectangle<<boundary>> {
  BackgroundColor #FEFECE
  BorderStyle solid
}

System_Boundary(sb, "System_Boundary") {
  Container_Boundary(cb1, "Container Boundary") {
    Container(c1, "Container")
  }
}
@enduml

Styling individual boundaries

Although it is currently not possible to style individual boundaries as one would for elements (using UpdateElementStyle), it is possible by setting a $tags and changing the skinparam for the tag`s stereotype:

@startuml
!include <C4/C4_Container>

hide stereotype

skinparam rectangle<<boundary>> {
  BackgroundColor #FEFECE
  BorderStyle solid
}

skinparam rectangle<<BOUNDARY_TAG>> {
  backgroundcolor #ABC

  border {
    color green
    style dotted
    thickness 2.5
  }

  Roundcorner 10

  Font { 
    Color red
    Name SansSerif
    Size 14
    Style plain
  }

}

System_Boundary(sb, "System_Boundary") {
  Container_Boundary(cb1, "Container Boundary\nwith tag") {
    Container(c1, "Container")
  }
  Container_Boundary(cb2, "Container_Boundary", $tags='BOUNDARY_TAG') {
    Container(c2, "Container")
  }
}
@enduml

@vellala2000 does this suffice for your usecase, or is there something else you need?

Potherca avatar Aug 10 '22 08:08 Potherca

[Updated] I re-checked the current implementation and UpdateElementStyle("boundary", ...) and AddElementTag() support basically boundaries (incl. legend support). There are only few limitations

  1. no sprites are displayed (node specific, not supported at all)
  2. missing explicit AddBoundaryTag() and UpdateBoundaryStyle() calls; ...Element... calls can be used as workaround
  3. "non-tagged" boundaries are not added to the legend (if it is not updated); possible workaround see in following sample
  4. boundaries in legend are not marked as (dashed, transparent?) (rounded box is an additional style in case of boundaries), $legendText=... can be used as workaround
  5. $techn=... (is $type like System) of the tags is not support, there is no workaround atm
@startuml
!include <C4/C4_Container>

' workaround missing default boundary legend entry - should be part of C4 files -------------------
UpdateElementStyle("boundary", $bgColor=$BOUNDARY_BG_COLOR, $fontColor=$BOUNDARY_COLOR, $borderColor=$BOUNDARY_COLOR)
!$tagDefaultLegend = $tagDefaultLegend + "\nboundary"

' automatic add of ` (dashed, transparent?)` in legend is missing; $legendText=... could be used as workaround
' end of fix -------------------
' missing UpdateBoundaryStyle() and AddBoundaryTag() has to be simulated with ...Element...() calls


UpdateElementStyle("boundary", $bgColor="gold", $fontColor="brown", $borderColor="brown")

AddElementTag("special", $bgColor="green", $fontColor="white", $borderColor="blue", $shadowing="true", $shape = RoundedBoxShape(), $techn="A SPECIAL SYSTEM BOUNDARY", $legendText="special system boundary")

AddElementTag("existingContainersBoundary", $bgColor="red", $fontColor="white", $borderColor="white", $shape = RoundedBoxShape(), $techn="A SPECIAL SYSTEM BOUNDARY", $legendText="existing containers boundary")

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

System_Boundary(sb1, "Special System 1 Boundary", $tags="special") {
  Container_Boundary(cb1, "Container Boundary\nwith tag", $tags="existingContainersBoundary") {
    Container(e1, "existing 1", "xyz")
    Container(e2, "existing 2", "xyz")
  }
  Container_Boundary(cb2, "Container_Boundary") {
    Container(c2, "Container", "xyz")
  }
}

System_Boundary(sb2, "Special System 2 Boundary", $tags="special") { 
}

Lay_R(sb, sb1)
Lay_R(sb1, sb2)

SHOW_LEGEND()
@enduml

I think I could fix missing Add....Tag() and UpdateBoundaryStyle() calls (2) and missing legend entry (3, 4). But I think we should not support sprites at all (1).

@vellala2000 and @Potherca: what do you think? Did I oversee something?

Best regards Helmut

kirchsth avatar Aug 14 '22 22:08 kirchsth

I think I could fix missing Add....Tag() and UpdateBoundaryStyle() calls (2) and missing legend entry (3, 4).

For the sake of consistency (or principle of least surprise, I think that would be a Good Idea:tm:

I think we should not support sprites at all (1).

Agreed.

Did I oversee something?

As usual, I think you got it spot-on.

Potherca avatar Aug 16 '22 09:08 Potherca

Hi @Potherca and @vellala2000 I added a better style support for border tags, can you please review my PR #231 Thank you and best regards Helmut

kirchsth avatar Aug 19 '22 23:08 kirchsth