4

I found out recently that plantuml sorts of align all the classes of the same rank. Each class is then centered around an invisible line corresponding to that rank

Example:

example 1

Here Class 1, Class2, Class3 and Class4 have the same rank and get centered around an invisible line for that rank.

On a simple diagram like this one, it's not so much an issue but it gets a bit awkward in more complex diagrams

Example:

    @startuml

    skinparam linetype ortho

    namespace namespace1 {

    class ParentClass{
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    }

    ParentClass -- Class1
    ParentClass -- Class2
    ParentClass -- Class3
    ParentClass -- Class4


    class Class1{
    something
    something
    something
    something
    something
    somethins
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    something
    }

    class Class2{
    something
    something
    something
    something
    something
    something
    something

    }

    class Class3{
    something
    something
    something
    something
    }

    class Class4{
    something
    something
    }

    }

    namespace namespace2 {
    OtherParentClass -- Class1
    OtherParentClass -- Class2

    class Class1{
    something
    }

    class Class2{
    something
    }

    }
    @enduml

Imgur

In namespace2 in this example, the children classes are really far from the parent class.

Is there a way to control this better? Ideally I would like to be able to center all the classes of the same rank toward the top or even be able to reset the position of the invisible ranking line (so that in namespace2 the position of Class1, Class2 is independent of the positioning of the classes in namespace1)

Antoine Lefebvre
  • 346
  • 3
  • 10

1 Answers1

2

I could not find a way to control the position of that invisible rank line, or the alignment relative to it. What I learned: the rank is a feature of graphviz, which is used to do the graphical layout for plantuml. There are some hacks to force the layout in graphviz, but they cannot be used in plantuml (example 1, example 2), but those workarounds are not possible from within plantuml.

You can change the connecting line length, which in effect putts an element on a different rank. This is not really the solution to your problem, but could be a workaround in some cases.

So if you use --- in namespace1 and -- in namespace2, the classes from namespace2 will be above those from namespace1. You could also, for example, use a short connector for all classes except namespace1::Class1.

Test with longer lines in namespace1

I figured this out based on this answer to: How to align blocks in PlantUML class diagrams?

user766308
  • 103
  • 7