How to stack layers of classes

+1 vote
asked Mar 6, 2019 in Question / help by janwilmans (200 points)
In this class diagram, I'd like the 'User' and 'CameraTest' class to be on top of like so:

https://pasteboard.co/I4cUjOP.png

how can I do this?

@startuml

'skinparam classBackgroundColor LightGoldenRodYellow

class User

User - CameraProvider
User - Camera

interface CameraProvider
CameraProvider : std::vector<Camera> GetCameras();

CameraProvider -> Camera

interface Camera
Camera : std::unique_ptr<Image> GetImage();

CameraTest - Camera

together {
  class CameraTest #red
}

.Camera <|-- CameraDummy
.Camera <|-- CameraExample

namespace implementations {

  .Camera <|-- Camera1
  .Camera <|-- Camera2
}

@enduml

1 Answer

+1 vote
answered Mar 6, 2019 by janwilmans (200 points)
To answer my own question:

Layout can be influenced by:

1) making relations 'longer' by adding extra minuses to a relation:

for example: change 'b -> c'  to 'b --> c' or even 'b ---> c' will
literally create more 'distance' between b and c, I could not find this in official documentation, but it seems to work quite well.

@startuml
A -right-> B
B ---> C
@enduml

2) specifying the direction (left/right/up/down) of a relation:

@startuml
A -up-> B
@enduml

will make the arrow point upwards placing B above A

3) hidden arrows can 'align' classes horizontally

this doesn't really do what you want, and top of that pollutes the diagram with relations that aren't actually meaningful, except to the layout.
the behaviour is the same as 2) but it hides the actual drawing of the arrow.

@startuml

class C

A --|> Base
B --|> Base

'for layout only
Base -[hidden]right- C

@enduml

4) putting classes in a namespace will group them together

@startuml
namespace YourGroup {
  class A
  class B
}
@enduml

5) in stead of the namespace putting stuff in a 'together' group will do exactly that:

together {
  class A
  class B
}

This will group stuff 'together' but not surround them with anything visible.
...