How to rearrange blocks in a UML state diagram
Asked Answered
I

1

5

I just created a state diagram and right now I am struggling with the positions of the blocks. My goal is to have States 1,2,4,5 in a "down"-row and state 3 at the right from state 1.

See my UML code and the attached screenshot for the current (left) and wanted (right) design

UML Code:

@startuml diagramStackO
scale 400 width
[*]    -down->  State1
State1 -down->  State2
State1 -right-> State3
State2 -up->    State3
State2 -down->  State4
State4 -->      State5
State5 -->      [*]
@enduml

Screenshot (left: current right: what it should look like)

enter image description here

Improvement answered 4/2, 2021 at 8:51 Comment(1)
Thanks for your answer :) The base functions are easy to use and changes are quickly implemented. "Hope is the last to die" !Improvement
G
9

My first advice would be to just ignore it and move on... Tweaking diagrams in PlantUML to get them "just right", even for little things, can take up a lot of time.

However, as someone who spends way too much time in getting their diagrams just right, there are two things that come to mind.

Using ortho

The first one is to just add skinparam linetype ortho. This is the least work but also gives the least improvment:

@startuml
skinparam linetype ortho

[*]    -down->  State1
State1 -down->  State2
State1 -right-> State3
State2 -up->    State3
State2 -down->  State4
State4 -->      State5
State5 -->      [*]
@enduml

Using a hidden container

The other is adding a hidden container which a bit more work, but not too much, I think.

To get the vertical alignment that you want, the states need to be grouped together:

All we need to do now is hide the container:

The code I used to achieve this effect is:

@startuml
skinparam {
    shadowing false

    state {
        BackgroundColor<<HIDDEN>> hidden
        BorderColor<<HIDDEN>> hidden
    }
}


state " " as _ <<HIDDEN>> {
    state State1
    state State2
    state State4
    state State5
}


[*]    -down->  State1
State1 -down->  State2
State1 -right-> State3
State2 -right->    State3
State2 -down->  State4
State4 -->      State5
State5 -->      [*]
@enduml
Gratia answered 5/2, 2021 at 9:52 Comment(3)
great answer, I did not catch that way to do looking at PlantUMLUnman
@Unman Well, I have the advantage of having used Graphviz a lot before switching to PlantUML. As PlantUMl use the Grahpviz layour engine, a lot of my previous knowledge comes in useful for edgecases like these. :-)Gratia
brilliant! what a mastery of this tool!Mew

© 2022 - 2024 — McMap. All rights reserved.