Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference earlier activity in PlantUML UML Activity Diagram

I am trying to make an activity diagram with PlantUML (new beta syntax).

So far I came up with (simplified):

@startuml
start
:A;
if (Q1) then (yes)
  :B;
  
  if (Q2) then (yes)
    :D;
  else (no)
    :E;
  endif
  
else (no)
  :C;
endif
stop
@enduml

plant uml diagram

It means, do A, if yes on first question do B otherwise C. After B ask question 2, if yes do D if no do E.

Instead of pointing to E when the answer on question 2 is no I want to go to activity C, however I don't know how to reference it. If I put :C; there (instead of :E; it is just interpreted as a new activity (however it's flow should continue from C there). I assume there is a way to draw a flow like this with PlantUML but I don't see it yet.

What would be the best way to reference an already defined activity?

like image 746
Roderik Avatar asked Jan 04 '23 05:01

Roderik


2 Answers

My current solution (been using plantUML for a week or so) is something like this:

@startuml
start
:A;
if (Q1) then (yes)
  :B;

  if (Q2) then (yes)
    :D;
  else (no)
    :E;
    :call C>
  endif
else (no)
  :call C>
endif
stop
partition C {
  :do 1st C thing;
  :do 2nd C thing;
}
@enduml

Plant uml diagram

like image 132
nmz787 Avatar answered Jan 23 '23 20:01

nmz787


I moved to graphviz for this exact reason. Plantuml gives some easy syntax for some types of diagrams but for moving in multiple directions it gets challenging.

I try to use plantuml for flow diagrams but when I get close to state machines I move to graphviz. So a graphviz solution to your problem would look like the following.

Original drawing:

digraph drawing1 {
  A -> B [label="yes"]
  A -> C [label="no"]
  B -> D [label="yes"]
  B -> E [label="no"]
}

PlantUML graphviz diagram

Make B goto C when no.

digraph drawing1 {
  A -> B [label="yes"]
  A -> C [label="no"]
  B -> D [label="yes"]
  B -> C [label="no"]
}

PlantUML Graphviz diagram

If you want to make nodes B and C line up with each other you can use the following code change.

digraph drawing1 {
  A -> B [label="yes"]
  A -> C [label="no"]
  B -> D [label="yes"]
  B -> C [label="no"]
  {rank=same B C}
}

PlantUML Graphviz diagram

I gave up on solving similar problems to yours with plantuml.


In Windows, once you install graphviz and want to generate a png output you go to your directory with a file that contains you digraph code; let's call the file test.gv.

Then run the following command to generate the output test.png.

dot test.gv -Tpng -o test.png
like image 44
jj2f1 Avatar answered Jan 23 '23 22:01

jj2f1