Old 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.
@startuml
:Hello world;
:This is on defined on
several **lines**;
@enduml
Simple action
Activities label starts with : and ends with ;.
Text formatting can be done using creole wiki syntax.
They are implicitly linked in their definition order.
@startuml
:Hello world;
:This is defined on
several **lines**;
@enduml
开始/结束
你可以使用关键字start和stop表示图示的开始和结束。
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml
也可以使用 end 关键字。
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
end
@enduml
Start/Stop/End
You can use start and stop keywords to denote the
beginning and the end of a diagram.
@startuml
start
:Hello world;
:This is defined on
several **lines**;
stop
@enduml
You can also use the end keyword.
@startuml
start
:Hello world;
:This is defined on
several **lines**;
end
@enduml
条件语句
在图示中可以使用关键字if,then和else设置分支测试。标注文字则放在括号中。
@startuml
start
if (Graphviz installed?) then (yes)
:process all\ndiagrams;
else (no)
:process only
__sequence__ and __activity__ diagrams;
endif
stop
@enduml
也可以使用关键字elseif设置多个分支测试。
@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
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
You can use the elseif keyword to have several tests (by default, it is the horizontal mode):
@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
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
It is also possible to use a full action as repeat target and insert an action in the return path using the backward keyword.
@startuml
start
repeat :foo as starting label;
:read data;
:generate diagrams;
backward:This is backward;
repeat while (more data?)
stop
@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.
@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) not (no)
->//merged step//;
: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
注释
文本格式支持creole wiki语法。
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 <b>HTML</b>
====
* Calling the method ""foo()"" is prohibited
end note
stop
@enduml
Notes
Text formatting can be done using 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 <b>HTML</b>
====
* 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
@startuml
start
:starting progress;
#HotPink:reading configuration files
These files should edited at this point!;
#AAAAAA:ending of the process;
@enduml
@startuml
start
:starting progress;
#HotPink:reading configuration files
These files should be 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
@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
Arrows
Using the -> notation, you can add texts to arrow, and change
their color.
It's also possible to have dotted, dashed, bold or hidden arrows.
@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
@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
分离(detach)
可以使用关键字detach移除箭头。
@startuml
:start;
fork
:foo1;
:foo2;
fork again
:foo3;
detach
endfork
if (foo4) then
:foo5;
detach
endif
:foo6;
detach
:foo7;
stop
@enduml
Detach or kill [detach, kill]
It's possible to remove an arrow using the detach or kill keyword:
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)
通过修改活动标签最后的分号分隔符(;),可以为活动设置不同的形状。
|
<
>
/
]
}
@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
:i > 5}
stop
end split
:finish;
@enduml
SDL (Specification and Description Language)
By changing the final ; separator, you can set different rendering for the activity:
|
<
>
/
\\
]
}
@startuml
:Ready;
:next(o)|
:Receiving;
split
:nak(i)<
:ack(o)>
split again
:ack(i)<
:next(o)
on several lines|
: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
一个完整的例子
@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
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