5

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?

Potherca
  • 13,207
  • 5
  • 76
  • 94
Roderik
  • 307
  • 1
  • 4
  • 12
  • @Potherca In general I think it is better to have a fixed image in the question as the images from plantuml are rendered at the moment of the reference to the plantuml web server and thus may contain updates from plantuml that are not yet available at the moment of asking the question and thus this might hide the original problem. – albert Aug 15 '20 at 12:20
  • 1
    Excellent point, I hadn't thought of that! I've replaced the dynamic images with static versions. – Potherca Aug 15 '20 at 17:52
  • @Potherca Thanks, I don't know whether or not you are working on other questions, but I think the non fixed image problem is also valid for other questions you edited like: https://stackoverflow.com/questions/33845514/plantuml-activity-diagram-go-back/33845966#33845966 – albert Aug 16 '20 at 07:43
  • I went over my other edits, looks like I missed that one. Fixed now. Thanks for pointing it out! – Potherca Aug 17 '20 at 11:17

4 Answers4

7

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
Potherca
  • 13,207
  • 5
  • 76
  • 94
jj2f1
  • 300
  • 1
  • 7
7

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

Potherca
  • 13,207
  • 5
  • 76
  • 94
nmz787
  • 1,960
  • 1
  • 21
  • 35
1

There was a similar question on the PlantUML forums in January, but basically the solution was to duplicate the common activities in such cases. So in your case it would give:

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

  if (Q2) then (yes)
    :D;
  else (no)
    :E;
    :C;
  endif

else (no)
  :C;
endif
stop
@enduml

PlantUML Graphviz diagram

Currently it only seems possible to use a workaround for this.

Potherca
  • 13,207
  • 5
  • 76
  • 94
Didier L
  • 18,905
  • 10
  • 61
  • 103
  • 1
    But the real flow is much more complicated, several activities will happen after :C, when there are two :C activities they should both have the same continuation. It's probably impossible to express it with this notation but I feel that's a really bad thing to have a modelling language that does not support all options of the model. I especially need it for complex flows to give better insight, for easy flows the code would be more or less self explaining already. – Roderik Sep 30 '18 at 00:50
0

This is what I found worked...

|Main|
start
  :SomeClass constructor called;
  :buildTreeListOpts called;
if (hasOptions()) then (yes)
else (no)
    :require DataLoader;
    :call getData;
|#Cyan|DataLoader|
 :getData;
if (hasDataInLocalStorage()) then (yes)
else (no)
|DataLoader|
    :XHR fetch options;
    :callback;
endif
|Main|
endif
  :finalize;
stop

PlantUML diagram

Keep practicing on their live demo until you find something that works. http://plantuml.com/

Good luck.

Potherca
  • 13,207
  • 5
  • 76
  • 94
cbuteau
  • 736
  • 1
  • 7
  • 15
  • And then :C is the finalize? Swimlanes are required? – Roderik Nov 18 '17 at 03:41
  • I don't know if swimlanes are required...I know I had the same problem with a sample with swimlanes and ifs...I found a solution and posted it....I found not filling in the if section and letting it flow to one activity did the trick....You might find something else...I did not solve for your problem but for mine ...I am sorry if I did not help at all. You are really better experimenting in the live demo on the plantuml site than the MD preview in atom or another editor. – cbuteau Nov 19 '17 at 19:41