Activity Diagram (new)
Old link::activity-diagram-legacy[syntax for activity diagram] had several limitations and drawbacks (for example, it’s difficult to maintain).
So a completely new syntax and implementation is now available to users. Another advantage of this implementation is that it’s done without the need of having Graphviz installed (as for sequence diagrams).
This syntax will replace the old legacy one. However, for compatibility reason, the old syntax will still be recognized, to ensure ascending compatibility.
Users are simply encouraged to migrate to the new syntax.
Conditional
You can use if
, then
and else
keywords to put tests in your diagram.
Labels can be provided using parentheses.
The 3 syntaxes are possible:
* if (...) then (...)
@startuml
start
if (Graphviz installed?) then (yes)
:process all\ndiagrams;
else (no)
:process only
__sequence__ and __activity__ diagrams;
endif
stop
@enduml
-
if (...) is (...) then
@startuml if (color?) is (<color:red>red) then :print red; else :print not red; @enduml
-
if (...) equals (...) then
@startuml if (counter?) equals (5) then :print 5; else :print not 5; @enduml
[Ref. QA-301]
Several tests (horizontal mode)
You can use the elseif
keyword to have several tests (by default, it is the horizontal mode):
Several tests (vertical mode)
You can use the command !pragma useVerticalIf on
to have the tests in vertical mode:
@startuml
!pragma useVerticalIf on
start
if (condition A) then (yes)
:Text 1;
elseif (condition B) then (yes)
:Text 2;
stop
elseif (condition C) then (yes)
:Text 3;
elseif (condition D) then (yes)
:Text 4;
else (nothing)
:Text else;
endif
stop
@enduml
You can use the -P
link::command-line[command-line] option to specify the pragma:
java -jar plantuml.jar -PuseVerticalIf=on
Switch and case [switch, case, endswitch]
You can use switch
, case
and endswitch
keywords to put switch in your diagram.
Labels can be provided using parentheses.
Conditional with stop on an action [kill, detach]
You can stop action on a if loop.
But if you want to stop at the precise action, you can use the kill
or detach
keyword:
-
kill
@startuml if (condition?) then #pink:error; kill endif #palegreen:action; @enduml
[Ref. QA-265]
-
detach
@startuml if (condition?) then #pink:error; detach endif #palegreen:action; @enduml
Repeat loop
You can use repeat
and repeatwhile
keywords to have repeat loops.
@startuml
start
repeat
:read data;
:generate diagrams;
repeat while (more data?) is (yes)
->no;
stop
@enduml
It is also possible to use a full action as repeat
target and insert an action in the return path using the backward
keyword.
Break on a repeat loop [break]
You can use the break
keyword after an action on a loop.
@startuml
start
repeat
:Test something;
if (Something went wrong?) then (no)
#palegreen:OK;
break
endif
->NOK;
:Alert "Error with long text";
repeat while (Something went wrong with long text?) is (yes) not (no)
->//merged step//;
:Alert "Success";
stop
@enduml
[Ref. QA-6105]
Goto and Label Processing [label, goto]
⚠ It is currently only experimental 🚧
You can use label
and goto
keywords to denote goto processing, with:
* label <label_name>
* goto <label_name>
@startuml
title Point two queries to same activity\nwith `goto`
start
if (Test Question?) then (yes)
'space label only for alignment
label sp_lab0
label sp_lab1
'real label
label lab
:shared;
else (no)
if (Second Test Question?) then (yes)
label sp_lab2
goto sp_lab1
else
:nonShared;
endif
endif
:merge;
@enduml
While loop
You can use while
and endwhile
keywords to have repeat loops.
It is possible to provide a label after the endwhile
keyword, or using the is
keyword.
If you are using detach
to form an infinite while loop, then you will want to also hide the partial arrow that results using -[hidden]->
Parallel processing [fork, fork again, end fork, end merge]
You can use fork
, fork again
and end fork
or end merge
keywords to denote parallel processing.
fork
with end merge
[Ref. QA-5320]
@startuml
start
fork
:action 1;
fork again
:action 2;
fork again
:action 3;
fork again
:action 4;
end merge
stop
@enduml
[Ref. QA-13731]
Label on end fork
(or UML joinspec):
[Ref. QA-5346]
Split processing
Input split (multi-start)
You can use hidden
arrows to make an input split (multi-start):
@startuml
split
-[hidden]->
:A;
split again
-[hidden]->
:B;
split again
-[hidden]->
:C;
end split
:D;
@enduml
@startuml
split
-[hidden]->
:A;
split again
-[hidden]->
:a;
:b;
split again
-[hidden]->
(Z)
end split
:D;
@enduml
[Ref. QA-8662]
Notes
Text formatting can be done using link::creole[creole wiki syntax].
A note can be floating, using floating
keyword.
@startuml
start
:foo1;
floating note left: This is a note
:foo2;
note right
This note is on several
//lines// and can
contain HTML
====
* Calling the method ""foo()"" is prohibited
end note
stop
@enduml
You can add note on backward activity:
@startuml
start
repeat :Enter data;
:Submit;
backward :Warning;
note right: Note
repeat while (Valid?) is (No) not (Yes)
stop
@enduml
[Ref. QA-11788]
You can add note on partition activity:
@startuml
start
partition "**process** HelloWorld" {
note
This is my note
----
//Creole test//
end note
:Ready;
:HelloWorld(i)>
:Hello-Sent;
}
@enduml
[Ref. QA-2398]
Colors
You can specify a link::color[color] for some activities.
@startuml
start
:starting progress;
#HotPink:reading configuration files
These files should be edited at this point!;
#AAAAAA:ending of the process;
@enduml
You can also use link::color[gradient color].
[Ref. QA-4906]
Lines without arrows
Arrows
Using the ->
notation, you can add texts to arrow, and change
their link::color[color].
It’s also possible to have dotted, dashed, bold or hidden arrows.
Color on connector
You can add link::color[color] on connector.
@startuml
start
:The connector below
wishes he was blue;
#blue:(B)
:This next connector
feels that she would
be better off green;
#green:(G)
stop
@enduml
[Ref. QA-10077]
Grouping or partition
Partition
You can group activity together by defining partition:
@startuml
start
partition Initialization {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
@enduml
It’s also possible to change partition link::color[color]:
@startuml
start
partition #lightGreen "Input Interface" {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
@enduml
[Ref. QA-2793]
It’s also possible to add link::link[link] to partition:
@startuml
start
partition "[[http://plantuml.com partition_name]]" {
:read doc. on [[http://plantuml.com plantuml_website]];
:test diagram;
}
end
@enduml
[Ref. QA-542]
Group, Partition, Package, Rectangle or Card
You can group activity together by defining: * group; * partition; * package; * rectangle; * card.
@startuml
start
group Group
:Activity;
end group
floating note: Note on Group
partition Partition {
:Activity;
}
floating note: Note on Partition
package Package {
:Activity;
}
floating note: Note on Package
rectangle Rectangle {
:Activity;
}
floating note: Note on Rectangle
card Card {
:Activity;
}
floating note: Note on Card
end
@enduml
Swimlanes
Using pipe |
, you can define swimlanes.
It’s also possible to change swimlanes link::color[color].
@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml
You can add if
conditional or repeat
or while
loop within swimlanes.
@startuml
|#pink|Actor_For_red|
start
if (color?) is (red) then
#pink:**action red**;
:foo1;
else (not red)
|#lightgray|Actor_For_no_red|
#lightgray:**action not red**;
:foo2;
endif
|Next_Actor|
#lightblue:foo3;
:foo4;
|Final_Actor|
#palegreen:foo5;
stop
@enduml
You can also use alias
with swimlanes, with this syntax:
* |[#<color>|]<swimlane_alias>| <swimlane_title>
@startuml
|#palegreen|f| fisherman
|c| cook
|#gold|e| eater
|f|
start
:go fish;
|c|
:fry fish;
|e|
:eat fish;
stop
@enduml
[Ref. QA-2681]
Detach or kill [detach, kill]
SDL (Specification and Description Language)
By changing the final ;
separator, you can set different rendering for the activity:
* |
* <
* >
* /
* \\
* ]
* }
Complete example
@startuml
start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (true)
:Page.onInit();
if (isForward?) then (no)
:Process controls;
if (continue processing?) then (no)
stop
endif
if (isPost?) then (yes)
:Page.onPost();
else (no)
:Page.onGet();
endif
:Page.onRender();
endif
else (false)
endif
if (do redirect?) then (yes)
:redirect process;
else
if (do forward?) then (yes)
:Forward request;
else (no)
:Render page template;
endif
endif
stop
@enduml
Condition Style
Condition End Style
Diamond style (by default)
-
With one branch
@startuml skinparam ConditionEndStyle diamond :A; if (decision) then (yes) :B1; else (no) endif :C; @enduml
-
With two branches (
B1
,B2
)
@startuml skinparam ConditionEndStyle diamond :A; if (decision) then (yes) :B1; else (no) :B2; endif :C; @enduml @enduml
Horizontal line (hline) style
-
With one branch
@startuml skinparam ConditionEndStyle hline :A; if (decision) then (yes) :B1; else (no) endif :C; @enduml
-
With two branches (
B1
,B2
)
@startuml skinparam ConditionEndStyle hline :A; if (decision) then (yes) :B1; else (no) :B2; endif :C; @enduml @enduml
[Ref. QA-4015]