4

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.

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
petersohn
  • 11,292
  • 13
  • 61
  • 98

3 Answers3

2

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
khalito
  • 971
  • 5
  • 22
  • 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? – albert May 07 '20 at 14:39
  • 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. – khalito May 08 '20 at 07:20
1

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

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
0

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
dellos
  • 327
  • 5
  • 15