packageumlplantuml

Plantuml - Rearrangement of components and packages


I try to arrange the components and packages as shown on the first screenshot. Is there any chance to do it like this (Screenshot 1) enter image description here

Please find my current approach here (Screenshot 2)

enter image description here

And uml script here:

@startuml
package "packageA" {
  [componentA]
}

package "packageB" {
  [componentB1] - [componentB2]
  [componentB2]
}

package "packageC" {
  [componentC1] - [componentC2]
  [componentC2]
}

package "packageD" {
  [componentD]
}



componentA --> componentB1
componentA --> componentC1
componentB2 -right-> [componentD]
componentC2 -right-> [componentD]

@enduml

Solution

  • With the left to right orientation, and leaving out the explicit orientation in the package, you can get roughly what you want:

    @startuml
    left to right direction
    
    skinparam package {
        backgroundColor Gray
    }
    skinparam component {
        backgroundColor Gold
    }
    
    package "packageA" {
      [componentA]
    }
    package "packageB" {
      [componentB1] -- [componentB2]
    }
    package "packageC" {
      [componentC1] -- [componentC2]
    }
    package "packageD" {
      [componentD]
    }
    
    componentA --> componentB1
    componentA --> componentC1
    componentB2 --> [componentD]
    componentC2 --> [componentD]
    @enduml
    

    package diagram with gray packages and gold components, aligned horizontally, but stacking multi-component packages vertically

    The vertical alignment it not easy to control. I believe the problem comes from the link between components whereas there are probably some attempt to align the packages.

    An alignment from top to bottom gives better centering in this regard. What can also help in some cases is to add also some -[hidden]-> links which seem to be taken into account in alignment/centering as well, but in this rather flat situation it doesn't change much.

    Demo