PlantUML语法速查

Table of Contents

1 Sequence Diagram

1.1 Basic examples

@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml

2016062901.png

1.2 Comments

注释用单引号或多行注释 /' … '/

1.3 Declaring participant

可以使用 participant 关键字来改变参与者的顺序 也可以使用其他的关键字声明一个参与者:

  • actor
  • boundary
  • control
  • entity
  • database
@startuml
actor Foo1
boundary Foo2
control Foo3
entity Foo4
database Foo5
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
@enduml

2016062902.png

可以使用 as 关键字来重命名一个参与者

@startuml
actor Bob #red
' The only difference between actor
'and participant is the drawing
participant Alice
participant "I have a really\nlong name" as L #99FF99
/' You can also declare:
participant L as "I have a really\nlong name" #99FF99
'/
Alice ->Bob: Authentication Request
Bob ->Alice: Authentication Response
Bob ->L: Log transaction
@enduml

2016062903.png

1.4 Use non-letters in participants

可以直接使用引号来定义参与者,并使用 as 关键字来起个别名。

@startuml
Alice -> "Bob()" : Hello
"Bob()" -> "This is very\nlong" as Long
' You can also declare:
' "Bob()" -> Long as "This is very\nlong"
Long --> "Bob()" : ok
@enduml

2016062904.png

1.5 Message to Self

@startuml
Alice ->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
@enduml

2016062905.png

1.6 Change arrow style

可以改变箭头的形状:

  1. add a final x to denote a lost message
  2. use \ or / instead of < or > to have only the bottom or top part of the arrow
  3. repeat the arrow head (for example, >> or //) head to have a thin drawing
  4. use – instead of - to have a dotted arrow
  5. add a final ”o” at arrow head
  6. use bidirectional arrow
@startuml
Bob ->x Alice
Bob -> Alice
Bob ->> Alice
Bob -\ Alice
Bob \\- Alice
Bob //-- Alice
Bob ->o Alice
Bob o\\-- Alice
Bob <-> Alice
Bob <->o Alice
@enduml

2016062906.png

1.7 Change arrow color

@startuml
Bob -[#red]> Alice : hello
Alice -[#0000FF]->Bob : ok
@enduml

2016062907.png

1.8 Message sequence numbering

使用关键字 autonumber 来自动给消息添加数字序号

@startuml
autonumber
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
@enduml

2016062908.png

可以使用 :autonumber 'start' 'increment' 指定一个起始数字和增量。

@startuml
autonumber
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
autonumber 15
Bob -> Alice : Another authentication Request
Bob <- Alice : Another authentication Response
autonumber 40 10
Bob -> Alice : Yet another authentication Request
Bob <- Alice : Yet another authentication Response
@enduml

2016062909.png

双引号之间也可以指定数字显示的格式, 可以参考Java类 DecimalFormat 中对格式的要求。 (’0’ means digit, ’#’ means digit and zero if absent) 在格式中,可以使用html标签。

@startuml
autonumber "<b>[000]"
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
autonumber 15 "<b>(<u>##</u>)"
Bob -> Alice : Another authentication Request
Bob <- Alice : Another authentication Response
autonumber 40 10 "<font color=red ><b>Message 0 "
Bob -> Alice : Yet another authentication Request
Bob <- Alice : Yet another authentication Response
@enduml

2016062910.png

也可以使用 autonumber stop 'increment' 'format' 以及 autonumber resume 'increment' 'format'来暂停和恢复数字编号。

@startuml
autonumber 10 10 "<b>[000]"
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
autonumber stop
Bob -> Alice : dummy
autonumber resume "<font color=red ><b>Message 0 "
Bob -> Alice : Yet another authentication Request
Bob <- Alice : Yet another authentication Response
autonumber stop
Bob -> Alice : dummy
autonumber resume 1 "<font color=blue ><b>Message 0 "
Bob -> Alice : Yet another authentication Request
Bob <- Alice : Yet another authentication Response
@enduml

2016062911.png

1.9 Title

为序列图定义一个标题

@startuml
title Simple communication example
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml

2016062912.png

1.10 Legend(图例) the diagram

The legend and end legend are keywords is used to put a legend. You can optionally specify to have left, right or center alignment for the legend.

@startuml
Alice -> Bob : Hello
legend right
Short
legend
endlegend
@enduml

2016062913.png

1.11 Splitting diagrams

newpage 关键字用于将一个图分解成多个图, 在 newpage 之后可以添 加一个标题。

@startuml
Alice -> Bob : message 1
Alice -> Bob : message 2
newpage
Alice -> Bob : message 3
Alice -> Bob : message 4
newpage A title for the\nlast page
Alice -> Bob : message 5
Alice -> Bob : message 6
@enduml

2016070102.png

1.12 Grouping message

可以使用如下一些关键字组合消息:

  • alt/else
  • opt
  • loop
  • par
  • break
  • critical
  • group 后面跟着要显示的文字 end 关键字关闭一个group,group是可以嵌套的。
@startuml
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Authentication Failure
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Log attack end
end
else Another type of failure
Bob -> Alice: Please repeat
end
@enduml

2016070103.png

1.13 Notes on messages

消息也可以添加注解,可以是显示在左边,可以显示在右边,也可以多行显 示。

@startuml
Alice ->Bob : hello
note left: this is a first note
Bob ->Alice : ok
note right: this is another note
Bob ->Bob : I am thinking
note left
a note
can also be defined
on several lines
end note
@enduml

2016070104.png

1.14 Some other notes

注解也可以以某个注解的位置为参考进行显示,也可以修改背景色。

@startuml
participant Alice
participant Bob
note left of Alice #aqua
This is displayed
left of Alice.
end note
note right of Alice: This is displayed right of Alice.
note over Alice: This is displayed over Alice.
note over Alice , Bob #FFAAAA: This is displayed\n over Bob and Alice.
note over Bob , Alice
This is yet another
example of
a long note.
end note
@enduml

2016070105.png

1.15 Changing notes shape

可以使用 hnoternote 关键字改变注解的形状。

@startuml
caller -> server : conReq
hnote over caller : idle
caller <- server : conConf
rnote over server
"r" as rectangle
"h" as hexagon
endrnote
@enduml

2016070106.png

1.16 Creole and HTML

可以使用creale格式定义注解

@startuml
participant Alice
participant "The **Famous** Bob" as Bob
Alice -> Bob : hello --there --
... Some ~~long delay~~ ...
Bob -> Alice : ok
note left
This is **bold**
This is //italics//
This is ""monospaced""
This is --stroked --
This is __underlined__
This is ~~waved~~
end note
Alice -> Bob : A //well formatted// message
note right of Alice
This is <back:cadetblue ><size:18>displayed </size ></back >
__left of__ Alice.
end note
note left of Bob
<u:red >This </u> is <color #118888> displayed </color >
**<color purple >left of </color > <s:red >Alice </strike > Bob**.
end note
note over Alice , Bob
<w:#FF33FF >This is hosted </w> by <img sourceforge.jpg >
end note
@enduml

2016070107.png

1.17 Divider

使用 == 将图拆分为一些逻辑步骤。

@startuml
== Initialization ==
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
== Repetition ==
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml

2016070108.png

1.18 Reference

可以使用 ref over 在图中使用引用。

@startuml
participant Alice
actor Bob
ref over Alice , Bob : init
Alice -> Bob : hello
ref over Bob
This can be on
several lines
end ref
@enduml

2016070109.png

1.19 Delay

可以使用 表示一个延迟。

@startuml
Alice -> Bob: Authentication Request
...
Bob --> Alice: Authentication Response
...5 minutes latter...
Bob --> Alice: Bye !
@enduml

2016070110.png

1.20 Space

使用 ||| 来表示图中的一些空格。

@startuml
Alice -> Bob: message 1
Bob --> Alice: ok
|||
Alice -> Bob: message 2
Bob --> Alice: ok
||45||
Alice -> Bob: message 3
Bob --> Alice: ok
@enduml

2016070111.png

1.21 Lifeline Activation and Destruction

生命周期图, activedeactive 表示参与者的生命周期, destroy 表示一个参考者生命周期的结束。

@startuml
participant User
User -> A: DoWork
activate A
A -> B: << createRequest >>
activate B
B -> C: DoWork
activate C
C --> B: WorkDone
destroy C
B --> A: RequestCreated
deactivate B
A -> User: Done
deactivate A
@enduml

2016070112.png

生命周期图也可以嵌套。

@startuml
participant User
User -> A: DoWork
activate A #FFBBBB
A -> A: Internal call
activate A #DarkSalmon
A -> B: << createRequest >>
activate B
B --> A: RequestCreated
deactivate B
deactivate A
A -> User: Done
deactivate A
@enduml

2016070113.png

1.22 Participant creation

create 关键字表示在接收到某个消息后,会创建一个新对象。

@startuml
Bob -> Alice : hello
create Other
Alice -> Other : new
create control String
Alice -> String
note right : You can also put notes!
Alice --> Bob : ok
@enduml

2016070114.png

1.23 Incoming and outgoing messages

当只表强调图的某个部分时,可以使用 "["和"]"分别表示图的左边和右边。

@startuml
[-> A: DoWork
activate A
A -> A: Internal call
activate A
A ->] : << createRequest >>
A<--] : RequestCreated
deactivate A
[<- A: Done
deactivate A
@enduml

2016070115.png

还可以使用如下语法:

@startuml
[-> Bob
[o-> Bob
[o->o Bob
[x-> Bob
[<- Bob
[x<- Bob
Bob ->]
Bob ->o]
Bob o->o]
Bob ->x]
Bob <-]
Bob x<-]
@enduml

2016070116.png

1.24 Stereotypes and Spots

@startuml
participant "Famous Bob" as Bob << Generated >>
participant Alice << (C,#ADD1B2) Testable >>
Bob ->Alice: First message
@enduml

2016070117.png

使用 skinparam guillemet 改变原型显示的字体。

@startuml
skinparam guillemet false
participant "Famous Bob" as Bob << Generated >>
participant Alice << (C,#ADD1B2) Testable >>
Bob ->Alice: First message
@enduml

2016070118.png

使用(X,color)add a spotted character in a colored circle

@startuml
participant Bob << (C,#ADD1B2) >>
participant Alice << (C,#ADD1B2) >>
Bob ->Alice: First message
@enduml

2016070119.png

1.25 More information on titles

标题格式化

@startuml
title __Simple__ **communication** example
Alice -> Bob: Authentication Request
Bob -> Alice: Authentication Response
@enduml

2016070120.png

标题中也可以包含换行符

@startuml
title __Simple__ communication example\non several lines
Alice -> Bob: Authentication Request
Bob -> Alice: Authentication Response
@enduml

2016070121.png

也可以使用 title end title 关键字定义跨跃多行的标题。

@startuml
title
<u>Simple </u> communication example
on <i>several </i> lines and using <font color=red >html </font >
This is hosted by <img:sourceforge.jpg >
end title
Alice -> Bob: Authentication Request
Bob -> Alice: Authentication Response
@enduml

2016070122.png

1.26 Participants encompass

可以使用框框把参考者框起来

@startuml
box "Internal Service" #LightBlue
participant Bob
participant Alice
end box
participant Other
Bob -> Alice : hello
Alice -> Other : hello
@enduml

2016070123.png

1.27 Removing Footer

可以使用 hide footbox 来删除图的footer。

@startuml
hide footbox
title Footer removed
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml

2016070124.png

1.28 Skinparam

可以使用 skinparm 来改变绘制时,使用的字体和颜色。

@startuml
skinparam backgroundColor #EEEBDC
skinparam sequence {
ArrowColor DeepSkyBlue
ActorBorderColor DeepSkyBlue
LifeLineBorderColor blue
LifeLineBackgroundColor #A9DCDF
ParticipantBorderColor DeepSkyBlue
ParticipantBackgroundColor DodgerBlue
ParticipantFontName Impact
ParticipantFontSize 17
ParticipantFontColor #A9DCDF
ActorBackgroundColor aqua
ActorFontColor DeepSkyBlue
ActorFontSize 17
ActorFontName Aapex
}
actor User
participant "First Class" as A
participant "Second Class" as B
participant "Last Class" as C
User -> A: DoWork
activate A
A -> B: Create Request
activate B
B -> C: DoWork
activate C
C --> B: WorkDone
destroy C
B --> A: Request Created
deactivate B
A --> User: Done
deactivate A
@enduml

2016070125.png

2 Use Case Diagram

2.1 Usecases

用例可以使用 '( )' 表示,或者使用关键字 usecase , 还可以使用 as 关键字来定义一个别名。

@startuml
(First usecase)
(Another usecase) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml

2016071210.png

2.2 Actors

活动者可以使用 ': :'表示,或者使用关键字 actor ,还可以使用 as 关键字来定义一个别名。

@startuml
:First Actor:
:Another\nactor: as Men2
actor Men3
actor :Last actor: as Men4
@enduml

2016071211.png

2.3 Usecases description

可以使用如下一些分隔符来表示多行用例描述。

@startuml
usecase UC1 as "You can use
several lines to define your usecase.
You can also use separators.
--
Several separators are possible.
==
And you can add titles:
..Conclusion..
This allows large description."
@enduml

2016071212.png.png

2.4 Basic Example

@startuml
User -> (Start)
User --> (Use the application) : A small label
:Main Admin: ---> (Use the application) : This is\nyet another\nlabel
@enduml

2016071213.png

2.5 Extension

@startuml
:Main Admin: as Admin
(Use the application) as (Use)
User <|-- Admin
(Start) <|-- (Use)
@enduml

2016071214.png

2.6 Using notes

@startuml
:Main Admin: as Admin
(Use the application) as (Use)
User -> (Start)
User --> (Use)
Admin ---> (Use)
note right of Admin : This is an example.
note right of (Use)
A note can also
be on several lines
end note
note "This note is connected\nto several objects." as N2
(Start) .. N2
N2 .. (Use)
@enduml

2016071215.png

2.7 Stereotypes

@startuml
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml

2016071216.png

2.8 Changing arrows direction

@startuml
:user: --> (Use case 1)
:user: -> (Use case 2)
@enduml

2016071217.png

You can also change directions by reversing the link:

@startuml
(Use case 1) <.. :user:
(Use case 2) <- :user:
@enduml

2016071218.png

还可以在箭头中直接使用 left right up down 等关键字指定

@startuml
:user: -left-> (dummyLeft)
:user: -right-> (dummyRight)
:user: -up-> (dummyUp)
:user: -down-> (dummyDown)
@enduml

2016071219.png

2.9 Title the diagram

@startuml
title Simple <b>Usecase </b>\nwith one actor
"Use the application" as (Use)
User -> (Use)
@enduml

2016071220.png

2.10 Splitting diagrams

@startuml
:actor1: --> (Usecase1)
newpage
:actor2: --> (Usecase2)
@enduml

2016071221.png

2.11 Left to right direction

默认方向是从上到下。

@startuml
'default
top to bottom direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml

2016071222.png

@startuml
left to right direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml

2016071223.png

2.12 Skinparam

改变颜色和显示的字体

@startuml
skinparam handwritten true
skinparam usecase {
BackgroundColor DarkSeaGreen
BorderColor DarkSlateGray
BackgroundColor << Main >> YellowGreen
BorderColor << Main >> YellowGreen
ArrowColor Olive
ActorBorderColor black
ActorFontName Courier
ActorBackgroundColor << Human >> Gold
}
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml

2016071224.png

2.13 Complete example

@startuml
left to right direction
skinparam packageStyle rect
actor customer
actor clerk
rectangle checkout {
customer -- (checkout)
(checkout) .> (payment) : include
(help) .> (checkout) : extends
(checkout) -- clerk
}
@enduml

2016071225.png

3 Class Diagram

3.1 Relations between classes

@startuml
Class01 <|-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
@enduml

2016080904.png

@startuml
Class11 <|.. Class12
Class13 --> Class14
Class15 ..> Class16
Class17 ..|> Class18
Class19 <--* Class20
@enduml

2016080905.png

3.2 Label on relations

@startuml
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
Class05 --> "1" Class06
@enduml

2016080906.png

@startuml
class Car
Driver - Car : drives >
Car *- Wheel : have 4 >
Car -- Person : < owns
@enduml

2016080907.png

3.3 Adding methods

@startuml
Object <|-- ArrayList
Object : equals()
ArrayList : Object[] elementData
ArrayList : size()
@enduml

2016080908.png

@startuml
class Dummy {
String data
void methods()
}
class Flight {
flightNumber : Integer
departureTime : Date
}
@enduml

2016080909.png

3.4 Defining visibility

@startuml
class Dummy {
-field1
#field2
~method1()
+method2()
}
@enduml

2016080910.png

@startuml
skinparam classAttributeIconSize 0
class Dummy {
-field1
#field2
~method1()
+method2()
}
@enduml

2016080911.png

3.5 Abstract and Static

@startuml
class Dummy {
{static} String id
{abstract} void methods()
}
@enduml

2016080912.png

3.6 Advanced class body

@startuml
class Foo1 {
You can use
several lines
..
as you want
and group
==
things together.
__
You can have as many groups
as you want
--
End of class
}
class User {
.. Simple Getter ..
+ getName()
+ getAddress()
.. Some setter ..
+ setName()
__ private data __
int age
-- encrypted --
String password
}
@enduml

2016080913.png

3.7 Notes and stereotypes

@startuml
class Object << general >>
Object <|--- ArrayList
note top of Object : In java , every class\nextends this one.
note "This is a floating note" as N1
note "This note is connected\nto several objects." as N2
Object .. N2
N2 .. ArrayList
class Foo
note left: On last defined class
@enduml

2016080914.png

3.8 More on notes

@startuml
class Foo
note left: On last defined class
note top of Object
In java , <size:18>every </size > <u>class </u>
<b>extends </b>
<i>this </i> one.
end note
note as N1
This note is <u>also </u>
<b><color:royalBlue >on several </color >
<s>words </s> lines
And this is hosted by <img:sourceforge.jpg >
end note
@enduml

2016080915.png

3.9 Note on links

@startuml
class Dummy
Dummy --> Foo : A link
note on link #red: note that is red
Dummy --> Foo2 : Another link
note right on link #blue
this is my note on right link
and in blue
end note
@enduml

2016080916.png

3.10 Abstract class and interface

@startuml
abstract class AbstractList
abstract AbstractCollection
interface List
interface Collection
List <|-- AbstractList
Collection <|-- AbstractCollection
Collection <|- List
AbstractCollection <|- AbstractList
AbstractList <|-- ArrayList
class ArrayList {
Object[] elementData
size()
}
enum TimeUnit {
DAYS
HOURS
MINUTES
}
annotation SuppressWarnings
@enduml

2016080917.png

3.11 Using non-letters

@startuml
class "This is my class" as class1
class class2 as "It works this way too"
class2 *-- "foo/dummy" : use
@enduml

2016080918.png

3.12 Hide attributes, methods

@startuml
class Dummy1 {
+myMethods()
}
class Dummy2 {
+hiddenMethod()
}
class Dummy3 <<Serializable >> {
String name
}
hide members
hide <<Serializable >> circle
show Dummy1 methods
show <<Serializable >> fields
@enduml

2016080919.png

3.13 Hide classes

@startuml
class Foo1
class Foo2
Foo2 *-- Foo1
hide Foo2
@enduml

2016080920.png

3.14 Use generics

@startuml
class Foo <? extends Element > {
int size()
}
Foo *- Element
@enduml

2016080921.png

3.15 Specific Spot

@startuml
class System << (S,#FF7700) Singleton >>
class Date << (D,orchid) >>
@enduml

2016080921.png

3.16 Packages

@startuml
package "Classic Collections" #DDDDDD {
Object <|-- ArrayList
}
package net.sourceforge.plantuml {
Object <|-- Demo1
Demo1 *- Demo2
}
@enduml

2016080922.png

3.17 Packages style

@startuml
scale 750 width
package foo1 <<Node >> {
class Class1
}
package foo2 <<Rect >> {
class Class2
}
package foo3 <<Folder >> {
class Class3
}
package foo4 <<Frame >> {
class Class4
}
package foo5 <<Cloud >> {
class Class5
}
package foo6 <<Database >> {
class Class6
}
@enduml

2016080923.png

3.18 Namespaces

@startuml
class BaseClass
namespace net.dummy #DDDDDD {
.BaseClass <|-- Person
Meeting o-- Person
.BaseClass <|- Meeting
}
namespace net.foo {
net.dummy.Person <|- Person
.BaseClass <|-- Person
net.dummy.Meeting o-- Person
}
BaseClass <|-- net.unused.Person
@enduml

2016080924.png

3.19 Automatic namespace creation

@startuml
set namespaceSeparator ::
class X1::X2::foo {
some info
}
@enduml

2016080925.png

关闭自动创建包的行为

set namespaceSeparator none
class X1.X2.foo {
some info
}

2016080926.png

3.20 Lollipop interface

@startuml
class foo
bar ()- foo
@enduml

2016080927.png

3.21 Changing arrows direction

@startuml
Room o- Student
Room *-- Chair
@enduml

2016080928.png

@startuml
Student -o Room
Chair --* Room
@enduml

2016080929.png

@startuml
foo -left-> dummyLeft
foo -right-> dummyRight
foo -up-> dummyUp
foo -down-> dummyDown
@enduml

2016080930.png

3.22 Title the diagram

@startuml
title Simple <b>example </b>\nof title
Object <|-- ArrayList
@enduml

2016080931.png

3.23 Legend the diagram

@startuml
Object <|- ArrayList
legend right
<b>Object </b> and <b>ArrayList </b>
are simple class
endlegend
@enduml

2016080932.png

3.24 Association classes

@startuml
class Student {
Name
}
Student "0..*" - "1..*" Course
(Student , Course) .. Enrollment
class Enrollment {
drop()
cancel()
}
@enduml

2016080933.png

@startuml
class Student {
Name
}
Student "0..*" -- "1..*" Course
(Student , Course) . Enrollment
class Enrollment {
drop()
cancel()
}
@enduml

2016080934.png

3.25 Skinparam

@startuml
skinparam class {
BackgroundColor PaleGreen
ArrowColor SeaGreen
BorderColor SpringGreen
}
skinparam stereotypeCBackgroundColor YellowGreen
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
@enduml

2016080935.png

3.26 Skinned Stereotypes

@startuml
skinparam class {
BackgroundColor PaleGreen
ArrowColor SeaGreen
BorderColor SpringGreen
BackgroundColor <<Foo >> Wheat
BorderColor <<Foo >> Tomato
}
skinparam stereotypeCBackgroundColor YellowGreen
skinparam stereotypeCBackgroundColor << Foo >> DimGray
Class01 <<Foo >>
Class03 <<Foo >>
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
@enduml

2016080936.png

3.27 Color gradient

@startuml
skinparam backgroundcolor AntiqueWhite/Gold
skinparam classBackgroundColor Wheat|CornflowerBlue
class Foo #red-green
note left of Foo #blue\9932CC
this is my
note on this class
end note
package example #GreenYellow/LightGoldenRodYellow {
class Dummy
}
@enduml

2016080937.png

3.28 Splitting large files

@startuml
' Split into 4 pages
page 2x2
class BaseClass
namespace net.dummy #DDDDDD {
.BaseClass <|-- Person
Meeting o-- Person
.BaseClass <|- Meeting
}
namespace net.foo {
net.dummy.Person <|- Person
.BaseClass <|-- Person
net.dummy.Meeting o-- Person
}
BaseClass <|-- net.unused.Person
@enduml

2016080938.png

4 Activity Diagram

活动图的新语法

4.1 Simple Activity

@startuml
:Hello world;
:This is on defined on
several **lines**;
@enduml

2016061002.png

4.2 Start/Stop

定义活动图的开始和结束位置

@startuml
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml

2016061003.png

也可以使用end关键字

@startuml
start
:Hello world;
:This is on defined on
several **lines**;
end
@enduml

2016061004.png

4.3 Conditional

@startuml
start
if (Graphviz installed?) then (yes)
:process all\ndiagrams;
else (no)
:process only
__sequence__ and __activity__ diagrams;
endif
stop
@enduml

2016061005.png

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

2016061006.png

4.4 Repeat loop

@startuml
start
repeat
:read data;
:generate diagrams;
repeat while (more data?)
stop
@enduml

2016061007.png

4.5 While loop

@startuml
start
while (data available?)
:read data;
:generate diagrams;
endwhile
stop
@enduml

2016061008.png

使用lable和is关键字

@startuml
while (check filesize ?) is (not empty)
:read file;
endwhile (empty)
:close file;
@enduml

2016061009.png

4.6 Parallel processing

@startuml
start
if (multiprocessor?) then (yes)
fork
:Treatment 1;
fork again
:Treatment 2;
end fork
else (monoproc)
:Treatment 1;
:Treatment 2;
endif
@enduml

2016061010.png

4.7 Notes

@startuml
start
:foo1;
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

2016061011.png

4.8 Title Legend

@startuml
title this is my title
if (condition?) then (yes)
:yes;
else (no)
:no;
note right
this is a note
end note
endif
stop
legend
this is the legend
endlegend
footer dummy footer
header
this is
a long __dummy__ header
end header
@enduml

2016061012.png

4.9 Colors

@startuml
start
:starting progress;
#HotPink:reading configuration files
These files should edited at this point!;
#AAAAAA:ending of the process;
@enduml

2016061013.png

4.10 Arrow

@startuml
:foo1;
-> You can put text on arrows;
if (test) then
-[#blue]->
:foo2;
-[#green]-> The text can
also be on several lines
and **very** long...;
:foo3;
else
-[#black]->
:foo4;
endif
-[#gray]->
:foo5;
@enduml

2016061014.png

4.11 Grouping

@startuml
start
partition Initialization {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
@enduml

2016061015.png

4.12 Swimlanes

@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml

2016061016.png

4.13 Detach

@startuml
:start;
fork
:foo1;
:foo2;
fork again
:foo3;
detach
endfork
if (foo4) then
:foo5;
detach
endif
:foo6;
detach
:foo7;
stop
@enduml

2016061017.png

4.14 SDL 通过改变最后的;分隔符,可以设置不同的Activity渲染图形

  • |
  • <
  • >
  • /
  • ]
  • }
@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

2016061018.png

4.15 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

2016061019.png

5 Component Diagram

5.1 Components

@startuml
[First component]
[Another component] as Comp2
component Comp3
component [Last\ncomponent] as Comp4
@enduml

2016081001.png

5.2 Interfaces

@startuml
() "First Interface"
() "Another interface" as Interf2
interface Interf3
interface "Last\ninterface" as Interf4
@enduml

2016081002.png

5.3 Basic example

Links between elements are made using combinations of dotted line (..), straight line (–), and arrows (–>) symbols.

@startuml
DataAccess - [First Component]
[First Component] ..> HTTP : use
@enduml

2016081003.png

5.4 Using notes

@startuml
interface "Data Access" as DA
DA - [First Component]
[First Component] ..> HTTP : use
note left of HTTP : Web Service only
note right of [First Component]
A note can also
be on several lines
end note
@enduml

2016081004.png

5.5 Grouping Components

@startuml
package "Some Group" {
HTTP - [First Component]
[Another Component]
}

node "Other Groups" {
FTP - [Second Component]
[First Component] --> FTP
}

cloud {
[Example 1]
}

database "MySql" {
    folder "This is my folder" {
        [Folder 3]
    }

    frame "Foo" {
        [Frame 4]
    }
}

[Another Component] --> [Example 1]
[Example 1] --> [Folder 3]
[Folder 3] --> [Frame 4]
@enduml

2016081005.png

5.6 Changing arrows direction

@startuml
[Component] --> Interface1
[Component] -> Interface2
@enduml

2016081006.png

@startuml
Interface1 <-- [Component]
Interface2 <- [Component]
@enduml

2016081007.png

@startuml
[Component] -left-> left
[Component] -right-> right
[Component] -up-> up
[Component] -down-> down
@enduml

2016081008.png

5.7 Title the diagram

You can use title and end title keywords for a longer title

@startuml
title Very simple component\ndiagram
interface "Data Access" as DA
DA - [First Component]
[First Component] ..> HTTP : use
@enduml

2016081009.png

5.8 Use UML2 notation

The skinparam componentStyle uml2 command is used to switch to UML2 notation

@startuml
skinparam componentStyle uml2
interface "Data Access" as DA
DA - [First Component]
[First Component] ..> HTTP : use
@enduml

2016081010.png

5.9 Individual colors

@startuml
component [Web Server] #Yellow
@enduml

2016081011.png

5.10 Skinparam

@startuml
skinparam component {
FontSize 13
InterfaceBackgroundColor RosyBrown
InterfaceBorderColor orange
BackgroundColor <<Apache >> Red
BorderColor <<Apache >> #FF6655
FontName Courier
BorderColor black
BackgroundColor gold
ArrowFontName Impact
ArrowColor #FF6655
ArrowFontColor #777777
}
() "Data Access" as DA
DA - [First Component]
[First Component] ..> () HTTP : use
HTTP - [Web Server] << Apache >>
@enduml

2016081012.png

@startuml
[AA] <<static lib>>
[BB] <<shared lib>>
[CC] <<static lib>>
node node1
node node2 <<shared node>>
database Production
skinparam component {
backgroundColor <<static lib>> DarkKhaki
backgroundColor <<shared lib>> Green
}
skinparam node {
borderColor Green
backgroundColor Yellow
backgroundColor <<shared node>> Magenta
}
skinparam databaseBackgroundColor Aqua
@enduml

2016081013.png

6 State Diagram

6.1 Simple State

@startuml
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string
State1 -> State2
State2 --> [*]
@enduml

2016081014.png

6.2 Composite state

@startuml
scale 350 width
[*] --> NotShooting
state NotShooting {
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
state Configuring {
[*] --> NewValueSelection
NewValueSelection --> NewValuePreview : EvNewValue
NewValuePreview --> NewValueSelection : EvNewValueRejected
NewValuePreview --> NewValueSelection : EvNewValueSaved
state NewValuePreview {
State1 -> State2
}
}
@enduml

2016081015.png

6.3 Long name

@startuml
scale 600 width
[*] -> State1
State1 --> State2 : Succeeded
State1 --> [*] : Aborted
State2 --> State3 : Succeeded
State2 --> [*] : Aborted
state State3 {
state "Accumulate Enough Data\nLong State Name" as long1
long1 : Just a test
[*] --> long1
long1 --> long1 : New Data
long1 --> ProcessData : Enough Data
}
State3 --> State3 : Failed
State3 --> [*] : Succeeded / Save Result
State3 --> [*] : Aborted
@enduml

2016081016.png

6.4 Concurrent state

@startuml
[*] --> Active
state Active {
[*] -> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] -> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] -> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
}
@enduml

2016081017.png

6.5 Arrow direction

@startuml
[*] -up-> First
First -right-> Second
Second --> Third
Third -left-> Last
@enduml

2016081018.png

6.6 Note

[*] --> Active
Active --> Inactive
note left of Active : this is a short\nnote
note right of Inactive
A note can also
be defined on
several lines
end note
@enduml

2016081019.png

floating notes:

@startuml
state foo
note "This is a floating note" as N1
@enduml

2016081020.png

6.7 More in notes

@startuml
[*] --> NotShooting
state "Not Shooting State" as NotShooting {
state "Idle mode" as Idle
state "Configuring mode" as Configuring
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
note right of NotShooting : This is a note on a composite state
@enduml

2016081021.png

6.8 Skinparam

@startuml
skinparam backgroundColor LightYellow
skinparam state {
StartColor MediumBlue
EndColor Red
BackgroundColor Peru
BackgroundColor <<Warning >> Olive
BorderColor Gray
FontName Impact
}
[*] --> NotShooting
state "Not Shooting State" as NotShooting {
state "Idle mode" as Idle <<Warning >>
state "Configuring mode" as Configuring
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
NotShooting --> [*]
@enduml

2016081022.png

7 Object Diagram

7.1 Definition of objects

@startuml
object firstObject
object "My Second Object" as o2
@enduml

2016081101.png

7.2 Relations between objects

Composition *– Aggregation o–

@startuml
object Object01
object Object02
object Object03
object Object04
object Object05
object Object06
object Object07
object Object08
Object01 <|-- Object02
Object03 *-- Object04
Object05 o-- "4" Object06
Object07 .. Object08 : some labels
@enduml

2016081102.png

7.3 Adding fields

@startuml
object user
user : name = "Dummy"
user : id = 123
@enduml

2016081103.png

or

@startuml
object user {
name = "Dummy"
id = 123
}
@enduml

2016081104.png

7.4 Common features with class diagrams

  • Visibility
  • Defines notes
  • Use packages
  • Title the diagram
  • Skin the output
  • Split the image

8 Common commands

8.1 Footer and header

@startuml
Alice -> Bob: Authentication Request
header
<font color=red >Warning:</font >
Do not use in production.
endheader
center footer Generated for demonstration
@enduml

2016081105.png

8.2 Zoom

@startuml
scale 180*90
Bob ->Alice : hello
@enduml

2016081106.png

10 Creole

定义文本样式

10.1 Emphasized text

@startuml
Alice -> Bob : hello --there --
... Some ~~ long delay ~~ ...
Bob -> Alice : ok
note left
This is ** bold **
This is // italics //
This is "" monospaced ""
This is --stroked --
This is __underlined__
This is ~~ waved ~~
end note
@enduml

2016081301.png

10.2 List

@startuml
object demo {
* Bullet list
* Second item
** Sub item
}
legend
# Numbered list
# Second item
## Sub item
## Another sub item
# Third item
end legend
@enduml

2016081302.png

10.3 Escape character

使用~转义字符

@startuml
object demo {
This is not ~___underscored__.
This is not ~"" monospaced "".
}
@enduml

2016081303.png

10.4 Horizontal lines

@startuml
database DB1 as "
You can have horizontal line
----
Or double line
====
Or strong line
____
Or dotted line
..My title ..
Enjoy!
"
note right
This is working also in notes
You can also add title in all these lines
== Title ==
--Another title --
end note
@enduml

2016081304.png

10.5 Headings

@startuml
usecase UC1 as "
= Extra -large heading
Some text
== Large heading
Other text
=== Medium heading
Information
....
==== Small heading"
@enduml

2016081305.png

10.6 Legacy HTML

Some HTML tags are also working:

  • <b> for bold text
  • <u> or <u:#AAAAAA> or <u:colorName> for underline
  • <i> for italic
  • <s> or <s:#AAAAAA> or <s:colorName> for strike text
  • <w> or <w:#AAAAAA> or <w:colorName> for wave underline text
  • <color:#AAAAAA> or <color:colorName>
  • <back:#AAAAAA> or <back:colorName> for background color
  • <size:nn> to change font size
  • <img:file> : the file must be accessible by the filesystem
  • <img:http://url> : the URL must be available from the Internet
@startuml
:* You can change <color:red >text color </color>
* You can change <back:cadetblue>background color </back>
* You can change <size:18>size </size>
* You use <u>legacy </u> <b>HTML <i>tag </i></b>
* You use <u:red >color </u> <s:green>in HTML </s> <w:#0000FF>tag </w>
----
* Use image : <img:/images/2016/2016081305.png>
;
@enduml

2016081306.png

10.7 Table

@startuml
skinparam titleFontSize 14
title
Example of simple table
|= |= table |= header |
| a | table | row |
| b | table | row |
end title
[*] --> State1
@enduml

2016081307.png

10.8 Tree

@startuml
skinparam titleFontSize 14
title
Example of Tree
|_ First line
|_ **Bom(Model )**
|_ prop1
|_ prop2
|_ prop3
|_ Last line
end title
[*] --> State1
@enduml

2016081308.png

10.9 Special characters

@startuml
usecase foo as "this is &#8734; long"
usecase bar as "this is also <U+221E> long"
@enduml

2016081309.png

10.10 OpenIconic

OpenIconic is an very nice open source icon set. You can use the following syntax: <&ICONNAME>.

@startuml
title: <size:20><&heart>Use of OpenIconic <&heart></size >
class Wifi
note left
Click on <&wifi>
end note
@enduml

2016081310.png

complete List of OpenIconic

@startuml
listopeniconic
@enduml

2016081311.png

10.11 Defining and using sprites(精灵)

A Sprite is a small graphic element that can be used in diagrams.

@startuml
sprite $foo1 {
FFFFFFFFFFFFFFF
F0123456789ABCF
F0123456789ABCF
F0123456789ABCF
F0123456789ABCF
F0123456789ABCF
F0123456789ABCF
F0123456789ABCF
F0123456789ABCF
FFFFFFFFFFFFFFF
}
Alice -> Bob : Testing <$foo1>
@enduml

2016081312.png

10.12 Encoding Sprite

To encode sprite, you can use the command line like:

java -jar plantuml.jar -encodesprite 16z foo.png

where foo.png if the image file you want to use (it will be converted to gray automatically) After -encodesprite, you have to specify a format: 4, 8, 16, 4z, 8z or 16z. The number indicates the gray level and the optionnal z is used to enable compression in definition.

10.13 Importing Sprite

You can also launch the GUI to generate a sprite from an existing image. Click in the menubar then on File/Open Sprite Window.

After copying an image into you clipboard, several possible definitions of the corresponding will be displayed : you will just have to pickup the one you want.

10.14 Examples

@startuml
sprite $printer [15x15/8z] NOtH3W0W208HxFz_kMAhj7lHWpa1XC716sz0Pq4MVPEWfBHIuxP3L6kbTcizR8tAhzaqFvXwvFfPEq
start
:click on <$printer> to print the page;
@enduml
@startuml
sprite $bug [15x15/16z] PKzR2i0m2BFMi15p__FEjQEqB1z27aeqCqixa8S4OT7C53cKpsHpaYPDJY_12MHM - BLRyywPhrrlw3qum
sprite $printer [15x15/8z] NOtH3W0W208HxFz_kMAhj7lHWpa1XC716sz0Pq4MVPEWfBHIuxP3L6kbTcizR8tAhzaqFvXwvFfPEq
sprite $disk {
444445566677881
436000000009991
43600000000ACA1
53700000001A7A1
53700000012B8A1
53800000123B8A1
63800001233C9A1
634999AABBC99B1
744566778899AB1
7456AAAAA99AAB1
8566AFC228AABB1
8567AC8118BBBB1
867BD4433BBBBB1
39AAAAABBBBBBC1
}
title Use of sprites (<$printer>, <$bug>...)
class Example {
Can have some bug : <$bug>
Click on <$disk> to save
}
note left : The printer <$printer> is available
@enduml

11 Changing fonts and colors

11.1 Usage

You can change colors and font of the drawing using the skinparam command.

skinparam backgroundColor yellow

11.2 Nested

To avoid repetition, it is possible to nest definition. So the following definition :

skinparam xxxxParam1 value1
skinparam xxxxParam2 value2
skinparam xxxxParam3 value3
skinparam xxxxParam4 value4

is strictly equivalent to:

skinparam xxxx {
Param1 value1
Param2 value2
Param3 value3
Param4 value4
}

11.3 Color

You can use either standard color name or RGB code.

2016081313.png

11.4 Font color, name and size

You can change the font for the drawing using xxxFontColor, xxxFontSize and xxxFontName parameters.

skinparam classFontColor red
skinparam classFontSize 10
skinparam classFontName Aapex

You can also change the default font for all fonts using skinparam defaultFontName.

skinparam defaultFontName Aapex

2016081314.png

2016081315.png

2016081316.png

11.5 Black and White

You can force the use of a black white output using the skinparam monochrome true command.

@startuml
skinparam monochrome true
actor User
participant "First Class" as A
participant "Second Class" as B
participant "Last Class" as C
User -> A: DoWork
activate A
A -> B: Create Request
activate B
B -> C: DoWork
activate C
C --> B: WorkDone
destroy C
B --> A: Request Created
deactivate B
A --> User: Done
deactivate A
@enduml

2016081317.png

12 Preprocessing

13 Internationalization

@startuml
skinparam backgroundColor #EEEBDC
actor 使用者
participant " 頭等艙 " as A
participant " 第二類 " as B
participant " 最後一堂課 " as 別的東西
使用者 -> A: 完成這項工作
activate A
A -> B: 創建請求
activate B
B -> 別的東西 : 創建請求
activate 別的東西
別的東西 --> B: 這項工作完成
destroy 別的東西
B --> A: 請求創建
deactivate B
A --> 使用者 : 做完
deactivate A
@enduml

2016081318.png

13.1 Charset

java -jar plantuml.jar -charset UTF-8 files.txt

14 Color Names

Here is the list of colors recognized by PlantUML. Note that color names are case insensitive.

2016081319.png