plantUML - Mud-H/TorqueLab GitHub Wiki
PlantUML is an Open Source project that allows to quickly write:
- Sequence diagram,
- Usecase diagram,
- Class diagram,
- Activity diagram,
- Component diagram,
- State diagram,
- Object diagram.
Diagrams are defined using a simple and intuitive language.
The sequence->is used to draw a message between two participants. Participants do not have to be explicitly declared. To have a dotted arrow, you use--> It is also possible to use<-and<--. That does not change the drawing, but may improve readability. Note that this is only true for sequence diagrams, rules are different for the other diagrams.
@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
It is possible to change participant order using theparticipantkeyword. It is also possible to use other keywords to declare a participant:
- actor
- boundary
- control
- entity
- database
@startuml
actor Foo
boundary Foo
control Foo
entity Foo
database Foo
collections Foo
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
Foo1 -> Foo6 : To collections
@enduml
1.2 Declaring participant 1 SEQUENCE DIAGRAM
You can rename a participant using theaskeyword. You can also change the background color of actor or participant.
@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 #99FF
/' You can also declare:
participant L as "I have a really\nlong name" #99FF
'/
Alice->Bob: Authentication Request
Bob->Alice: Authentication Response
Bob->L: Log transaction
@enduml
You can use theorderkeyword to custom the print order of participant.
@startuml
participant Last order 30
participant Middle order 20
participant First order 10
@enduml
1.3 Use non-letters in participants 1 SEQUENCE DIAGRAM
You can use quotes to define participants. And you can use theaskeyword to give an alias to those participants.
@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
A participant can send a message to itself. It is also possible to have multi-line using\n.
@startuml
Alice->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
@enduml
You can change arrow style by several ways:
- add a finalxto denote a lost message
- use\or/instead ofto have only the bottom or top part of the arrow
- repeat the arrow head (for example,>>or//) head to have a thin drawing
- use--instead of-to have a dotted arrow
- add a final ”o” at arrow head
- use bidirectional arrow
1.6 Change arrow color 1 SEQUENCE DIAGRAM
@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
You can change the color of individual arrows using the following notation:
@startuml
Bob -[#red]> Alice : hello
Alice -[#0000FF]->Bob : ok
@enduml
The keywordautonumberis used to automatically add number to messages.
@startuml
autonumber
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
@enduml
1.7 Message sequence numbering 1 SEQUENCE DIAGRAM
You can specify a startnumber withautonumber 'start', and also an increment withautonumber '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
You can specify a format for your number by using between double-quote. The formatting is done with the Java classDecimalFormat(’ 0 ’ means digit, ’#’ means digit and zero if absent). You can use some html tag in the format.
@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
1.8 Splitting diagrams 1 SEQUENCE DIAGRAM
You can also useautonumber stopandautonumber resume 'increment' 'format'to respectively pause and resume automatic numbering.
@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
Thenewpagekeyword is used to split a diagram into several images. You can put a title for the new page just after thenewpagekeyword. This is very handy with Word to print long diagram on several pages.
1.9 Grouping message 1 SEQUENCE DIAGRAM
@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
It is possible to group messages together using the following keywords:
- alt/else
- opt
- loop
- par
- break
- critical
- group, followed by a text to be displayed
1.10 Notes on messages 1 SEQUENCE DIAGRAM
It is possible a add a text that will be displayed into the header (except forgroup). Theendkeyword is used to close the group. Note that it is possible to nest groups.
@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
It is possible to put notes on message using thenote leftornote rightkeywords just after the message. You can have a multi-line note using theend notekeywords.
@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
1.11 Some other notes 1 SEQUENCE DIAGRAM
a note
can also be defined
on several lines
end note
@enduml
It is also possible to place notes relative to participant withnote left of,note right ofornote overkeywords. It is possible to highlight a note by changing its background color. You can also have a multi-line note using theend notekeywords.
@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
1.12 Changing notes shape 1 SEQUENCE DIAGRAM
You can usehnoteandrnotekeywords to change note shapes.
@startuml
caller -> server : conReq
hnote over caller : idle
caller <- server : conConf
rnote over server
"r" as rectangle
"h" as hexagon
endrnote
@enduml
It is also possible to use creole formatting:
@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__
1.14 Divider 1 SEQUENCE DIAGRAM
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
If you want, you can split a diagram using==separator to divide your diagram into logical steps.
@startuml
== Initialization ==
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
== Repetition ==
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
1.15 Reference 1 SEQUENCE DIAGRAM
You can use reference in a diagram, using the keywordref 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
You can use...to indicate a delay in the diagram. And it is also possible to put a message with this delay.
@startuml
Alice -> Bob: Authentication Request
...
Bob --> Alice: Authentication Response
1.17 Space 1 SEQUENCE DIAGRAM
...5 minutes latter...
Bob --> Alice: Bye!
@enduml
You can use|||to indicate some spacing in the diagram. It is also possible to specify a number of pixel to be used.
@startuml
Alice -> Bob: message 1
Bob --> Alice: ok
|||
Alice -> Bob: message 2
Bob --> Alice: ok
||45||
Alice -> Bob: message 3
Bob --> Alice: ok
@enduml
Theactivateanddeactivateare used to denote participant activation. Once a participant is activated, its lifeline appears. Theactivateanddeactivateapply on the previous message. Thedestroydenote the end of the lifeline of a participant.
1.18 Lifeline Activation and Destruction 1 SEQUENCE DIAGRAM
@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
Nested lifeline can be used, and it is possible to add a color on the lifeline.
@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
1.19 Participant creation 1 SEQUENCE DIAGRAM
You can use thecreatekeyword just before the first reception of a message to emphasize the fact that this message is actually creating this new object.
@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
You can use incoming or outgoing arrows if you want to focus on a part of the diagram. Use square brackets to denote the left ”[” or the right ”]” side of the diagram.
@startuml
[-> A: DoWork
activate A
A -> A: Internal call
activate A
A ->] : << createRequest >>
1.21 Stereotypes and Spots 1 SEQUENCE DIAGRAM
A<--] : RequestCreated
deactivate A
[<- A: Done
deactivate A
@enduml
You can also have the following syntax:
@startuml
[-> Bob
[o-> Bob
[o->o Bob
[x-> Bob
[<- Bob
[x<- Bob
Bob ->]
Bob ->o]
Bob o->o]
Bob ->x]
Bob <-]
Bob x<-]
@enduml
It is possible to add stereotypes to participants using<>. In the stereotype, you can add a spotted character in a colored circle using the syntax(X,color).
@startuml
participant "Famous Bob" as Bob << Generated >>
participant Alice << (C,#ADD1B2) Testable >>
1.22 More information on titles 1 SEQUENCE DIAGRAM
Bob->Alice: First message
@enduml
By default, the guillemet character is used to display the stereotype. You can change this behavious using the skinparamguillemet:
@startuml
skinparam guillemet false
participant "Famous Bob" as Bob << Generated >>
participant Alice << (C,#ADD1B2) Testable >>
Bob->Alice: First message
@enduml
@startuml
participant Bob << (C,#ADD1B2) >>
participant Alice << (C,#ADD1B2) >>
Bob->Alice: First message
@enduml
You can use creole formatting in the title.
@startuml
title __Simple__ **communication** example
Alice -> Bob: Authentication Request
Bob -> Alice: Authentication Response
@enduml
1.22 More information on titles 1 SEQUENCE DIAGRAM
You can add newline using\nin the title description.
@startuml
title __Simple__ communication example\non several lines
Alice -> Bob: Authentication Request
Bob -> Alice: Authentication Response
@enduml
You can also define title on several lines usingtitleandend titlekeywords.
@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
1.23 Participants encompass 1 SEQUENCE DIAGRAM
It is possible to draw a box around some participants, usingboxandend boxcommands. You can add an optional title or a optional background color, after theboxkeyword.
@startuml
box "Internal Service" #LightBlue
participant Bob
participant Alice
end box
participant Other
Bob -> Alice : hello
Alice -> Other : hello
@enduml
You can use thehide footboxkeywords to remove the footer of the diagram.
@startuml
hide footbox
title Footer removed
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml
You can use theskinparamcommand to change colors and fonts for the drawing. You can use this command:
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task. You can also change other rendering parameter, as seen in the following examples:
1.25 Skinparam 1 SEQUENCE DIAGRAM
@startuml
skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam maxmessagesize 60
skinparam sequenceParticipant underline
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
@startuml
skinparam backgroundColor #EEEBDC
skinparam handwritten true
skinparam sequence {
ArrowColor DeepSkyBlue
ActorBorderColor DeepSkyBlue
LifeLineBorderColor blue
LifeLineBackgroundColor #A9DCDF
ParticipantBorderColor DeepSkyBlue
ParticipantBackgroundColor DodgerBlue
ParticipantFontName Impact
ParticipantFontSize 17
1.26 Changing padding 1 SEQUENCE DIAGRAM
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
It is possible to tune some padding settings.
@startuml
skinparam ParticipantPadding 20
skinparam BoxPadding 10
box "Foo1"
participant Alice1
participant Alice2
end box
box "Foo2"
participant Bob1
participant Bob2
1.26 Changing padding 1 SEQUENCE DIAGRAM
end box
Alice1 -> Bob1 : hello
Alice1 -> Out : out
@enduml
Use cases are enclosed using between parentheses (because two parentheses looks like an oval). You can also use theusecasekeyword to define a usecase. And you can define an alias, using theas keyword. This alias will be used latter, when defining relations.
@startuml
(First usecase)
(Another usecase) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml
Actor are enclosed using between two points. You can also use theactorkeyword to define an actor. And you can define an alias, using theas keyword. This alias will be used latter, when defining relations. We will see later that the actor definitions are optional.
@startuml
:First Actor:
:Another\nactor: as Men2
actor Men3
actor :Last actor: as Men4
@enduml
If you want to have description on several lines, you can use quotes. You can also use the following separators:-- .. == __. And you can put titles within the separators.
2.4 Basic example 2 USE CASE DIAGRAM
@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
To link actors and use cases, the arrow-->is used. The more dashes"-"in the arrow, the longer the arrow. You can add a label on the arrow, by adding a ”:” character in the arrow definition. In this example, you see that User has not been defined before, and is used as an actor.
@startuml
User -> (Start)
User --> (Use the application) : A small label
:Main Admin: ---> (Use the application) : This is\nyet another\nlabel
@enduml
If one actor/use case extends another one, you can use the symbol<|--(which stands for).
2.6 Using notes 2 USE CASE DIAGRAM
@startuml
:Main Admin: as Admin
(Use the application) as (Use)
User <|-- Admin
(Start) <|-- (Use)
@enduml
You can use thenote left of,note right of,note top of,note bottom ofkeywords to define notes related to a single object. A note can be also define alone with thenotekeywords, then linked to other objects using the.. symbol.
@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
2.7 Stereotypes 2 USE CASE DIAGRAM
You can add stereotypes while defining actors and use cases using ”<<” and ”>>”.
@startuml
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml
By default, links between classes have two dashes--and are vertically oriented. It is possible to use horizontal link by putting a single dash (or dot) like this:
@startuml
:user: --> (Use case 1)
:user: -> (Use case 2)
@enduml
2.8 Changing arrows direction 2 USE CASE DIAGRAM
You can also change directions by reversing the link:
@startuml
(Use case 1) <.. :user:
(Use case 2) <- :user:
@enduml
It is also possible to change arrow direction by addingleft,right,upordownkeywords inside the arrow:
@startuml
:user: -left-> (dummyLeft)
:user: -right-> (dummyRight)
:user: -up-> (dummyUp)
:user: -down-> (dummyDown)
@enduml
You can shorten the arrow by using only the first character of the direction (for example,-d-instead of-down-) or the two first characters (-do-). Please note that you should not abuse this functionality : Graphviz gives usually good results without tweaking.
2.9 Splitting diagrams 2 USE CASE DIAGRAM
Thenewpagekeywords to split your diagram into several pages or images.
@startuml
:actor1: --> (Usecase1)
newpage
:actor2: --> (Usecase2)
@enduml
The general default behavior when building diagram is top to bottom.
@startuml
'default
top to bottom direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
You may change to left to right using theleft to right directioncommand. The result is often better with this direction.
@startuml
left to right direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
2.11 Skinparam 2 USE CASE DIAGRAM
You can use theskinparamcommand to change colors and fonts for the drawing. You can use this command :
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task. You can define specific color and fonts for stereotyped actors and usecases.
@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
2.12 Complete example 2 USE CASE DIAGRAM
@startuml
left to right direction
skinparam packageStyle rectangle
actor customer
actor clerk
rectangle checkout {
customer -- (checkout)
(checkout) .> (payment) : include
(help) .> (checkout) : extends
(checkout) -- clerk
}
@enduml
Relations between classes are defined using the following symbols : Extension <|-- Composition *-- Aggregation o-- It is possible to replace--by..to have a dotted line. Knowing those rules, it is possible to draw the following drawings:
@startuml
Class01 <|-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
@enduml
@startuml
Class11 <|.. Class12
Class13 --> Class14
Class15 ..> Class16
Class17 ..|> Class18
Class19 <--* Class20
@enduml
@startuml
Class21 #-- Class22
Class23 x-- Class24
Class25 }-- Class26
Class27 +-- Class28
Class29 ^-- Class30
@enduml
3.2 Label on relations 3 CLASS DIAGRAM
It is possible a add a label on the relation, using ”:”, followed by the text of the label.
For cardinality, you can use double-quotes""on each side of the relation.
@startuml
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
Class05 --> "1" Class06
@enduml
You can add an extra arrow pointing at one object showing which object acts on the other object, usingat the begin or at the end of the label.
@startuml
class Car
Driver - Car : drives >
Car *- Wheel : have 4 >
Car -- Person : < owns
@enduml
3.3 Adding methods 3 CLASS DIAGRAM
To declare fields and methods, you can use the symbol":"followed by the field’s or method’s name.
The system checks for parenthesis to choose between methods and fields.
@startuml
Object <|-- ArrayList
Object : equals()
ArrayList : Object[] elementData
ArrayList : size()
@enduml
It is also possible to group between brackets{}all fields and methods.
Note that the syntax is highly flexible about type/name order.
@startuml
class Dummy {
String data
void methods()
}
class Flight {
flightNumber : Integer
departureTime : Date
}
@enduml
You can use{field}and{method}modifiers to override default behaviour of the parser about fields and methods.
@startuml
class Dummy {
{field} A field (despite parentheses)
{method} Some method
}
@enduml
3.4 Defining visibility 3 CLASS DIAGRAM
When you define methods or fields, you can use characters to define the visibility of the corresponding
item:
- private
̃ package private
- public
@startuml
class Dummy {
-field1
#field2
~method1()
+method2()
}
@enduml
You can turn off this feature using theskinparam classAttributeIconSize 0command :
@startuml
skinparam classAttributeIconSize 0
class Dummy {
-field1
#field2
~method1()
+method2()
}
@enduml
3.5 Abstract and Static 3 CLASS DIAGRAM
You can define static or abstract methods or fields using the{static}or{abstract}modifier.
These modifiers can be used at the start or at the end of the line. You can also use{classifier}
instead of{static}.
@startuml
class Dummy {
{static} String id
{abstract} void methods()
}
@enduml
3.6 Advanced class body 3 CLASS DIAGRAM
By default, methods and fields are automatically regrouped by PlantUML. You can use separators to
define your own way of ordering fields and methods. The following separators are possible :-- ..
== __.
You can also use titles within the separators:
@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
3.7 Notes and stereotypes 3 CLASS DIAGRAM
Stereotypes are defined with theclasskeyword, ”<<” and ”>>”.
You can also define notes usingnote left of,note right of,note top of,note bottom of
keywords.
You can also define a note on the last defined class usingnote left,note right,note top,note
bottom.
A note can be also define alone with thenotekeywords, then linked to other objects using the..
symbol.
@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
3.8 More on notes 3 CLASS DIAGRAM
It is also possible to use few html tags like :
,,- or
- color:#AAAAAAorcolor:colorName
- size:nnto change font size
-
orimg:file: the file must be accessible by the filesystem You can also have a note on several lines. You can also define a note on the last defined class usingnote left,note right,note top,note bottom.
@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
3.9 Note on links 3 CLASS DIAGRAM
It is possible to add a note on a link, just after the link definition, usingnote on link.
You can also usenote left on link,note right on link,note top on link,note bottom on
linkif you want to change the relative position of the note with the label.
@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
3.10 Abstract class and interface 3 CLASS DIAGRAM
You can declare a class as abstract using"abstract"or"abstract class"keywords.
The class will be printed in italic.
You can use theinterface,annotationandenumkeywords too.
@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
3.11 Using non-letters 3 CLASS DIAGRAM
If you want to use non-letters in the class (or enum...) display, you can either :
- Use theaskeyword in the class definition
- Put quotes""around the class name
@startuml
class "This is my class" as class1
class class2 as "It works this way too"
class2 *-- "foo/dummy" : use
@enduml
3.12 Hide attributes, methods... 3 CLASS DIAGRAM
You can parameterize the display of classes using thehide/showcommand.
The basic command is:hide empty members. This command will hide attributes or methods if
they are empty.
Instead ofempty members, you can use:
- empty fieldsorempty attributesfor empty fields,
- empty methodsfor empty methods,
- fieldsorattributeswhich will hide fields, even if they are described,
- methodswhich will hide methods, even if they are described,
- memberswhich will hide fields andmethods, even if they are described,
- circlefor the circled character in front of class name,
- stereotypefor the stereotype. You can also provide, just after thehideorshowkeyword:
- classfor all classes,
- interfacefor all interfaces,
- enumfor all enums,
- <>for classes which are stereotyped with foo1 ,
- an existing class name. You can use severalshow/hidecommands to define rules and exceptions.
@startuml
class Dummy1 {
+myMethods()
}
class Dummy2 {
+hiddenMethod()
}
class Dummy3 <<Serializable>> {
String name
}
hide members
hide <<Serializable>> circle
show Dummy1 methods
show <<Serializable>> fields
@enduml
3.13 Hide classes 3 CLASS DIAGRAM
You can also use theshow/hidecommands to hide classes.
This may be useful if you define a large !included file, and if you want to hide come classes after
file inclusion.
@startuml class Foo1 class Foo2 Foo2 *-- Foo1 hide Foo2 @enduml
You can also use bracket<and>to define generics usage in a class.
@startuml class Foo<? extends Element> { int size() } Foo *- Element @enduml
It is possible to disable this drawing usingskinparam genericDisplay oldcommand.
Usually, a spotted character (C, I, E or A) is used for classes, interface, enum and abstract classes.
But you can define your own spot for a class when you define the stereotype, adding a single
character and a color, like in this example:
@startuml class System << (S,#FF7700) Singleton >> class Date << (D,orchid) >> @enduml
3.16 Packages 3 CLASS DIAGRAM
You can define a package using thepackagekeyword, and optionally declare a background color
for your package (Using a html color code or name).
Note that package definitions can be nested.
@startuml package "Classic Collections" #DDDDDD { Object <|-- ArrayList } package net.sourceforge.plantuml { Object <|-- Demo1 Demo1 *- Demo2 } @enduml
There are different styles available for packages.
You can specify them either by setting a default style with the command :skinparam packageStyle,
or by using a stereotype on the package:
@startuml scale 750 width package foo1 <> { class Class1 } package foo2 <> { class Class2 } package foo3 <> { class Class3 } package foo4 <> { class Class4 } package foo5 <> { class Class5 } package foo6 <> { class Class6 } @enduml
3.18 Namespaces 3 CLASS DIAGRAM
You can also define links between packages, like in the following example:
@startuml skinparam packageStyle rectangle package foo1.foo2 { } package foo1.foo2.foo3 { class Object } foo1.foo2 +-- foo1.foo2.foo3 @enduml
In packages, the name of a class is the unique identifier of this class. It means that you cannot have
two classes with the very same name in different packages.
In that case, you should use namespaces instead of packages.
You can refer to classes from other namespaces by fully qualify them. Classes from the default
namespace are qualified with a starting dot.
Note that you don’t have to explicitly create namespace : a fully qualified class is automatically
put in the right namespace.
@startuml class BaseClass namespace net.dummy #DDDDDD { .BaseClass <|-- Person Meeting o-- Person .BaseClass <|- Meeting } namespace net.foo { net.dummy.Person <|- Person .BaseClass <|-- Person
3.19 Automatic namespace creation 3 CLASS DIAGRAM
net.dummy.Meeting o-- Person } BaseClass <|-- net.unused.Person @enduml
You can define another separator (other than the dot) using the command :set namespaceSeparator
???.
@startuml set namespaceSeparator :: class X1::X2::foo { some info } @enduml
You can disable automatic package creation using the commandset namespaceSeparator none.
@startuml set namespaceSeparator none class X1.X2.foo { some info } @enduml
3.20 Lollipop interface 3 CLASS DIAGRAM
You can also define lollipops interface on classes, using the following syntax:
- bar ()- foo
- bar ()-- foo
- foo -() bar
@startuml
class foo
bar ()- foo
@enduml
By default, links between classes have two dashes--and are vertically oriented. It is possible to
use horizontal link by putting a single dash (or dot) like this:
@startuml Room o- Student Room *-- Chair @enduml
You can also change directions by reversing the link:
@startuml Student -o Room Chair --* Room @enduml
It is also possible to change arrow direction by addingleft,right,upordownkeywords inside the
arrow:
3.22 Association classes 3 CLASS DIAGRAM
@startuml foo -left-> dummyLeft foo -right-> dummyRight foo -up-> dummyUp foo -down-> dummyDown @enduml
You can shorten the arrow by using only the first character of the direction (for example,-d-
instead of-down-) or the two first characters (-do-).
Please note that you should not abuse this functionality : Graphviz gives usually good results
without tweaking.
You can define association class after that a relation has been defined between two classes, like in
this example:
@startuml class Student { Name } Student "0.." - "1.." Course (Student, Course) .. Enrollment class Enrollment { drop() cancel() } @enduml
You can define it in another direction:
3.23 Skinparam 3 CLASS DIAGRAM
@startuml class Student { Name } Student "0.." -- "1.." Course (Student, Course). Enrollment class Enrollment { drop() cancel() } @enduml
You can use theskinparamcommand to change colors and fonts for the drawing.
You can use this command :
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task.
@startuml
skinparam class {
BackgroundColor PaleGreen
ArrowColor SeaGreen
BorderColor SpringGreen
}
skinparam stereotypeCBackgroundColor YellowGreen
Class01 "1" *-- "many" Class02 : contains
Class03 o-- Class04 : aggregation
@enduml
3.24 Skinned Stereotypes 3 CLASS DIAGRAM
You can define specific color and fonts for stereotyped classes.
@startuml skinparam class { BackgroundColor PaleGreen ArrowColor SeaGreen BorderColor SpringGreen BackgroundColor<> Wheat BorderColor<> Tomato } skinparam stereotypeCBackgroundColor YellowGreen skinparam stereotypeCBackgroundColor << Foo >> DimGray Class01 <> Class03 <> Class01 "1" *-- "many" Class02 : contains Class03 o-- Class04 : aggregation @enduml
It’s possible to declare individual color for classes or note using the notation.
You can use either standard color name or RGB code.
You can also use color gradient in background, with the following syntax: two colors names separated
either by:
- |,
- /,
- ,
- or- depending the direction of the gradient. For example, you could have:
3.26 Help on layout 3 CLASS DIAGRAM
@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
Sometimes, the default layout is not perfect...
You can usetogetherkeyword to group some classes together : the layout engine will try to group
them (as if they were in the same package).
You can also usehiddenlinks to force the layout.
@startuml class Bar1 class Bar2 together { class Together1 class Together2 class Together3 } Together1 - Together2 Together2 - Together3 Together2 -[hidden]--> Bar1 Bar1 -[hidden]> Bar2
@enduml
3.27 Splitting large files 3 CLASS DIAGRAM
Sometimes, you will get some very large image files.
You can use the ”page (hpages)x(vpages)” command to split the generated image into several
files :
hpagesis a number that indicated the number of horizontal pages, andvpagesis a number that
indicated the number of vertical pages.
You can also use some specific skinparam settings to put borders on splitted pages (see example).
@startuml ' Split into 4 pages page 2x2 skinparam pageMargin 10 skinparam pageExternalColor gray skinparam pageBorderColor black 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
3.27 Splitting large files 3 CLASS DIAGRAM
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 Activity"
"First 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 Activity"
-->[You can put also labels] "Second Activity"
--> (*)
@enduml
You can use->for horizontal arrows. It is possible to force arrow’s direction using the following syntax:
- -down->(default arrow)
4.4 Branches 4 ACTIVITY DIAGRAM
- -right->or->
- -left->
- -up->
@startuml
(*) -up-> "First Activity"
-right-> "Second Activity"
--> "Third Activity"
-left-> (*)
@enduml
You can useif/then/elsekeywords to define branches.
@startuml () --> "Initialization" if "Some Test" then -->[true] "Some Activity" --> "Another activity" -right-> () else ->[false] "Something else" -->[Ending process] (*) endif @enduml
Unfortunately, you will have to sometimes repeat the same activity in the diagram text:
4.5 More on Branches 4 ACTIVITY DIAGRAM
@startuml () --> "check input" If "input is verbose" then --> [Yes] "turn on verbosity" --> "run command" else --> "run command" 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 theifkeywords.
It is also possible to nest branches.
@startuml (*) --> if "Some Test" then -->[true] "activity 1" if "" then -> "activity 3" as a3 else if "Other test" then -left-> "activity 5" else --> "activity 6" endif endif else ->[false] "activity 2" endif a3 --> if "last test" then --> "activity 7" else -> "activity 8"
4.6 Synchronization 4 ACTIVITY DIAGRAM
endif @enduml
You can use=== code ===to display synchronization bars.
@startuml () --> ===B1=== --> "Parallel Activity 1" --> ===B2=== ===B1=== --> "Parallel Activity 2" --> ===B2=== --> () @enduml
4.7 Long activity description 4 ACTIVITY DIAGRAM
When you declare activities, you can span on several lines the description text. You can also add
\nin the description.
You can also give a short code to the activity with theaskeyword. This code can be used latter
in the diagram description.
@startuml (*) -left-> "this size:20activity is very color:redlong2 and defined on several lines that contains many text" as A1 -up-> "Another activity\n on several lines" A1 --> "Short activity img:sourceforge.jpg" @enduml
You can add notes on a activity using the commandsnote left,note right,note topornote
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 theendnotekeywords.
@startuml () --> "Some Activity" note right: This activity has to be defined "Some Activity" --> () note left This note is on several lines end note @enduml
4.9 Partition 4 ACTIVITY DIAGRAM
You can define a partition using thepartitionkeyword, 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
4.10 Skinparam 4 ACTIVITY DIAGRAM
You can use theskinparamcommand to change colors and fonts for the drawing.
You can use this command :
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task. 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
--> (*)
4.11 Octagon 4 ACTIVITY DIAGRAM
@enduml
You can change the shape of activities to octagon using theskinparam activityShape octagon
command.
@startuml 'Default is skinparam activityShape roundBox skinparam activityShape octagon () --> "First Activity" "First Activity" --> () @enduml
@startuml title Servlet Container (*) --> "ClickServlet.handleRequest()" --> "new Page" if "Page.onSecurityCheck" then ->[true] "Page.onInit()"
4.12 Complete example 4 ACTIVITY DIAGRAM
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
4.12 Complete example 4 ACTIVITY DIAGRAM
Current syntax for activity diagram has several limitations and drawbacks (for example, it’s difficult to maintain). So a completely new syntax and implementation is proposed as beta version to users (starting with V7947), so that we could define a better format and syntax. Another advantage of this new implementation is that it’s done without the need of having Graphviz installed (as for sequence diagrams). The new syntax will replace the old 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.
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 on defined on
several **lines**;
@enduml
You can usestartandstopkeywords to denote the beginning and the end of a diagram.
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml
You can also use theendkeyword.
5.3 Conditional 5 ACTIVITY DIAGRAM (BETA)
@startuml start :Hello world; :This is on defined on several lines; end @enduml
You can useif,thenandelsekeywords to put tests if your diagram. Labels can be provided
using parentheses.
@startuml start if (Graphviz installed?) then (yes) :process all\ndiagrams; else (no) :process only sequence and activity diagrams; endif stop @enduml
You can use theelseifkeyword to have several tests :
@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)
5.4 Repeat loop 5 ACTIVITY DIAGRAM (BETA)
:Text 4; else (nothing) :Text else; endif stop @enduml
You can userepeatandrepeatwhilekeywords to have repeat loops.
@startuml start repeat :read data; :generate diagrams; repeat while (more data?) stop @enduml
You can usewhileandend whilekeywords to have repeat loops.
@startuml start
5.6 Parallel processing 5 ACTIVITY DIAGRAM (BETA)
while (data available?) :read data; :generate diagrams; endwhile stop @enduml
It is possible to provide a label after theendwhilekeyword, or using theiskeyword.
@startuml while (check filesize ?) is (not empty) :read file; endwhile (empty) :close file; @enduml
You can usefork,fork againandend forkkeywords to denote 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
5.7 Notes 5 ACTIVITY DIAGRAM (BETA)
Text formatting can be done using creole wiki syntax.
A note can be floating, usingfloatingkeyword.
@startuml start :foo1; floating note left: This is a note :foo2; note right This note is on several //lines// and can contain HTML
- Calling the method ""foo()"" is prohibited end note stop @enduml
You can use specify a color for some activities.
@startuml start :starting progress; #HotPink:reading configuration files These files should edited at this point!; #AAAAAA:ending of the process; @enduml
5.9 Arrows 5 ACTIVITY DIAGRAM (BETA)
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
You can use parentheses to denote connector.
@startuml start :Some activity; (A)
5.11 Grouping 5 ACTIVITY DIAGRAM (BETA)
detach (A) :Other activity; @enduml
You can group activity together by defining partition:
@startuml start partition Initialization { :read config file; :init internal variable; } partition Running { :wait for user interaction; :print information; } stop @enduml
Using pipe|, you can define swimlanes.
5.13 Detach 5 ACTIVITY DIAGRAM (BETA)
It’s also possible to change swimlanes color.
@startuml |Swimlane1| start :foo1; |#AntiqueWhite|Swimlane2| :foo2; :foo3; |Swimlane1| :foo4; |Swimlane2| :foo5; stop @enduml
It’s possible to remove an arrow using thedetachkeyword.
@startuml :start; fork :foo1; :foo2; fork again :foo3; detach endfork if (foo4) then :foo5; detach endif :foo6; detach :foo7; stop @enduml
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 line|
:i := i + 1]
:ack(o)>
split again
:err(i)<
:nak(o)>
split again
:foo/
split again
:i > 5}
stop
end split
:finish;
@enduml
5.15 Complete example 5 ACTIVITY DIAGRAM (BETA)
@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
5.15 Complete example 5 ACTIVITY DIAGRAM (BETA)
Components must be bracketed. You can also use thecomponentkeyword to defines a component. And you can define an alias, using theaskeyword. This alias will be used latter, when defining relations.
@startuml
[First component]
[Another component] as Comp2
component Comp3
component [Last\ncomponent] as Comp4
@enduml
Interface can be defined using the()symbol (because this looks like a circle). You can also use theinterfacekeyword to defines an interface. And you can define an alias, using theaskeyword. This alias will be used latter, when defining relations. We will see latter that interface definition is optional.
@startuml
() "First Interface"
() "Another interface" as Interf2
interface Interf3
interface "Last\ninterface" as Interf4
@enduml
Links between elements are made using combinations of dotted line (..), straight line (--), and arrows (-->) symbols.
6.4 Using notes 6 COMPONENT DIAGRAM
@startuml DataAccess - [First Component] [First Component] ..> HTTP : use @enduml
You can use thenote left of,note right of,note top of,note bottom ofkeywords to
define notes related to a single object.
A note can be also define alone with thenotekeywords, then linked to other objects using the..
symbol.
@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
You can use several keywords to group components and interfaces together:
- package
- node
6.5 Grouping Components 6 COMPONENT DIAGRAM
- folder
- frame
- cloud
- database
@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
6.6 Changing arrows direction 6 COMPONENT DIAGRAM
By default, links between classes have two dashes--and are vertically oriented. It is possible to
use horizontal link by putting a single dash (or dot) like this:
@startuml [Component] --> Interface1 [Component] -> Interface2 @enduml
You can also change directions by reversing the link:
@startuml Interface1 <-- [Component] Interface2 <- [Component] @enduml
6.7 Use UML2 notation 6 COMPONENT DIAGRAM
It is also possible to change arrow direction by addingleft,right,upordownkeywords inside the
arrow:
@startuml [Component] -left-> left [Component] -right-> right [Component] -up-> up [Component] -down-> down @enduml
You can shorten the arrow by using only the first character of the direction (for example,-d-
instead of-down-) or the two first characters (-do-).
Please note that you should not abuse this functionality : Graphviz gives usually good results
without tweaking.
Theskinparam componentStyle uml2command is used to switch to UML2 notation.
@startuml skinparam componentStyle uml2 interface "Data Access" as DA DA - [First Component] [First Component] ..> HTTP : use @enduml
6.8 Long description 6 COMPONENT DIAGRAM
It is possible to put description on several lines using square brackets.
@startuml component comp1 [ This component has a long comment on several lines ] @enduml
You can specify a color after component definition.
@startuml component [Web Server] #Yellow @enduml
You can use sprites within stereotype components.
@startuml sprite $businessProcess [16x16/16] { FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFF0FFFFF FFFFFFFFFF00FFFF FF00000000000FFF FF000000000000FF FF00000000000FFF FFFFFFFFFF00FFFF FFFFFFFFFF0FFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
6.11 Skinparam 6 COMPONENT DIAGRAM
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF }
rectangle " End to End\nbusiness process" <<$businessProcess>> { rectangle "inner process 1" <<$businessProcess>> as src rectangle "inner process 2" <<$businessProcess>> as tgt src -> tgt } @enduml
You can use theskinparamcommand to change colors and fonts for the drawing.
You can use this command :
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task. You can define specific color and fonts for stereotyped components and interfaces.
@startuml
skinparam interface {
backgroundColor RosyBrown
borderColor orange
}
skinparam component {
FontSize 13
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
6.11 Skinparam 6 COMPONENT DIAGRAM
@startuml [AA] <> [BB] <> [CC] <> node node1 node node2 <> database Production skinparam component { backgroundColor<> DarkKhaki backgroundColor<> Green } skinparam node { borderColor Green backgroundColor Yellow backgroundColor<> Magenta } skinparam databaseBackgroundColor Aqua @enduml
You can use[*]for the starting point and ending point of the state diagram. Use-->for arrows.
@startuml
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string
State1 -> State2
State2 --> [*]
@enduml
A state can also be composite. You have to define it using thestatekeywords and brackets.
@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
7.3 Long name 7 STATE DIAGRAM
You can also use thestatekeyword to use long description for states.
@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
7.4 Concurrent state 7 STATE DIAGRAM
You can define concurrent state into a composite state using either--or||symbol as separator.
@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
7.5 Arrow direction 7 STATE DIAGRAM
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
First -right-> Second
Second --> Third
Third -left-> Last
@enduml
7.6 Note 7 STATE DIAGRAM
You can shorten the arrow by using only the first character of the direction (for example,-d-
instead of-down-) or the two first characters (-do-).
Please note that you should not abuse this functionality : Graphviz gives usually good results
without tweaking.
You can also define notes usingnote left of,note right of,note top of,note bottom of
keywords.
You can also define notes on several lines.
@startuml [*] --> 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
You can also have floating notes.
@startuml state foo note "This is a floating note" as N1 @enduml
7.7 More in notes 7 STATE DIAGRAM
You can put notes on composite states.
@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
You can use theskinparamcommand to change colors and fonts for the drawing.
You can use this command :
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task. You can define specific color and fonts for stereotyped states.
@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 {
7.8 Skinparam 7 STATE DIAGRAM
state "Idle mode" as Idle <> state "Configuring mode" as Configuring [] --> Idle Idle --> Configuring : EvConfig Configuring --> Idle : EvConfig } NotShooting --> [] @enduml
You define instance of objects using theobjectkeywords.
@startuml
object firstObject
object "My Second Object" as o2
@enduml
Relations between objects are defined using the following symbols : Extension <|-- Composition *-- Aggregation o-- It is possible to replace--by..to have a dotted line. Knowing those rules, it is possible to draw the following drawings. It is possible a add a label on the relation, using ”:”, followed by the text of the label. For cardinality, you can use double-quotes""on each side of the relation.
@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
To declare fields, you can use the symbol":"followed by the field’s name.
@startuml
object user
user : name = "Dummy"
user : id = 123
@enduml
8.4 Common features with class diagrams 8 OBJECT DIAGRAM
It is also possible to ground between brackets{}all fields.
@startuml object user { name = "Dummy" id = 123 } @enduml
- Visibility
- Defines notes
- Use packages
- Skin the output
You can use the commandsheaderorfooterto add a footer or a header on any generated diagram. You can optionally specify if you want acenter,leftorrightfooter/header, by adding a keyword. As for title, it is possible to define a header or a footer on several lines. It is also possible to put some HTML into the header or footer.
@startuml
Alice -> Bob: Authentication Request
header
<font color=red>Warning:</font>
Do not use in production.
endheader
center footer Generated for demonstration
@enduml
You can use thescalecommand to zoom the generated image. You can use either a number or a fraction to define the scale factor. You can also specify either width or height (in pixel). And you can also give both width and height : the image is scaled to fit inside the specified dimension.
- scale 1.5
- scale 2/3
- scale 200 width
- scale 200 height
- scale 200*100
- scale max 300*200
@startuml
scale 180*90
Bob->Alice : hello
@enduml
Salt is a subproject included in PlantUML that may help you to design graphical interface. You can use either@startsaltkeyword, or``` @startumlfollowed by a line withsaltkeyword.
A window must start and end with brackets. You can then define:
- Button using[and].
- Radio button using(and).
- Checkbox using[and].
- User text area using".
@startuml
salt
{
Just plain text
[This is my button]
() Unchecked radio
(X) Checked radio
[] Unchecked box
[X] Checked box
"Enter text here "
^This is a droplist^
}
@enduml
The goal of this tool is to discuss about simple and sample windows.
A table is automatically created when you use an opening bracket{. And you have to use|to separate columns. For example: @startsalt { Login | "MyName " Password | "**** " [Cancel] | [ OK ] } @endsalt
10.3 Using separator 10 SALT
Just after the opening bracket, you can use a character to define if you want to draw lines or columns
of the grid :
#To display all vertical and horizontal lines
!To display all vertical lines
- To display all horizontal lines +To display external lines @startsalt {+ Login | "MyName " Password | "**** " [Cancel] | [ OK ] } @endsalt
You can use several horizontal lines as separator.
@startsalt
{
Text1
..
"Some field"
==
Note on usage
~~
Another text
--
[Ok]
}
@endsalt
To have a Tree, you have to start with{Tand to use+to denote hierarchy.
@startsalt
{
{T
+ World
++ America
+++ Canada
+++ USA
++++ New York
++++ Boston
+++ Mexico
++ Europe
+++ Italy
+++ Germany
10.5 Enclosing brackets 10 SALT
++++ Berlin
++ Africa
}
}
@endsalt
You can define subelements by opening a new opening bracket.
@startsalt
{
Name | " "
Modifiers: | { (X) public | () default | () private | () protected
[] abstract | [] final | [] static }
Superclass: | { "java.lang.Object " | [Browse...] }
}
@endsalt
You can add tabs using{/notation. Note that you can use HTML code to have bold text.
@startsalt
{+
{/ <b>General | Fullscreen | Behavior | Saving }
{
{ Open image in: | ^Smart Mode^ }
[X] Smooth images when zoomed
[X] Confirm image deletion
[ ] Show hidden images
}
[Close]
}
@endsalt
Tab could also be vertically oriented:
10.7 Using menu 10 SALT
@startsalt
{+
{/ <b>General
Fullscreen
Behavior
Saving } |
{
{ Open image in: | ^Smart Mode^ }
[X] Smooth images when zoomed
[X] Confirm image deletion
[ ] Show hidden images
[Close]
}
}
@endsalt
You can add a menu by using{*notation.
@startsalt
{+
{* File | Edit | Source | Refactor }
{/ General | Fullscreen | Behavior | Saving }
{
{ Open image in: | ^Smart Mode^ }
[X] Smooth images when zoomed
[X] Confirm image deletion
[ ] Show hidden images
}
[Close]
}
@endsalt
It is also possible to open a menu:
@startsalt
{+
{* File | Edit | Source | Refactor
Refactor | New | Open File | - | Close | Close All }
{/ General | Fullscreen | Behavior | Saving }
{
{ Open image in: | ^Smart Mode^ }
[X] Smooth images when zoomed
[X] Confirm image deletion
[ ] Show hidden images
}
[Close]
}
@endsalt
10.8 Advanced table 10 SALT
You can use two special notations for table :
- *to indicate that a cell with span with left
- .to denotate an empty cell @startsalt {# . | Column 2 | Column 3 Row header 1 | value 1 | value 2 Row header 2 | A long cell | * } @endsalt
A light Creole engine have been integrated into PlantUML to have a standardized way of defining text style. All diagrams are now supporting this syntax. Note that ascending compatibility with HTML syntax is preserved.
@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
@startuml
object demo {
* Bullet list
* Second item
** Sub item
}
legend
# Numbered list
# Second item
## Sub item
## Another sub item
# Third item
end legend
@enduml
11.3 Escape character 11 CREOLE
You can use the tilde~to escape special creole characters.
@startuml object demo { This is not ~_underscored. This is not ~""monospaced"". } @enduml
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
@startuml usecase UC1 as " = Extra-large heading Some text == Large heading Other text === Medium heading Information .... ==== Small heading" @enduml
Some HTML tags are also working:
- for bold text
- or<u:#AAAAAA>or<u:colorName>for underline
- for italic
or<s:#AAAAAA>or<s:colorName>for strike text
11.7 Table 11 CREOLE
- or<w:#AAAAAA>or<w:colorName>for wave underline text
- color:#AAAAAAorcolor:colorName
- back:#AAAAAAorback:colorNamefor background color
- size:nnto 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:sourceforge.jpg>
;
@enduml
@startuml skinparam titleFontSize 14 title Example of simple table |= |= table |= header | | a | table | row | | b | table | row | end title [*] --> State1 @enduml
You can use|_characters to build a tree.
@startuml skinparam titleFontSize 14 title Example of Tree |_ First line |_ Bom(Model) |_ prop1 |_ prop2 |_ prop3 |_ Last line end title [*] --> State1 @enduml
It’s possible to use any unicode characters with&#syntax or<U+XXXX>
startuml
usecase foo as "this is ∞ long"
usecase bar as "this is also <U+221E> long"
enduml
11.10 OpenIconic 11 CREOLE
OpenIconic is an very nice open source icon set. Those icons have been integrated into the creole
parser, so you can use them out-of-the-box.
You can use the following syntax:<&ICON_NAME>.
@startuml title: size:20<&heart>Use of OpenIconic <&heart> class Wifi note left Click on <&wifi> end note @enduml
The complete list is available on OpenIconic Website, or you can use the following special diagram:
@startuml listopeniconic @enduml
11.11 Defining and using sprites 11 CREOLE
A Sprite is a small graphic element that can be used in diagrams.
In PlantUML, sprites are monochrome and can have either 4, 8 or 16 gray level.
To define a sprite, you have to use a hexadecimal digit between 0 and F per pixel.
Then you can use the sprite using<$XXX>where XXX is the name of the sprite.
@startuml sprite $foo1 { FFFFFFFFFFFFFFF F0123456789ABCF F0123456789ABCF F0123456789ABCF F0123456789ABCF F0123456789ABCF F0123456789ABCF F0123456789ABCF F0123456789ABCF FFFFFFFFFFFFFFF } Alice -> Bob : Testing <$foo1> @enduml
To encode sprite, you can use the command line like:
java -jar plantuml.jar -encodesprite 16z foo.png
wherefoo.pngif 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, 8zor16z.
The number indicates the gray level and the optionnalzis used to enable compression in sprite
definition.
You can also launch the GUI to generate a sprite from an existing image.
Click in the menubar then onFile/Open Sprite Window.
After copying an image into you clipboard, several possible definitions of the corresponding sprite
will be displayed : you will just have to pickup the one you want.
@startuml sprite $printer [15x15/8z] NOtH3W0W208HxFz_kMAhj7lHWpa1XC716sz0Pq4MVPEWfBHIuxP3L6kbTcizR8tAhzaqFvXwvFfPEqm0 start :click on <$printer> to print the page; @enduml
11.14 Examples 11 CREOLE
@startuml sprite $bug [15x15/16z] PKzR2i0m2BFMi15p__FEjQEqB1z27aeqCqixa8S4OT7C53cKpsHpaYPDJY_12MHM -BLRyywPhrrlw3qumqNThmXgd1TOterAZmOW8sgiJafogofWRwtV3nCF sprite $printer [15x15/8z] NOtH3W0W208HxFz_kMAhj7lHWpa1XC716sz0Pq4MVPEWfBHIuxP3L6kbTcizR8tAhzaqFvXwvFfPEqm0 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
You can change colors and font of the drawing using theskinparamcommand. Example: skinparam backgroundColor yellow
You can use this command :
- In the diagram definition, like any other commands,
- In an included file (see Preprocessing ),
- In a configuration file, provided in the command line or the ANT task.
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 }
12.3 Color 12 CHANGING FONTS AND COLORS
You can use either standard color name or RGB code.
Parameter name Default Color Comment
Value
backgroundColor white Background of the page
activityArrowColor #A80036 Color of arrows in activity diagrams
activityBackgroundColor #FEFECE Background of activities
activityBorderColor #A80036 Color of activity borders
activityStartColor black Starting circle in activity diagrams
activityEndColor black Ending circle in activity diagrams
activityBarColor black Synchronization bar in activity diagrams
usecaseArrowColor #A80036 Color of arrows in usecase diagrams
usecaseActorBackgroundColor #FEFECE Head’s color of actor in usecase diagrams
usecaseActorBorderColor #A80036 Color of actor borders in usecase diagrams
usecaseBackgroundColor #FEFECE Background of usecases
usecaseBorderColor #A80036 Color of usecase borders in usecase diagrams
classArrowColor #A80036 Color of arrows in class diagrams
classBackgroundColor #FEFECE Background of classes/interface/enum in class diagrams
classBorderColor #A80036 Borders of classes/interface/enum in class diagrams
packageBackgroundColor #FEFECE Background of packages in class diagrams
packageBorderColor #A80036 Borders of packages in class diagrams
stereotypeCBackgroundColor #ADD1B2 Background of class spots in class diagrams
stereotypeABackgroundColor #A9DCDF Background of abstract class spots in class diagrams
stereotypeIBackgroundColor #B4A7E5 Background of interface spots in class diagrams
stereotypeEBackgroundColor #EB937F Background of enum spots in class diagrams
componentArrowColor #A80036 Color of arrows in component diagrams
componentBackgroundColor #FEFECE Background of components
componentBorderColor #A80036 Borders of components
componentInterfaceBackgroundColor #FEFECE Background of interface in component diagrams
componentInterfaceBorderColor #A80036 Border of interface in component diagrams
noteBackgroundColor #FBFB77 Background of notes
noteBorderColor #A80036 Border of notes
stateBackgroundColor #FEFECE Background of states in state diagrams
stateBorderColor #A80036 Border of states in state diagrams
stateArrowColor #A80036 Colors of arrows in state diagrams
stateStartColor black Starting circle in state diagrams
stateEndColor black Ending circle in state diagrams
sequenceArrowColor #A80036 Color of arrows in sequence diagrams
sequenceActorBackgroundColor #FEFECE Head’s color of actor in sequence diagrams
sequenceActorBorderColor #A80036 Border of actor in sequence diagrams
sequenceGroupBackgroundColor #EEEEEE Header color of alt/opt/loop in sequence diagrams
sequenceLifeLineBackgroundColor white Background of life line in sequence diagrams
sequenceLifeLineBorderColor #A80036 Border of life line in sequence diagrams
sequenceParticipantBackgroundColor #FEFECE Background of participant in sequence diagrams
sequenceParticipantBorderColor #A80036 Border of participant in sequence diagrams
12.4 Font color, name and size 12 CHANGING FONTS AND COLORS
You can change the font for the drawing usingxxxFontColor,xxxFontSizeandxxxFontName
parameters.
Example:
skinparam classFontColor red
skinparam classFontSize 10
skinparam classFontName Aapex
You can also change the default font for all fonts usingskinparam defaultFontName.
Example:
skinparam defaultFontName Aapex
Please note the fontname is highly system dependent, so do not over use it, if you look for portability.
Parameter Default Comment
Name Value
activityFontColor black
activityFontSizeactivityFontStyle plain (^14) Used for activity box activityFontName activityArrowFontColor black activityArrowFontSizeactivityArrowFontStyle plain (^13) Used for text on arrows in activity diagrams activityArrowFontName circledCharacterFontColor black Used for text in circle for class, enum and others circledCharacterFontSize 17 circledCharacterFontStyle bold circledCharacterFontName Courier circledCharacterRadius 11 classArrowFontColor black classArrowFontSizeclassArrowFontStyle plain (^10) Used for text on arrows in class diagrams classArrowFontName classAttributeFontColor black classAttributeFontSizeclassAttributeIconSize (^1010) Class attributes and methods classAttributeFontStyle plain classAttributeFontName classFontColor black classFontSizeclassFontStyle plain (^12) Used for classes name classFontName classStereotypeFontColor black classStereotypeFontSizeclassStereotypeFontStyle italic (^12) Used for stereotype in classes classStereotypeFontName componentFontColor black componentFontSizecomponentFontStyle plain (^14) Used for components name componentFontName componentStereotypeFontColor black componentStereotypeFontSizecomponentStereotypeFontStyle italic (^14) Used for stereotype in components componentStereotypeFontName
12.4 Font color, name and size 12 CHANGING FONTS AND COLORS
componentArrowFontColor black
componentArrowFontSizecomponentArrowFontStyle plain (^13) Used for text on arrows in component diagrams componentArrowFontName noteFontColor black noteFontSizenoteFontStyle plain (^13) Used for notes in all diagrams but sequence diagrams noteFontName packageFontColor black packageFontSizepackageFontStyle plain (^14) Used for package and partition names packageFontName sequenceActorFontColor black sequenceActorFontSizesequenceActorFontStyle plain (^13) Used for actor in sequence diagrams sequenceActorFontName sequenceDividerFontColor black sequenceDividerFontSizesequenceDividerFontStyle bold (^13) Used for text on dividers in sequence diagrams sequenceDividerFontName sequenceArrowFontColor black sequenceArrowFontSizesequenceArrowFontStyle plain (^13) Used for text on arrows in sequence diagrams sequenceArrowFontName sequenceGroupingFontColor black sequenceGroupingFontSizesequenceGroupingFontStyle plain (^11) Used for text for ”else” in sequence diagrams sequenceGroupingFontName sequenceGroupingHeaderFontColor black sequenceGroupingHeaderFontSizesequenceGroupingHeaderFontStyle plain (^13) Used for text for ”alt/opt/loop” headers in sequence diagrams sequenceGroupingHeaderFontName sequenceParticipantFontColor black sequenceParticipantFontSizesequenceParticipantFontStyle plain (^13) Used for text on participant in sequence diagrams sequenceParticipantFontName sequenceTitleFontColor black sequenceTitleFontSizesequenceTitleFontStyle plain (^13) Used for titles in sequence diagrams sequenceTitleFontName titleFontColor black titleFontSizetitleFontStyle plain (^18) Used for titles in all diagrams but sequence diagrams titleFontName stateFontColor black stateFontSizestateFontStyle plain (^14) Used for states in state diagrams stateFontName stateArrowFontColor black stateArrowFontSizestateArrowFontStyle plain (^13) Used for text on arrows in state diagrams stateArrowFontName stateAttributeFontColor black stateAttributeFontSizestateAttributeFontStyle plain (^12) Used for states description in state diagrams stateAttributeFontName
12.4 Font color, name and size 12 CHANGING FONTS AND COLORS
usecaseFontColor black
usecaseFontSizeusecaseFontStyle plain (^14) Used for usecase labels in usecase diagrams usecaseFontName usecaseStereotypeFontColor black usecaseStereotypeFontSizeusecaseStereotypeFontStyle italic (^14) Used for stereotype in usecase usecaseStereotypeFontName usecaseActorFontColor black usecaseActorFontSizeusecaseActorFontStyle plain (^14) Used for actor labels in usecase diagrams usecaseActorFontName usecaseActorStereotypeFontColor black usecaseActorStereotypeFontSizeusecaseActorStereotypeFontStyle italic (^14) Used for stereotype for actor usecaseActorStereotypeFontName usecaseArrowFontColor black usecaseArrowFontSizeusecaseArrowFontStyle plain (^13) Used for text on arrows in usecase diagrams usecaseArrowFontName footerFontColor black footerFontSizefooterFontStyle plain (^10) Used for footer footerFontName headerFontColor black headerFontSizeheaderFontStyle plain (^10) Used for header headerFontName
12.5 Black and White 12 CHANGING FONTS AND COLORS
You can force the use of a black white output using theskinparam monochrome truecommand.
@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
Some minor preprocessing capabilities are included in PlantUML , and available for all diagrams. Those functionnalities are very similar to the C language preprocessor, except that the special character (#) has been changed to the exclamation mark (!).
Use the!includedirective to include file in your diagram. Imagine you have the very same class that appears in many diagrams. Instead of duplicating the description of this class, you can define a file that contains the description.
@startuml
!include List.iuml
List <|.. ArrayList
@enduml
File List.iuml : interface List List : int size() List : void clear() The fileList.iumlcan be included in many diagrams, and any modification in this file will change all diagrams that include it. You can also put several``` @startuml/@enduml
block you want to include adding!0where 0 is the block number.
For example, if you use!include foo.txt!1, the second```
@startuml/@enduml
```block withinfoo.txt
will be included.
You can also put an id to some```
@startuml/@enduml
```text block in an included file using```
@startuml(id=MY_OWN_ID)
syntax and then include the block adding!MY_OWN_IDwhen including the file, so using something
like!include foo.txt!MY_OWN_ID.
### 13.2 Including URL
Use the!includeurldirective to include file from Internet/Intranet in your diagram.
You can also use!includeurl [http://someurl.com/mypath!0to](http://someurl.com/mypath!0to) specify which```
@startuml/@enduml
block fromhttp://someurl.com/mypathyou want to include. The!0notation denotes the first diagram.
You can define constant using the!definedirective. As in C language, a constant name can only use alphanumeric and underscore characters, and cannot start with a digit.
@startuml
!define SEQUENCE (S,#AAAAAA) Database Sequence
!define TABLE (T,#FFAAAA) Database Table
13.4 Macro definition 13 PREPROCESSING
class USER << TABLE >> class ACCOUNT << TABLE >> class UID << SEQUENCE >> USER "1" -- "*" ACCOUNT USER -> UID @enduml
Of course, you can use the!includedirective to define all your constants in a single file that you
include in your diagram.
Constant can be undefined with the!undef XXXdirective.
You can also specify constants within the command line, with the-Dflags.
java -jar plantuml.jar -DTITLE="My title" atest1.txt
Note that the-Dflag must be put after the ”-jar plantuml.jar” section.
You can also define macro with arguments.
@startuml !define module(x) component x <> module(ABC) module(XYZ) @enduml
Macro can have several arguments.
@startuml !define send(a,b,c) a->b : c send(Alice, Bob, Hello) send(Bob, Alice, ok) @enduml
You can also define macro on several lines using!definelongand!enddefinelong.
@startuml !define DOUBLE(x) x x !definelong AUTHEN(x,y) x -> y : DOUBLE(hello) y -> x : ok !enddefinelong AUTHEN(Bob,Alice) @enduml
13.6 Conditions 13 PREPROCESSING
You can use!ifdef XXXand!endifdirectives to have conditionnal drawings.
The lines between those two directives will be included only if the constant after the!ifdefdirective
has been defined before.
You can also provide a!elsepart which will be included if the constant has not been defined.
@startuml !include ArrayList.iuml @enduml
File ArrayList.iuml :
class ArrayList
!ifdef SHOW_METHODS
ArrayList : int size()
ArrayList : void clear()
!endif
You can then use the!definedirective to activate the conditionnal part of the diagram.
@startuml !define SHOW_METHODS !include ArrayList.iuml @enduml
You can also use the!ifndefdirective that includes lines if the provided constant has NOT been
defined.
You can specify the java property ”plantuml.include.path” in the command line.
For example:
java -Dplantuml.include.path="c:/mydir" -jar plantuml.jar atest1.txt
Note the this -D option has to put before the -jar option. -D options after the -jar option will be
used to define constants within plantuml preprocessor.
It is possible to append text to a macro argument using the##syntax.
@startuml !definelong COMP_TEXTGENCOMP(name) [name] << Comp >> interface Ifc << IfcType >> AS name##Ifc name##Ifc - [name] !enddefinelong COMP_TEXTGENCOMP(dummy) @enduml
A macro can be defined by another macro.
13.8 Advanced features 13 PREPROCESSING
@startuml !define DOUBLE(x) x x !definelong AUTHEN(x,y) x -> y : DOUBLE(hello) y -> x : ok !enddefinelong AUTHEN(Bob,Alice) @enduml
A macro can be polymorphic with argument count.
@startuml !define module(x) component x <> !define module(x,y) component x as y <> module(foo) module(bar, barcode) @enduml
You can use system environment variable or constant definition when using include:
!include %windir%/test1.txt
!define PLANTUML_HOME /home/foo
!include PLANTUML_HOME/test1.txt
The PlantUML language use letters to define actor, usecase and so on. But letters are not only A-Z latin characters, it could be any kind of letter from any language.
@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
The default charset used when reading the text files containing the UML text description is system dependent. Normally, it should just be fine, but in some case, you may want to the use another charset. For example, with the command line: java -jar plantuml.jar -charset UTF-8 files.txt
Or, with the ant task:
14.1 Charset 14 INTERNATIONALIZATION
<target name="main">
<plantuml dir="./src" charset="UTF-8" />
</target>
Depending of your Java installation, the following charset should be available:ISO-8859-1,UTF-8,
UTF-16BE,UTF-16LE,UTF-16.
Here is the list of colors recognized by PlantUML. Note that color names are case insensitive.
AliceBlue GhostWhite NavajoWhite
AntiqueWhite GoldenRod Navy
Aquamarine Gold OldLace
Aqua Gray OliveDrab
Azure GreenYellow Olive
Beige Green OrangeRed
Bisque HoneyDew Orange
Black HotPink Orchid
BlanchedAlmond IndianRed PaleGoldenRod
BlueViolet Indigo PaleGreen
Blue Ivory PaleTurquoise
Brown Khaki PaleVioletRed
BurlyWood LavenderBlush PapayaWhip
CadetBlue Lavender PeachPuff
Chartreuse LawnGreen Peru
Chocolate LemonChiffon Pink
Coral LightBlue Plum
CornflowerBlue LightCoral PowderBlue
Cornsilk LightCyan Purple
Crimson LightGoldenRodYellow Red
Cyan LightGreen RosyBrown
DarkBlue LightGray RoyalBlue
DarkCyan LightPink SaddleBrown
DarkGoldenRod LightSalmon Salmon
DarkGray LightSeaGreen SandyBrown
DarkGreen LightSkyBlue SeaGreen
DarkKhaki LightSlateGray SeaShell
DarkMagenta LightSteelBlue Sienna
DarkOliveGreen LightYellow Silver
DarkOrchid LimeGreen SkyBlue
DarkRed Lime SlateBlue
DarkSalmon Linen SlateGray
DarkSeaGreen Magenta Snow
DarkSlateBlue Maroon SpringGreen
DarkSlateGray MediumAquaMarine SteelBlue
DarkTurquoise MediumBlue Tan
DarkViolet MediumOrchid Teal
Darkorange MediumPurple Thistle
DeepPink MediumSeaGreen Tomato
DeepSkyBlue MediumSlateBlue Turquoise
DimGray MediumSpringGreen Violet
DodgerBlue MediumTurquoise Wheat
FireBrick MediumVioletRed WhiteSmoke
FloralWhite MidnightBlue White
ForestGreen MintCream YellowGreen
Fuchsia MistyRose Yellow
Gainsboro Moccasin
1 Sequence Diagram 1
1.1 Basic examples....................................... 1
1.2 Declaring participant.................................... 1
1.3 Use non-letters in participants............................... 3
1.4 Message to Self....................................... 3
1.5 Change arrow style..................................... 3
1.6 Change arrow color..................................... 4
1.7 Message sequence numbering............................... 4
1.8 Splitting diagrams..................................... 6
1.9 Grouping message..................................... 7
1.10 Notes on messages..................................... 8
1.11 Some other notes...................................... 9
1.12 Changing notes shape................................... 10
1.13 Creole and HTML..................................... 10
1.14 Divider........................................... 11
1.15 Reference.......................................... 12
1.16 Delay............................................ 12
1.17 Space............................................ 13
1.18 Lifeline Activation and Destruction............................ 13
1.19 Participant creation.................................... 15
1.20 Incoming and outgoing messages............................. 15
1.21 Stereotypes and Spots................................... 16
1.22 More information on titles................................. 17
1.23 Participants encompass.................................. 19
1.24 Removing Footer...................................... 19
1.25 Skinparam.......................................... 19
1.26 Changing padding..................................... 21
2 Use Case Diagram 23
2.1 Usecases........................................... 23
2.2 Actors............................................ 23
2.3 Usecases description.................................... 23
2.4 Basic example........................................ 24
2.5 Extension.......................................... 24
2.6 Using notes......................................... 25
2.7 Stereotypes......................................... 26
2.8 Changing arrows direction................................. 26
2.9 Splitting diagrams..................................... 28
2.10 Left to right direction................................... 28
2.11 Skinparam.......................................... 29
2.12 Complete example..................................... 30
3 Class Diagram 31
3.1 Relations between classes................................. 31
3.2 Label on relations..................................... 32
3.3 Adding methods...................................... 33
3.4 Defining visibility...................................... 34
3.5 Abstract and Static.................................... 35
3.6 Advanced class body.................................... 36
3.7 Notes and stereotypes................................... 37
3.8 More on notes........................................ 38
3.9 Note on links........................................ 39
3.10 Abstract class and interface................................ 40
3.11 Using non-letters...................................... 41
3.12 Hide attributes, methods................................... 42
3.13 Hide classes......................................... 43
3.14 Use generics......................................... 43
3.15 Specific Spot........................................ 43
3.16 Packages........................................... 44
3.17 Packages style........................................ 44
3.18 Namespaces......................................... 45
3.19 Automatic namespace creation.............................. 46
3.20 Lollipop interface...................................... 47
3.21 Changing arrows direction................................. 47
3.22 Association classes..................................... 48
3.23 Skinparam.......................................... 49
3.24 Skinned Stereotypes.................................... 50
3.25 Color gradient........................................ 50
3.26 Help on layout....................................... 51
3.27 Splitting large files..................................... 52
4 Activity Diagram 54
4.1 Simple Activity....................................... 54
4.2 Label on arrows....................................... 54
4.3 Changing arrow direction................................. 54
4.4 Branches........................................... 55
4.5 More on Branches..................................... 56
4.6 Synchronization....................................... 57
4.7 Long activity description.................................. 58
4.8 Notes............................................ 58
4.9 Partition........................................... 59
4.10 Skinparam.......................................... 60
4.11 Octagon........................................... 61
4.12 Complete example..................................... 61
5 Activity Diagram (beta) 64
5.1 Simple Activity....................................... 64
5.2 Start/Stop.......................................... 64
5.3 Conditional......................................... 65
5.4 Repeat loop......................................... 66
5.5 While loop......................................... 66
5.6 Parallel processing..................................... 67
5.7 Notes............................................ 68
5.8 Colors............................................ 68
5.9 Arrows............................................ 69
5.10 Connector.......................................... 69
5.11 Grouping.......................................... 70
5.12 Swimlanes.......................................... 70
5.13 Detach............................................ 71
5.14 SDL............................................. 72
5.15 Complete example..................................... 73
6 Component Diagram 75
6.1 Components......................................... 75
6.2 Interfaces.......................................... 75
6.3 Basic example........................................ 75
6.4 Using notes......................................... 76
6.5 Grouping Components................................... 76
6.6 Changing arrows direction................................. 78
6.7 Use UML2 notation.................................... 79
6.8 Long description...................................... 80
6.9 Individual colors...................................... 80
6.10 Using Sprite in Stereotype................................. 80
6.11 Skinparam.......................................... 81
7 State Diagram 83
7.1 Simple State........................................ 83
7.2 Composite state...................................... 83
7.3 Long name......................................... 84
7.4 Concurrent state...................................... 85
7.5 Arrow direction....................................... 86
7.6 Note............................................. 87
7.7 More in notes........................................ 88
7.8 Skinparam.......................................... 88
8 Object Diagram 90
8.1 Definition of objects.................................... 90
8.2 Relations between objects................................. 90
8.3 Adding fields........................................ 90
8.4 Common features with class diagrams.......................... 91
9 Common commands 92
9.1 Footer and header..................................... 92
9.2 Zoom............................................ 92
10 Salt 93
10.1 Basic widgets........................................ 93
10.2 Using grid.......................................... 93
10.3 Using separator....................................... 94
10.4 Tree widget......................................... 94
10.5 Enclosing brackets..................................... 95
10.6 Adding tabs......................................... 95
10.7 Using menu......................................... 96
10.8 Advanced table....................................... 97
11 Creole 98
11.1 Emphasized text...................................... 98
11.2 List............................................. 98
11.3 Escape character...................................... 99
11.4 Horizontal lines....................................... 99
11.5 Headings........................................... 99
11.6 Legacy HTML....................................... 99
11.7 Table............................................. 100
11.8 Tree............................................. 100
11.9 Special characters...................................... 100
11.10OpenIconic......................................... 101
11.11Defining and using sprites................................. 102
11.12Encoding Sprite....................................... 102
11.13Importing Sprite...................................... 102
11.14Examples.......................................... 102
12 Changing fonts and colors 104
12.1 Usage............................................ 104
12.2 Nested............................................ 104
12.3 Color............................................. 105
12.4 Font color, name and size................................. 106
12.5 Black and White...................................... 109
13 Preprocessing 110
13.1 Including files........................................ 110
13.2 Including URL....................................... 110
13.3 Constant definition..................................... 110
13.4 Macro definition...................................... 111
13.5 Macro on several lines................................... 111
13.6 Conditions.......................................... 112
13.7 Search path......................................... 112
13.8 Advanced features..................................... 112
14 Internationalization 114
14.1 Charset........................................... 114
15 Color Names 116