Activity diagram

The diagram of activities (activities) – reflects the dynamic aspects of the behavior of the system. A flowchart that illustrates how the control flow moves from one activity to another. 

Activities on the diagram are “scattered” along floating lines (“Swimlane”). Each “Swimlane” corresponds to the behavior of one of the objects (for example, client, manager, web server, database server, etc.). Thanks to this, it is easy to determine which of the objects performs each of the activities. 

Swimlane is a part of the area of an activity diagram that displays only those activities for which a particular object is responsible.

1. Basic elements

Action state

The case of a state with some incoming action and at least one transition leaving the state. This transition implicitly assumes that the incoming action has already completed. The state of action is elementary (cannot have internal transitions). 

It is used to simulate one step of an algorithm (procedure) or control flow. 

Graphically, the state of the action is depicted by a rectangle with rounded corners. An action expression is written inside this figure, which must be unique within the same activity diagram. 

Transitions 

When constructing an activity diagram, only those transitions are used that are triggered immediately after the completion of the activity or the corresponding action. 

This transition transfers the activity to the next state as soon as the action in the previous state ends. 

In the diagram, such a transition is represented by a solid line with an arrow. 

If a single transition leaves the action state, then it may not be marked in any way. If there are several such transitions, then only one of them can work. It is in this case that the condition must be explicitly written for each of these transitions. 

Branching – a situation where the activity should be divided into alternative branches depending on the value of the intermediate result. 

Graphically, a branch in the activity diagram is indicated by a small rhombus. 

Splitting and merging – a symbol for splitting and merging parallel threads 

Graphically it is shown as a segment of a horizontal line that is thicker than the main lines in the diagram. 

Swimlanes

This refers to the visual analogy with swimming lanes in the pool if you look at the corresponding diagram. 

All action states in the activity diagram are divided into separate groups, which are separated from each other by vertical lines. Two adjacent lines form a track, and a group of states between these lines is performed by a separate unit (role, department, group, branch). 

Objects, Connectors, Comments

Added if necessary. 

2. Syntax 

Activities are indirectly related in the order in which they are defined

Код скопирован
  • @startuml
  • :alarm signal;
  • :awakening;
  • @enduml

To indicate the beginning and end of the chart, use the keywords start and stop (you can use the word end)

Код скопирован
  • @startuml 
  • start 
  • :alarm signal; 
  • :awakening; 
  • :alarm clock snoozing; 
  • :falling asleep; 
  • stop   
  • @enduml 

By changing the last separator, you can set different rendering for activities: 

Код скопирован
  • @startuml 
  • start 
  • :alarm signal> 
  • :awakening< 
  • :alarm clock snoozing | 
  • :falling asleep / 
  • :alarm signal 2} 
  • :awakening in panic 
  • :getting out of bed; 
  • stop 
  • @enduml

You can set a color Activities. The color designation is placed before the description of the activity, for example:

Код скопирован
  • @startuml
  • start
  • :alarm signal;
  • :awakening;
  • #HotPink:alarm clock snoozing;
  • #Lime:falling asleep;
  • stop
  • @enduml

The colors used in PlantUML can be found at https://plantuml.com/en/color 

You can group activities by defining a partition using the partition keyword:

Код скопирован
  • @startuml 
  • start 
  • partition Attempt1 { 
  • :alarm signal; 
  • #HotPink:awakening, 
  • alarm clock snoozing 
  • falling asleep; 
  • partition Attempt2 { 
  • :alarm signal2; 
  • #Lime:awakening2 
  • panic 
  • getting out of bed; 
  • stop 
  • @enduml

Transitions

Simple transitions in the form of arrows appear automatically if you indicate more than one activity on the diagram. 

If conditions for the transition are necessary, you can use the keywords if, then and else and the description of the conditions in parentheses. The endif keyword should end with all conditions. 

Код скопирован
  • @startuml
  • start
  • if (alarm signal) then (woke up)
  • :clean teeth\have breakfast;
  • else (did not wake up)
  • :hope only on alarm2 or relatives;
  • endif
  • stop
  • @enduml

Using the elseif keyword, you can create several checks:

Код скопирован
  • @startuml 
  • 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 keywords repeat and  repeat while to create a repeating loop.

Код скопирован
  • @startuml    
  • start  
  • repeat 
  • :woke up, 
  • had breakfast; 
  • :went to work; 
  • :drank beer; 
  • repeat while (fell asleep) 
  • stop 
  • @enduml

Using the while and end while keywords, you can create repeating loops of this kind: 

Код скопирован
  • @startuml               
  • start 
  • while (tired?) 
  •   :have a dinner; 
  •   :take a shower; 
  • endwhile 
  • :do some work!; 
  • stop 
  • @endum 

It is possible to add a description using the endwhile keyword or using the is keyword

Код скопирован
  • @startuml                      
  • while (tired?) is (no)  
  • :work;  
  • endwhile (yes)  
  • :go home;  
  • @enduml 

To define parallel processes, use the keywords fork, fork again and end fork. 

Код скопирован
  • @startuml
  • start
  • if (multiprocessor?) then (yes)
  • fork
  • :Treatment 1;
  • fork again
  • :Treatment 2;
  • end fork
  • else (monoproc)
  • :Treatment 1;
  • :Treatment 2;
  • endif
  • @enduml

It is possible to remove (detach) the arrow using the detach keyword. 

Код скопирован
  • @startuml
  • :start;
  • fork
  • :foo1;
  • :foo2;
  • fork again
  • :foo3;
  • detach
  • endfork
  • stop
  • @enduml

Using the  -> notation, you can add text to the arrow, and change its color

You can make arrows from dots, hyphens, bold and hidden. 

Код скопирован
  • @startuml
  • :foo1;
  • -> You can put text on arrows;
  • if (test) then
  • -[#blue]->
  • :foo2;
  • -[#green,dashed]-> The text can
  • also be on several lines
  • and **very** long…;
  • :foo3;
  • else
  • -[#black,dotted]->
  • :foo4;
  • endif
  • -[#gray,bold]->
  • :foo5;
  • @enduml

Swimlanes

Swimlanes are identified by symbol |

It is also possible to set the color of the swimlanes. 

Код скопирован
  • @startuml 
  • |Swimlane1| 
  • start 
  • :foo1; 
  • |#AntiqueWhite|Swimlane2|    
  • :foo2; 
  • :foo3; 
  • |Swimlane1| 
  • :foo4; 
  • |Swimlane2| 
  • :foo5; 
  • stop 
  • @enduml 

Notes

Note right keyword adds the note to the right of activity; note left places the note to the left of the activity; floating note keyword makes the floating note. 

Text formatting can be done with creole syntax. 

Код скопирован
  • @startuml
  • start
  • :foo1;
  • floating note left: This is a note
  • :foo2;
  • note right
  • This note is on several
  • //lines// and can
  • contain <b>HTML</b>
  • ====
  • * Calling the method “”foo()”” is prohibited
  • end note
  • stop
  • @enduml

Connector

Brackets () are used to indicate a connector. 

Код скопирован
  • @startuml
  • start
  • :Some activity;
  • (A)
  • detach
  • (A)
  • :Other activity;
  • @enduml