PlantUML工具书之二(流程图|模块图|状态图)

流程图


1
2
3
4
5
@startuml
:Hello world;
:This is on defined on
several **lines**;
@enduml

1
2
3
4
5
6
7
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml

1
2
3
4
5
6
7
@startuml
start
:Hello world;
:This is on defined on
several **lines**;
end
@enduml

1
2
3
4
5
6
7
8
9
10
@startuml
start
if (Graphviz installed?) then (yes)
:process all\ndiagrams;
else (no)
:process only
__sequence__ and __activity__ diagrams;
endif
stop
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@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

1
2
3
4
5
6
7
8
@startuml
start
repeat
:read data;
:generate diagrams;
repeat while (more data?)
stop
@enduml

1
2
3
4
5
6
7
8
@startuml
start
while (data available?)
:read data;
:generate diagrams;
endwhile
stop
@enduml

1
2
3
4
5
6
@startuml
while (check filesize ?) is (not empty)
:read file;
endwhile (empty)
:close file;
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
@startuml
start
if (multiprocessor?) then (yes)
fork
:Treatment 1;
fork again
:Treatment 2;
end fork
else (monoproc)
:Treatment 1;
:Treatment 2;
endif
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@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

1
2
3
4
5
6
7
@startuml
start
:starting progress;
#HotPink:reading configuration files
These files should edited at this point!;
#AAAAAA:ending of the process;
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@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

1
2
3
4
5
6
7
8
9
10
11
12
@startuml
start
partition Initialization {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@startuml
:start;
fork
:foo1;
:foo2;
fork again
:foo3;
detach
endfork
if (foo4) then
:foo5;
detach
endif
:foo6;
detach
:foo7;
stop
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@startuml
start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (tru
: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

模块图


1
2
3
4
5
6
@startuml
[First component]
[Another component] as Comp2
component Comp3
component [Last\ncomponent] as Comp4
@enduml

1
2
3
4
5
6
@startuml
() "First Interface"
() "Another interface" as Interf2
interface Interf3
interface "Last\ninterface" as Interf4
@enduml

1
2
3
4
@startuml
DataAccess - [First Component]
[First Component] ..> HTTP : use
@enduml

1
2
3
4
5
6
7
8
9
10
@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

1
2
3
4
@startuml
Interface1 <-- [Component]
Interface2 <- [Component]
@enduml

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

1
2
3
4
5
6
@startuml
skinparam componentStyle uml2
interface "Data Access" as DA
DA - [First Component]
[First Component] ..> HTTP : use
@enduml

1
2
3
@startuml
component [Web Server] #Yellow
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@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

状态图


1
2
3
4
5
6
7
8
@startuml
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string
State1 -> State2
State2 --> [*]
@enduml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@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

1
2
3
4
5
6
7
8
9
10
@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

1
2
3
4
@startuml
state foo
note "This is a floating note" as N1
@enduml

1
2
3
4
@startuml
state foo
note "This is a floating note" as N1
@enduml

1
2
3
4
5
6
7
8
9
10
11
@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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@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