Android Studio UML 插件 PlantUML 使用語法


活動標簽(activity label)以冒號開始,以分號結束。

文本格式支持creole wiki語法。

活動默認安裝它們定義的順序就行連接。

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

開始/結束

你可以使用關鍵字startstop表示圖示的開始和結束。

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

也可以使用 end 關鍵字。

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

條件語句

在圖示中可以使用關鍵字ifthenelse設置分支測試。標注文字則放在括號中。

@startuml

start

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

stop

@enduml
if then else example

也可以使用關鍵字elseif設置多個分支測試。

@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
several if test

重復循環

你可以使用關鍵字repeatrepeatwhile進行重復循環。

@startuml

start

repeat
  :read data;
  :generate diagrams;
repeat while (more data?)

stop

@enduml
basic repeat while loop

while循環

可以使用關鍵字whileend while進行while循環。

@startuml

start

while (data available?)
  :read data;
  :generate diagrams;
endwhile

stop

@enduml
another while loop

還可以在關鍵字endwhile后添加標注,還有一種方式是使用關鍵字is

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

並行處理

你可以使用關鍵字forkfork againend fork表示並行處理。

@startuml

start

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

@enduml
activity diagram with parallel processing

注釋

文本格式支持creole wiki語法。

A note can be floating, using floating keyword.

@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 notes on activity diagram

標題和圖例

你可以給圖表(diagram)添加標題、標頭、腳注和圖例。

@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
title and legend on an activity diagram

顏色

你可以為活動(activity)指定一種顏色。

@startuml

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

@enduml
changing colors

箭頭

使用->標記,你可以給箭頭添加文字或者修改箭頭顏色。

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
colored arrows

組合(grouping)

通過定義分區(partition),你可以把多個活動組合(group)在一起。

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

stop
@enduml
grouping and partitionning in activity diagram

泳道(Swimlanes)

你可以使用管道符|來定義泳道。 
還可以改變泳道的顏色。

@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml
swimlanes

分離(detach)

可以使用關鍵字detach移除箭頭。

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

特殊領域語言(SDL)

通過修改活動標簽最后的分號分隔符(;),可以為活動設置不同的形狀。

  • |
  • <
  • >
  • /
  • ]
  • }
@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
SDL 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
full servlet example


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM