処理プロセスを整理したいときに、アクティビティ図を書くことがあります。「処理フロー」と「並行に実行できる処理」を可視化することができます。ここでは、PlantUMLを利用してアクティビティ図を書く方法について紹介します。
目次
アクティビティ図を書く目的
私は、以下目的でアクティビティ図を書きます。
- 必要な前処理の確認
- 並行して作業を進められるアクティビティの発見
日常のルーチン作業を可視化して、改善を検討するのにも活用できます。
基本的な書き方|「旧記法」と「新記法」
アクティビティ図は、開始点
から始まり、 アクティビティ
を順番に記述して、終了点
で処理の終了です。
PlantUMLでアクティビティ図を書く方法として、旧記法
と新記法
があります。
旧記法
@startuml
title 旧記法
(*) --> アクティビティA
--> "アクティビティB\n(改行)"
--> アクティビティC
--> (*)
@enduml

新記法
@startuml
title 新記法
start
:アクティビティA;
:アクティビティB
(改行);
:アクティビティC;
stop
@enduml

以降、新記法の記述で紹介します。
注釈の書き方
@startuml
title 注釈
start
:アクティビティA;
:アクティビティB;
note right
注釈
アクティビティBに対する注釈です。
end note
:アクティビティC;
stop
@enduml

ループ処理の書き方
前判定
@startuml
title ループ処理
start
:アクティビティA;
while (i < 10)
:アクティビティB;
endwhile
:アクティビティC;
stop
@enduml

後判定
@startuml
title ループ処理
start
:アクティビティA;
repeat
:アクティビティB;
repeat while (i < 10)
:アクティビティC;
stop
@enduml

分岐処理の書き方
水平
@startuml
title 分岐処理
start
:アクティビティA;
if (x > 0) then (true)
:アクティビティB;
else if (x == 0) then (true)
:アクティビティC;
else (false)
:アクティビティD;
endif
:アクティビティE;
stop
@enduml

垂直
!pragma useVerticalIf on
を記載すると垂直に描画されます。
@startuml
!pragma useVerticalIf on
title 分岐処理
start
:アクティビティA;
if (x > 0) then (true)
:アクティビティB;
else if (x == 0) then (true)
:アクティビティC;
else (false)
:アクティビティD;
endif
:アクティビティE;
stop
@enduml

処理の停止
特定の条件分岐で処理を停止したい場合 kill
と記述します。
@startuml
title 分岐処理
start
:アクティビティA;
if (x > 0) then (true)
:アクティビティB;
kill
else if (x == 0) then (true)
:アクティビティC;
kill
else (false)
:アクティビティD;
endif
:アクティビティE;
stop
@enduml

並列処理の書き方
@startuml
title 並列処理
start
:アクティビティA;
fork
:アクティビティB;
fork
:アクティビティC;
fork again
:アクティビティD;
end fork
fork again
:アクティビティE;
end fork
:アクティビティF;
stop
@enduml

専用レーンで仕切る方法
@startuml
title パーティション
|ユーザーA|
start
:アクティビティA;
|ユーザーB|
:アクティビティB;
|ユーザーC|
:アクティビティC;
|ユーザーA|
:アクティビティD;
stop
@enduml
