Search code examples
positionumlplantuml

How to enforce a layout for nodes containing other nodes


I use plantuml 1.2019.8 and graphviz 2.38

I want to position the middle node in the center of the diagramme and the up and down nodes above and below it.

But I cannot move up, down and middle to the center while at the same enforcing that right shows on the right side and left on the left side.

@startuml

skinparam linetype ortho

node up
node down
node "\n\n<b>    middle\n\n" as middle
node " " as left {
 node "left" as in_left
}
node " " as right {
 node "right" as in_right 
}

middle -u- up
down -u- middle

right -u- up
down -u- right

left -u- up
down -u- left

@enduml

now this complex problem

@startuml

    skinparam linetype ortho

    node up
    node down

    node " " as left {
     node "left1" as in_left1
     node "left2" as in_left2
     node "left3" as in_left3
    }
    together " " as T {
     node " " as middle {
      node "middle1" as in_middle1
      node "middle2" as in_middle2
    }
     node " " as right {
      node "right1" as in_right1
      node "right2" as in_right2
    }
    }

    in_left1 .d. in_left2
    in_left2 .d. in_left3

    in_right1 .r. in_right2

    in_middle1 .d. in_middle2
    middle -u- up
    down -u-- middle

    right -u- up
    down -u--- right

    left -u- up
    down -u- left

    @enduml

Here is the Result

but the up and down are again not centered with middle1 and middle2


Solution

  • You could use the together keyword to enforce that middle and right stick together. Left will then flow around it on the other side.

    @startuml
    
    skinparam linetype ortho
    
    node up
    node down
    node " " as left {
        node "left" as in_left 
    }
    
    together {
        node "\n\n<b>    middle\n\n" as middle
        node " " as right {
            node "right" as in_right
        }
    }
    
    middle -u- up
    down -u- middle
    
    right -u- up
    down -u- right
    
    left -u- up
    down -u- left
    
    
    @enduml