Multilingual Wiki Documentation

You are currently using syntax.
In an attempt to improve PlantUML documentation...
Please do not use this website for your own diagrams.
You can click here and use the online server here for your own documentation.

Wiki Toc    View page history    Add new chapter    Reorder page    Raw


活动图

Activity Diagram (legacy)

This is the old Activity Diagram (legacy) syntax, to see the new current version see: Activity Diagram (new).

简单活动

Simple Action

使用(*)作为活动图的开始点和结束点。

有时,你可能想用(*top)强制开始点位于图示的顶端。

使用-->绘制箭头。

@startuml

(*) --> "First Activity"
"First Activity" --> (*)

@enduml

You can use (*) for the starting point and ending point of the activity diagram.

In some occasion, you may want to use (*top) to force the starting point to be at the top of the diagram.

Use --> for arrows.

@startuml

(*) --> "First Action"
"First Action" --> (*)

@enduml

箭头上的标签

Label on arrows

默认情况下,箭头开始于最接近的活动。

可以用[]放在箭头定义的后面来添加标签。

@startuml

(*) --> "First Activity"
-->[You can put also labels] "Second Activity"
--> (*)

@enduml

By default, an arrow starts at the last used activity.

You can put a label on an arrow using brackets [ and ] just after the arrow definition.

@startuml

(*) --> "First Action"
-->[You can put also labels] "Second Action"
--> (*)

@enduml

改变箭头方向

Changing arrow direction

你可以使用->定义水平方向箭头,还可以使用下列语法强制指定箭头的方向:
  • -down-> (default arrow)
  • -right-> or ->
  • -left->
  • -up->

@startuml

(*) -up-> "First Activity"
-right-> "Second Activity"
--> "Third Activity"
-left-> (*)

@enduml

You can use -> for horizontal arrows. It is possible to force arrow's direction using the following syntax:
  • -down-> (default arrow)
  • -right-> or ->
  • -left->
  • -up->

@startuml

(*) -up-> "First Action"
-right-> "Second Action"
--> "Third Action"
-left-> (*)

@enduml

分支

Branches

你可以使用关键字if/then/else创建分支。

@startuml
(*) --> "Initialization"

if "Some Test" then
  -->[true] "Some Activity"
  --> "Another activity"
  -right-> (*)
else
  ->[false] "Something else"
  -->[Ending process] (*)
endif

@enduml

不过,有时你可能需要重复定义同一个活动:

@startuml
(*)  --> "check input"
If "input is verbose" then
--> [Yes] "turn on verbosity"
--> "run command"
else
--> "run command"
Endif
-->(*)
@enduml

You can use if/then/else keywords to define branches.

@startuml
(*) --> "Initialization"

if "Some Test" then
  -->[true] "Some Action"
  --> "Another Action"
  -right-> (*)
else
  ->[false] "Something else"
  -->[Ending process] (*)
endif

@enduml

Unfortunately, you will have to sometimes repeat the same activity in the diagram text:

@startuml
(*)  --> "check input"
If "input is verbose" then
--> [Yes] "turn on verbosity"
--> "run command"
else
--> "run command"
Endif
-->(*)
@enduml

更多分支

More on Branches

默认情况下,一个分支连接上一个最新的活动,但是也可以使用if关键字进行连接。

还可以嵌套定义分支。

@startuml

(*) --> if "Some Test" then

  -->[true] "action 1"

  if "" then
    -> "action 3" as a3
  else
    if "Other test" then
      -left-> "action 5"
    else
      --> "action 6"
    endif
  endif

else

  ->[false] "action 2"

endif

a3 --> if "last test" then
  --> "action 7"
else
  -> "action 8"
endif

@enduml

By default, a branch is connected to the last defined activity, but it is possible to override this and to define a link with the if keywords.

It is also possible to nest branches.

@startuml

(*) --> if "Some Test" then

  -->[true] "action 1"

  if "" then
    -> "action 3" as a3
  else
    if "Other test" then
      -left-> "action 5"
    else
      --> "action 6"
    endif
  endif

else

  ->[false] "action 2"

endif

a3 --> if "last test" then
  --> "action 7"
else
  -> "action 8"
endif

@enduml

同步

Synchronization

你可以使用 === code === 来显示同步条。

@startuml

(*) --> ===B1===
--> "Parallel Activity 1"
--> ===B2===

===B1=== --> "Parallel Activity 2"
--> ===B2===

--> (*)

@enduml

You can use === code === to display synchronization bars.

@startuml

(*) --> ===B1===
--> "Parallel Action 1"
--> ===B2===

===B1=== --> "Parallel Action 2"
--> ===B2===

--> (*)

@enduml

长的活动描述

Long action description

定义活动时可以用\n来定义跨越多行的描述。

还可以用as关键字给活动起一个短的别名。 这个别名可以在接下来的图示定义中使用。

@startuml
(*) -left-> "this <size:20>activity</size>
is <b>very</b> <color:red>long2</color>
and defined on several lines
that contains many <i>text</i>" as A1

-up-> "Another activity\n on several lines"

A1 --> "Short activity <img:sourceforge.jpg>"
@enduml

When you declare activities, you can span on several lines the description text. You can also add \n in the description.

You can also give a short code to the activity with the as keyword. This code can be used latter in the diagram description.

@startuml
(*) -left-> "this <size:20>action</size>
is <b>very</b> <color:red>long2</color>
and defined on several lines
that contains many <i>text</i>" as A1

-up-> "Another action\n on several lines"

A1 --> "Short action <img:sourceforge.jpg>"
@enduml

注释

Notes

你可以在活动定义之后用 note left, note right, note top or note bottom, 命令给活动添加注释。

如果想给开始点添加注释,只需把注释的定义放在活动图最开始的地方即可。

也可以用关键字endnote定义多行注释。

@startuml

(*) --> "Some Activity"
note right: This activity has to be defined
"Some Activity" --> (*)
note left
 This note is on
 several lines
end note

@enduml

You can add notes on a activity using the commands note left, note right, note top or note bottom, just after the description of the activity you want to note.

If you want to put a note on the starting point, define the note at the very beginning of the diagram description.

You can also have a note on several lines, using the endnote keywords.

@startuml

(*) --> "Some action"
note right: This action has to be defined
"Some action" --> (*)
note left
 This note is on
 several lines
end note

@enduml

分区

Partition

用关键字partition定义分区,还可以设置背景色(用颜色名或者颜色值)。

定义活动的时候,它自动被放置到最新的分区中。

}结束分区的定义。

@startuml

partition Conductor {
  (*) --> "Climbs on Platform"
  --> === S1 ===
  --> Bows
}

partition Audience #LightSkyBlue {
  === S1 === --> Applauds
}

partition Conductor {
  Bows --> === S2 ===
  --> WavesArmes
  Applauds --> === S2 ===
}

partition Orchestra #CCCCEE {
  WavesArmes --> Introduction
  --> "Play music"
}

@enduml

You can define a partition using the partition keyword, and optionally declare a background color for your partition (Using a html color code or name)

When you declare activities, they are automatically put in the last used partition.

You can close the partition definition using a closing bracket }.

@startuml

partition Conductor {
  (*) --> "Climbs on Platform"
  --> === S1 ===
  --> Bows
}

partition Audience #LightSkyBlue {
  === S1 === --> Applauds
}

partition Conductor {
  Bows --> === S2 ===
  --> WavesArmes
  Applauds --> === S2 ===
}

partition Orchestra #CCCCEE {
  WavesArmes --> Introduction
  --> "Play music"
}

@enduml

显示参数

Skinparam

skinparam命令修改字体和颜色。

如下场景可用:
  • 在图示定义中
  • 在引入的文件中
  • 在命令行或ANT任务提供的配置文件中。
还可以为构造类型指定特殊颜色和字体。

@startuml

skinparam backgroundColor #AAFFFF
skinparam activity {
  StartColor red
  BarColor SaddleBrown
  EndColor Silver
  BackgroundColor Peru
  BackgroundColor<< Begin >> Olive
  BorderColor Peru
  FontName Impact
}

(*) --> "Climbs on Platform" << Begin >>
--> === S1 ===
--> Bows
--> === S2 ===
--> WavesArmes
--> (*)

@enduml

You can use the skinparam command to change colors and fonts for the drawing.

You can use this command : You can define specific color and fonts for stereotyped activities.

@startuml

skinparam backgroundColor #AAFFFF
skinparam activity {
  StartColor red
  BarColor SaddleBrown
  EndColor Silver
  BackgroundColor Peru
  BackgroundColor<< Begin >> Olive
  BorderColor Peru
  FontName Impact
}

(*) --> "Climbs on Platform" << Begin >>
--> === S1 ===
--> Bows
--> === S2 ===
--> WavesArmes
--> (*)

@enduml

八边形活动

Octagon

可用用skinparam activityShape octagon命令将活动的外形改为八边形。

@startuml
'Default is skinparam activityShape roundBox
skinparam activityShape octagon

(*) --> "First Activity"
"First Activity" --> (*)

@enduml

You can change the shape of activities to octagon using the skinparam activityShape octagon command.

@startuml
'Default is skinparam activityShape roundBox
skinparam activityShape octagon

(*) --> "First Action"
"First Action" --> (*)

@enduml

一个完整的例子

Complete example

@startuml
title Servlet Container

(*) --> "ClickServlet.handleRequest()"
--> "new Page"

if "Page.onSecurityCheck" then
  ->[true] "Page.onInit()"

  if "isForward?" then
   ->[no] "Process controls"

   if "continue processing?" then
     -->[yes] ===RENDERING===
   else
     -->[no] ===REDIRECT_CHECK===
   endif

  else
   -->[yes] ===RENDERING===
  endif

  if "is Post?" then
    -->[yes] "Page.onPost()"
    --> "Page.onRender()" as render
    --> ===REDIRECT_CHECK===
  else
    -->[no] "Page.onGet()"
    --> render
  endif

else
  -->[false] ===REDIRECT_CHECK===
endif

if "Do redirect?" then
 ->[yes] "redirect request"
 --> ==BEFORE_DESTROY===
else
 if "Do Forward?" then
  -left->[yes] "Forward request"
  --> ==BEFORE_DESTROY===
 else
  -right->[no] "Render page template"
  --> ==BEFORE_DESTROY===
 endif
endif

--> "Page.onDestroy()"
-->(*)

@enduml

@startuml
title Servlet Container

(*) --> "ClickServlet.handleRequest()"
--> "new Page"

if "Page.onSecurityCheck" then
  ->[true] "Page.onInit()"

  if "isForward?" then
   ->[no] "Process controls"

   if "continue processing?" then
     -->[yes] ===RENDERING===
   else
     -->[no] ===REDIRECT_CHECK===
   endif

  else
   -->[yes] ===RENDERING===
  endif

  if "is Post?" then
    -->[yes] "Page.onPost()"
    --> "Page.onRender()" as render
    --> ===REDIRECT_CHECK===
  else
    -->[no] "Page.onGet()"
    --> render
  endif

else
  -->[false] ===REDIRECT_CHECK===
endif

if "Do redirect?" then
 ->[yes] "redirect request"
 --> ==BEFORE_DESTROY===
else
 if "Do Forward?" then
  -left->[yes] "Forward request"
  --> ==BEFORE_DESTROY===
 else
  -right->[no] "Render page template"
  --> ==BEFORE_DESTROY===
 endif
endif

--> "Page.onDestroy()"
-->(*)

@enduml


Please report any bugs to plantuml@gmail.com or here.
This website is still in beta testing.