La syntaxe courante pour les diagrammes d'activité possède plusieurs limitations et inconvénients (par exemple, la difficulté à maintenir un diagramme lors de modifications). Une nouvelle syntaxe est maintenant proposée aux utilisateurs. Un autre avantage de cette nouvelle implémentation est qu'il n'y a pas besoin d'avoir Graphviz d'installé (comme pour les diagrammes de séquences). La nouvelle syntaxe remplace l'ancienne. Cependant, pour des raisons de compatibilité, l'ancienne syntaxe reste reconnu, pour assurer la compatibilité ascendante. Les utilisateurs sont simplement encouragés à migrer vers la nouvelle syntaxe.
Activité simple
Les étiquettes d'activités commencent avec : et finissent avec ;. Le formatage de texte peut être fait en utilisant la syntaxe créole wiki. Les activités sont implicitement liées à leur ordre de définition.
@startuml
:Hello world;
:This is on defined on
several **lines**;
@enduml
Départ/Arrêt [start, stop, end]
Vous pouvez utiliser les mots clés start et stop pour indiquer le début et la fin du diagramme.
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml
Vous pouvez aussi utiliser le mot clé end.
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
end
@enduml
Conditionnel [if, then, else]
Vous pouvez utiliser les mots clés if, then et else pour mettre des tests dans votre diagramme. Les étiquettes peuvent être fournies entre parenthèses. Les trois syntaxes possibles sont:
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
Vous pouvez utiliser le mot clé elseif pour avoir plusieurs tests, par défaut le mode est horizontal :
@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
Plusieurs conditions (en mode vertical)
Vous pouvez utiliser la commande !pragma useVerticalIf on pour avoir les conditions en mode vertical :
@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
d'utiliser une vrai action comme cible de répétition, après le premier mot clé repeat,
d'insérer une action dans le chemin de retour à l'aide du mot clé backward.
@startuml
start
repeat :foo as starting label;
:read data;
:generate diagrams;
backward:This is backward;
repeat while (more data?)
stop
@enduml
Break on a repeat loop [break]
You can break 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)
->no;
:Alert "Sucess";
stop
@enduml
You can use kill or detach to make an output split (multi-end):
@startuml
start
split
:A;
kill
split again
:B;
detach
split again
:C;
kill
end split
@enduml
@startuml
start
split
:A;
kill
split again
:b;
:c;
detach
split again
(Z)
detach
split again
end
split again
stop
end split
@enduml
Notes
Le formattage de texte peut être fait en utilisant la syntaxe créole wiki. Une note peut aussi être détachée, à l'aide du mot-clé floating.
@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
Vous pouvez ajouter une note sur un chemin de retour.
@startuml
start
repeat :Enter data;
:Submit;
backward :Warning;
note right: Note
repeat while (Valid?) is (No) not (Yes)
stop
@enduml
Vous pouvez spécifier une couleur pour certaines activités.
@startuml
start
:starting progress;
#HotPink:reading configuration files
These files should edited at this point!;
#AAAAAA:ending of the process;
@enduml
Lines without arrows
You can use skinparam ArrowHeadColor none in order to connect activities using lines only, without arrows.
@startuml
skinparam ArrowHeadColor none
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml
@startuml
skinparam ArrowHeadColor none
start
repeat :Enter data;
:Submit;
backward :Warning;
repeat while (Valid?) is (No) not (Yes)
stop
@enduml
Flèches
En utilisant la notation ->, vous pouvez ajouter du texte à une flèche, et changer sa couleur. Il est aussi possible d'avoir des flèches en pointillé, en gras, avec des tirets ou bien complètement cachées.
@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
Connecteurs
Il est possible d'utiser des parenthèses pour dessiner des connecteurs.
@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
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
Détacher [detach]
Il est possible de supprimer une flèche en utilisant le mot clé detach ou kill :
detach
@startuml
:start;
fork
:foo1;
:foo2;
fork again
:foo3;
detach
endfork
if (foo4) then
:foo5;
detach
endif
:foo6;
detach
:foo7;
stop
@enduml
kill
@startuml
:start;
fork
:foo1;
:foo2;
fork again
:foo3;
kill
endfork
if (foo4) then
:foo5;
kill
endif
:foo6;
kill
:foo7;
stop
@enduml
SDL (Specification and Description Language)
En changeant le séparateur final ;, vous pouvez déterminer différents rendus pour l’activité, conformément au langage de description et de spécification (LDS) ou Specification and Description Language (SDL) (en anglais) :
|
<
>
/
\\
]
}
@startuml
:Ready;
:next(o)|
:Receiving;
split
:nak(i)<
:ack(o)>
split again
:ack(i)<
:next(o)
on several line|
:i := i + 1]
:ack(o)>
split again
:err(i)<
:nak(o)>
split again
:foo/
split again
:bar\\
split again
:i > 5}
stop
end split
:finish;
@enduml
Exemple complet
@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