LoginSignup
16
15

More than 5 years have passed since last update.

PlantUMLで見ためを変更

Last updated at Posted at 2018-06-16

はじめに

PlantUMLの見ためはデフォルトだと以下のようなスタイルである。

default.png

デフォルトでも内容を読む分には支障はないが、用途に合わせてスタイルを変えたいところだ。
そのような場合、PlantUMLでは以下のような方法でスタイルを変更することができる。

  • ファイルに直接記入する
  • 別ファイルで定義して!includeディレクティブで読み込む
  • 別ファイルで定義してplantumlでビルドする際に読み込む
  • 要素ごとに指定する
変更前 変更後
default.png test1.png

ファイルに直接記入

サンプルのシーケンス図を記載するには以下のようにskinparamを使用する。

@startuml
'共通
skinparam backgroundColor grey

'シーケンス図
skinparam sequence {
          'オブジェクト
          ParticipantBorderColor DeepSkyBlue
          ParticipantBackgroundColor white                                                                      
          ParticipantFontSize 20

          '矢印
          ArrowColor DeepSkyBlue
          ActorBorderColor DeepSkyBlue

          'ライフライン
          LifeLineBorderColor blue
}

佐藤 -> 田中 : 処理A
田中 -> 田中 : 処理B
田中 --> 佐藤 : 応答

@enduml

skinparamでは色はHTMLでお馴染みのRGB表記や色名を指定することで設定できる。
色以外にも文字サイズやフォントなど、多様な設定ができるようだ。
尚、skinparamはシーケンス図に限らず、PlantUMLで共通して使用できる。

パラメータ名は以下のコマンドで取得できるようだが、
説明は出ないので名前から察するしかないようだ。

$ java -jar ./plantuml.jar -language

また、設定は以下のようにskinparamを羅列しても良いが、
LifeLineBorderColorとSequenceLifeLineBorderColorのように
パラメータ名が変わるものもあるようだ。

skinparam backgroundColor grey
skinparam ParticipantBorderColor DeepSkyBlue
skinparam ParticipantBackgroundColor white
skinparam ParticipantFontSize 20
skinparam ArrowColor DeepSkyBlue
skinparam ActorBorderColor DeepSkyBlue
skinparam SequenceLifeLineBorderColor blue

別ファイルで定義して!includeディレクティブで読み込む

スタイルに限った話ではないが、PlantUMLでは!includeディレクティブを使用して、
ファイルを分割できる。

test.txt
@startuml
!include test.conf

佐藤 -> 田中 : 処理A
田中 -> 田中 : 処理B
田中 --> 佐藤 : 応答

@enduml
test.conf
'共通
skinparam backgroundColor grey

'シーケンス図
skinparam sequence {
          'オブジェクト
          ParticipantBorderColor DeepSkyBlue
          ParticipantBackgroundColor white
          ParticipantFontSize 20

          '矢印
          ArrowColor DeepSkyBlue
          ActorBorderColor DeepSkyBlue

          'ライフライン
          LifeLineBorderColor blue
}

!includeはskinparamと同様、シーケンス図以外の図でも使用できる。

別ファイルで定義してplantumlでビルドする際に読み込む

plantumlの-configオプションを使用すると、!includeを指定することなく、
別ファイルで定義した設定を適用することができる。

test.txt
@startuml

佐藤 -> 田中 : 処理A
田中 -> 田中 : 処理B
田中 --> 佐藤 : 応答

@enduml
test.conf
※「別ファイルで定義して!includeディレクティブで読み込む」と同様

$ java -jar ./plantuml.jar -config test.conf test.txt

この方法の最大のメリットは内容を変更することなく、さまざまなスタイルファイルを適用できる点である。

要素ごとに指定する

PlantUMLでは以下のように個別に色を指定することができる。

test1.png

@startuml
participant 佐藤 #FF0000
participant 田中 #0000FF

佐藤 -> 田中 : 処理A
田中 -> 田中 : 処理B
田中 --> 佐藤 : 応答

@enduml

ただし、上記の方法は柔軟な設定ができるが、図の種類どころか、
シーケンス図の中だけでもオブジェクトや矢印によって書き方が多様である。
そのため、個人で使うには良いが、グループで使うには不便と思われる。
詳細は 公式ページ を参照。

参考ページ


関連記事

PlantUML シーケンス図で便利だと思った機能・使い方

16
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15