Skip to content
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

Set padding for elements inside a boundary #299

Closed
skngetich opened this issue Apr 11, 2023 · 4 comments
Closed

Set padding for elements inside a boundary #299

skngetich opened this issue Apr 11, 2023 · 4 comments

Comments

@skngetich
Copy link

I would like to change the padding of the elements in a boundary. How can I do that?

@Potherca
Copy link
Member

Hi! To make it easier to help, could you post a (simplified) diagram, so we have an example to work with?

@Potherca
Copy link
Member

Potherca commented Apr 14, 2023

In the meantime, I've looked into this some more. Sadly, PlantUML does not offer an easy way to add spacing inside an element.

TL;DR (short version)

Use a dummy container inside the boundary as a workaround.

@startuml
!include <C4/C4_Container>

skinparam {
  rectangle<<DUMMY>> {
    borderColor transparent
    stereotypeFontSize 0
    fontSize 0
  }
}

Boundary(b, "Boundary") {
  rectangle padding <<DUMMY>> {
    Container(c, "Container")
    Person(p, "Person")
    System(s, "System") 
    Boundary(b1, "Boundary")
  }
}
@enduml

Full details

I'll use this diagram as the basis for further examples:

@startuml
!include <C4/C4_Container>

Boundary(b, "Boundary") {
    Container(c, "Container")
    Person(p, "Person")
    System(s, "System") 
    Boundary(b1, "Boundary")
}
@enduml

See full details

No skinparam "margin" or "padding"

Sadly, there is no skinparam for "margin" or "padding":

@startuml
!include <C4/C4_Container>

skinparam rectangle<<boundary>> {
   margin 100 100 100 100
   padding 100 100 100 100
}

Boundary(b, "Boundary") {
    Container(c, "Container")
    Person(p, "Person")
    System(s, "System") 
    Boundary(b1, "Boundary")
}
@enduml

Skinparam nodesep and ranksep

There is skinparam nodesep and ranksep which can be used to increase the space between elements but not around them. That is to say: the space between an element and the boundary does not change.

@startuml
!include <C4/C4_Container>

skinparam nodesep 100 /' horizontal margin '/
skinparam ranksep 100 /' vertical margin '/

Boundary(b, "Boundary") {
    Container(c, "Container")
    Person(p, "Person")
    System(s, "System") 
    Boundary(b1, "Boundary")
}
@enduml

Padding and Margin (new CSS-like style) not working

There are padding and margin instruction using the new CSS-like style, but they do not seem to be implemented for the elements used by C4. This could be a bug in PlantUML and might be worth reporting there.

@startuml
!include <C4/C4_Container>

<style>
  root {
    BackgroundColor #FFE
    Margin 100
    Padding 100
  }

  rectangle {
    Margin 100
    Padding 100
  }

  .boundary {
    Margin 100
    Padding 100
  }
</style>

Boundary(b, "Boundary") {
    Container(c, "Container")
    Person(p, "Person")
    System(s, "System") 
    Boundary(b1, "Boundary")
}
@enduml

Workaround

What could work is a workaround, putting the elements in an invisible container. This does mean adding a container inside every boundary. Not ideal.

@startuml
!include <C4/C4_Container>

skinparam {
  rectangle<<DUMMY>> {
    borderColor transparent
    stereotypeFontSize 0
    fontSize 0
  }
}

Boundary(b, "Boundary") {
  rectangle padding <<DUMMY>> {
    Container(c, "Container")
    Person(p, "Person")
    System(s, "System") 
    Boundary(b1, "Boundary")
  }
}
@enduml

@skngetich
Copy link
Author

Thank you very much for the descriptive description. From your explanations, I have realized that the issue was the margin between the elements and not the padding. I sorted it out using nodesep and ranksep.

@Potherca
Copy link
Member

Glad to be of help. Happy diagramming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants