Search code examples
plantuml

How to make vertical switch-case like this?


I want to create an activity diagram in plantuml with some operators selection if elseif (switch - case), which lead to 2 decisions. I created such diagram, but it has horizontal layout. What i get;

@startuml

start
:start;


if (some question) then (no)

elseif (some question) then (no)

elseif (some question) then (no)


else (yes)
 : decision 2;
stop

endif
: decision 1;
stop
@enduml

What i want: desired diagram


Solution

  • Try putting the yes following the then using nested ifs, like this:

    start
    :start;
    
    if (some question) then (yes)
      if (some question) then (yes)
        if (some question) then (yes)
          : decision 2;
          stop
        else (no)
        endif
      else (no)
      endif
    else (no)
    endif
    : decision 1;
    stop
    

    That will give you :

    planuml sample server generated image

    This is using the beta/new Activity Diagram Syntax, as your example uses it. I tried to use swimlanes and other features to move decision 1 to the right or left. But was not able to find anything that produced a better output.