Align packages vertically in PlantUML

Viewed 2749

I have a class structure of something like this:

@startuml
package "A" {
ABase <|-- A1
ABase <|-- A2
ABase <|-- A3
}
package "B" {
BBase <|-- B1
BBase <|-- B2
BBase <|-- B3
}
package "C" {
CBase <|-- C1
CBase <|-- C2
CBase <|-- C3
}
@enduml

Result of PlantUML

PlantUML renders the packages next to each other. This can get way too wide if class names are longer, or there are more subclasses, as the subclasses are always put next to each other. Is there any way to make the packages be aligned vertically?

I tried using left to right direction, which is an improvement, but has its own problems. I'd want a top to bottom direction for each package, but the packages should be below each other.

3 Answers

Many vertically challenged diagrams and what feels like hours of horizontal scrolling have made me ask the same question as you. Alas, the only admittedly unsustainable workaround that I have found so far is to create vertical helper links between the classes. That is fine for small diagrams but as I said, I would not call it sustainable as your diagram grows.

@startuml

package "A" {
ABase <|-- A1
ABase <|-- A2
ABase <|-- A3
}
package "B" {
BBase <|-- B1
BBase <|-- B2
BBase <|-- B3
}
package "C" {
CBase <|-- C1
CBase <|-- C2
CBase <|-- C3
}

A2 -[hidden]down- BBase
B2 -[hidden]down- CBase

@enduml

I tested with this code and maybe what you want to achieve.

@startuml
package Main{
}
package A{
}
Main -- A /'Main above A in vertical'/
A -- Main /'A above Main in vertical '/
Main - A  /'same as position of code'/
A - Main /'same as position of code'/
@enduml

Probably not the solution you want, but newpage after each package will make them appear on separate pages (you'd need a GUI that supports multipage diagrams such as PlantUML for VSCode). Could be useful if you're combining the images in a single document.

@startuml
package "A" {
ABase <|-- A1
ABase <|-- A2
ABase <|-- A3
}
newpage
package "B" {
BBase <|-- B1
BBase <|-- B2
BBase <|-- B3
}
newpage
package "C" {
CBase <|-- C1
CBase <|-- C2
CBase <|-- C3
}
@enduml

package A

package B

package C

Related