UML (アクティビティ図)

Markdown で PlantUML、アクティビティ図

UML (アクティビティ図)

ちょっとの間離れるとすぐ忘れてしまうので備忘録として。。。

基本的な書き方だけ。

参考

State Diagram

Simple action

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

ベーシックなやつね

Start/Stop

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

処理を止める

Start/End

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

処理を終わらせる(例外エラーとかかな)

Conditional

if (…) then (…)

@startuml
start

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

stop
@enduml

条件式

if (…) is (…) then

@startuml
if (color?) is (<color:red>red) then
:print red;
else 
:print not red;
@enduml

if文

if (…) equals (…) then

@startuml
if (counter?) equals (5) then
:print 5;
else 
:print not 5;
@enduml

これもif文

Several tests (horizontal mode)

@startuml
start
if (condition A) then (yes)
  :Text 1;
elseif (condition B) then (yes)
  :Text 2;
  stop
(no) elseif (condition C) then (yes)
  :Text 3;
(no) elseif (condition D) then (yes)
  :Text 4;
else (nothing)
  :Text else;
endif
stop
@enduml

テスト実行 横表示

Several tests (vertical mode)

@startuml
!pragma useVerticalIf on
start
if (condition A) then (yes)
  :Text 1;
elseif (condition B) then (yes)
  :Text 2;
  stop
elseif (condition C) then (yes)
  :Text 3;
elseif (condition D) then (yes)
  :Text 4;
else (nothing)
  :Text else;
endif
stop
@enduml

テスト実行 縦表示

Switch and case [switch, case, endswitch]

@startuml
start
switch (test?)
case ( condition A )
  :Text 1;
case ( condition B ) 
  :Text 2;
case ( condition C )
  :Text 3;
case ( condition D )
  :Text 4;
case ( condition E )
  :Text 5;
endswitch
stop
@enduml

switch,case文

Conditional with stop on an action [kill, detach]

stop action on a if loop

@startuml
if (condition?) then
  :error;
  stop
endif
#palegreen:action;
@enduml

if文でstopで処理を止めるラインと処理を続けるライン

kill or detach keyword

kill

@startuml
if (condition?) then
  #pink:error;
  kill
endif
#palegreen:action;
@enduml

if文でkillで処理を止めるラインと処理を続けるライン(重大なエラーとかの時かな???)

detach

@startuml
if (condition?) then
  #pink:error;
  detach
endif
#palegreen:action;
@enduml

if文でdetachで処理を止めるラインと処理を続けるライン(killと同様かな?)

Repeat loop

epeat and repeatwhile keywords to have repeat loops

@startuml
start
repeat
:read data;
:generate diagrams;
repeat while (more data?) is (yes)
->no;
stop
@enduml

ループの基本形

target and insert an action in the return path using the backward keyword

@startuml
start
repeat :foo as starting label;
  :read data;
  :generate diagrams;
backward:This is backward;
repeat while (more data?)
stop
@enduml

***ループの戻りに処理名を入れる場合はbackward

Break on a repeat loop [break]

@startuml
start
repeat
  :Test something;
    if (Something went wrong?) then (no)
      #palegreen:OK;
      break
    endif
    ->NOK;
    :Alert "Error with long text";
repeat while (Something went wrong with long text?) is (yes) not (no)
->//merged step//;
:Alert "Success";
stop
@enduml

Breakで抜ける処理

While loop

while and endwhile keywords to have repeat loops

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

do while

label after the endwhile keyword, or using the is keyword.

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

ラベル付けね

detach to form an infinite while loop, then you will want to also hide the partial arrow that results using

@startuml
:Step 1;
if (condition1) then
  while (loop forever)
   :Step 2;
  endwhile
  -[hidden]->
  detach
else
  :end normally;
  stop
endif
@enduml

detachで処理終了 -[hidden]-> でラインを消す

Parallel processing

fork

@startuml
start
fork
  :action 1;
fork again
  :action 2;
end fork
stop
@enduml

並列処理

fork with end merge

@startuml
start
fork
  :action 1;
fork again
  :action 2;
end merge
stop
@enduml

並列処理から合流

@startuml
start
fork
  :action 1;
fork again
  :action 2;
  end
end merge
stop
@enduml

並列処理から合流、かたや終了

Label on end fork

@startuml
start
fork
  :action A;
fork again
  :action B;
end fork {or}
stop
@enduml

ラベル付け

@startuml
start
fork
  :action A;
fork again
  :action B;
end fork {and}
stop
@enduml

ラベル付け

Other example

@startuml

start

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

@enduml

分岐・並列処理

Split processing

Split

@startuml
start
split
   :A;
split again
   :B;
split again
   :C;
split again
   :a;
   :b;
end split
:D;
end
@enduml

分散

Input split (multi-start)

	
@startuml
split
   -[hidden]->
   :A;
split again
   -[hidden]->
   :B;
split again
   -[hidden]->
   :C;
end split
:D;
@enduml

最初から分散

@startuml
split
   -[hidden]->
   :A;
split again
   -[hidden]->
   :a;
   :b;
split again
   -[hidden]->
   (Z)
end split
:D;
@enduml

最初から分散・複数処理

Output split (multi-end)

@startuml
start
split
   :A;
   kill
split again
   :B;
   detach
split again
   :C;
   kill
end split
@enduml

分散処理で終了

@startuml
start
split
   :A;
   kill
split again
   :b;
   :c;
   detach
split again
   (Z)
   detach
split again
   end
split again
   stop
end split
@enduml

分散処理で終了の仕方いろいろ

notes

@startuml

start
:foo1;
floating note left: This is a note
:foo2;
note right
  This note is on several
  //lines// and can
  contain <b>HTML</b>
  ====
  * Calling the method ""foo()"" is prohibited
end note
stop

@enduml

ノート

add note on backward activity

@startuml
start
repeat :Enter data;
:Submit;
backward :Warning;
note right: Note
repeat while (Valid?) is (No) not (Yes)
stop
@enduml

ノート基本形

add note on partition activity

@startuml
start
partition "**process** HelloWorld" {
    note
        This is my note
        ----
        //Creole test//
    end note
    :Ready;
    :HelloWorld(i)>
    :Hello-Sent;
}
@enduml

partitionにノート

Colors

@startuml

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

色付け

@startuml
start
partition #red/white testPartition {
        #blue\green:testActivity;
}
@enduml

色付け

Lines without arrows

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

矢印除去(ラインのみ)

@startuml
skinparam ArrowHeadColor none
start
repeat :Enter data;
:Submit;
backward :Warning;
repeat while (Valid?) is (No) not (Yes)
stop
@enduml

矢印除去(ラインのみ)

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

矢印の色

Connector

@startuml
start
:Some activity;
(A)
detach
(A)
:Other activity;
@enduml

接続 DBとかかな?

color on connector

@startuml
start
:The connector below
wishes he was blue;
#blue:(B)
:This next connector
feels that she would
be better off green;
#green:(G)
stop
@enduml

色付け

Grouping or partition

Group

@startuml
start
group Initialization 
    :read config file;
    :init internal variable;
end group
group Running group
    :wait for user interaction;
    :print information;
end group

stop
@enduml

グルーピング

Partition

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

グルーピング

@startuml
start
partition #lightGreen "Input Interface" {
    :read config file;
    :init internal variable;
}
partition Running {
    :wait for user interaction;
    :print information;
}
stop
@enduml

グルーピングカラー

Detach or kill [detach, kill]

detach

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

detachで処理をとめる

kill

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

killで処理をとめる

SDL (Specification and Description Language)

- |
- <
- >
- /
- \\
- ]
- }
@startuml
:Ready;
:next(o)|
:Receiving;
split
 :nak(i)<
 :ack(o)>
split again
 :ack(i)<
 :next(o)
 on several lines|
 :i := i + 1]
 :ack(o)>
split again
 :err(i)<
 :nak(o)>
split again
 :foo/
split again
 :bar\\
split again
 :i > 5}
stop
end split
:finish;
@enduml

処理の種類

Complete example

@startuml

start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (true)
  :Page.onInit();
  if (isForward?) then (no)
    :Process controls;
    if (continue processing?) then (no)
      stop
    endif

    if (isPost?) then (yes)
      :Page.onPost();
    else (no)
      :Page.onGet();
    endif
    :Page.onRender();
  endif
else (false)
endif

if (do redirect?) then (yes)
  :redirect process;
else
  if (do forward?) then (yes)
    :Forward request;
  else (no)
    :Render page template;
  endif
endif

stop

@enduml

完成形

Condition Style

Inside style (by default)

@startuml
skinparam conditionStyle inside
start
repeat
  :act1;
  :act2;
repeatwhile (<b>end)
:act3;
@enduml

この2つ skinparam conditionStyle inside repeatwhile (<b>end)

@startuml
start
repeat
  :act1;
  :act2;
repeatwhile (<b>end)
:act3;
@enduml

repeatwhile (<b>end)

Diamond style

@startuml
skinparam conditionStyle diamond
start
repeat
  :act1;
  :act2;
repeatwhile (<b>end)
:act3;
@enduml

この2つ skinparam conditionStyle diamond repeatwhile (<b>end)

InsideDiamond (or Foo1) style

@startuml
skinparam conditionStyle InsideDiamond
start
repeat
  :act1;
  :act2;
repeatwhile (<b>end)
:act3;
@enduml

skinparam conditionStyle InsideDiamond で内部表示

Condition End Style

Diamond style (by default)

@startuml
skinparam ConditionEndStyle diamond
:A;
if (decision) then (yes)
    :B1;
else (no)
endif
:C;
@enduml

skinparam ConditionEndStyle diamond で空になる

With two branches (B1, B2)

@startuml
skinparam ConditionEndStyle diamond
:A;
if (decision) then (yes)
    :B1;
else (no)
    :B2;
endif
:C;
@enduml
@enduml

Horizontal line (hline) style

With one branch

@startuml
skinparam ConditionEndStyle hline
:A;
if (decision) then (yes)
    :B1;
else (no)
endif
:C;
@enduml

skinparam ConditionEndStyle hlineで 並行のライン表示

With two branches (B1, B2)

@startuml
skinparam ConditionEndStyle hline
:A;
if (decision) then (yes)
    :B1;
else (no)
    :B2;
endif
:C;
@enduml
@enduml

skinparam ConditionEndStyle hlineで 並行のライン表示


おっさんWEBエンジニア奮闘記©2007 WEBDIMENSION