Align packages vertically in PlantUML
Asked Answered
H

3

6

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.

Hamo answered 6/5, 2020 at 16:11 Comment(0)
H
7

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
Homomorphism answered 7/5, 2020 at 13:42 Comment(2)
In this case this works but what happens when there will be more complex structures a simple test is to add a class in package B. Is there a way to align the left sides of the packages?Freberg
I don't know any ways to align the packages to one side. As I said, this is a really dirty workaround that you can use once when you are under pressure to deliver something. I would have posted it as a comment instead of a proper answer if possible.Homomorphism
V
4

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

Vaivode answered 18/8, 2022 at 23:59 Comment(0)
P
1

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
Petua answered 8/12, 2021 at 4:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.