PlantUML+MarkDown學習

在Markdown中可以使用mermaid畫圖,但是我在網上看到了Plant UML,功能比mermaid強大,所以就學習了一下。

總體說明

支持圖形種類

  • Sequence diagram
  • Usecase diagram
  • Class diagram
  • Activity diagram (here is the legacy syntax)
  • Component diagram
  • State diagram
  • Object diagram
  • Deployment diagram
  • Timing diagram
  • Network
  • Wireframe graphical interface
  • Archimate diagram
  • Specification and Description Language (SDL)
  • Ditaa diagram
  • Gantt diagram
  • MindMap diagram
  • Work Breakdown Structure diagram
  • Mathematic with AsciiMath or JLaTeXMath notation
  • Entity Relationship diagram

預處理

所有預處理命令都是以“!”開頭,語法類似於C

  • 變量:$a=23local $b="foo"global $c='foo'
  • 條件判斷:if ... else ...
  • 函數:function ... return ... endfunction
  • 包含其他文件或URL:import filenameinclude filename!idincludesub filename!id
  • 日誌打印:logdump_memoryassert condition : "message"
  • 動態參數名:##
  • 動態函數調用:%invoke_void_func()%call_user_func()
  • 內置函數:%strlen,%substr,%strpos,%intval,%file_exists,function_exists,%variable_exists,%set_variable_value,%get_variable_value,%getenv,%dirpath,%filename,%date,%true,%false,%not,%lower,%upper

通用命令

  • 頁眉頁腳:[center | left | right] head, footer
  • 縮放:scale
  • 標題:title ... end title
  • 圖片標題:caption
  • 圖片說明:legend [center | left | right] ... end legend

標準庫

參考:https://plantuml.com/zh/stdlib

圖形舉例

Usecase diagram

  • 用例:(), usecase, as,用例描述分隔:--text--, ==text==, ..text..
  • 角色:::, actor, as
  • 連接
    • 箭頭連接:->, -->, <-, <--, <., <.., .>, ..>, -right->, -left->, -down->, -up->
    • 繼承:<|--
  • 註釋:note [left | right | top | bottom] of () ... end notenote message as ID, ID .. ()
  • 構造類型:<< >>
  • 方向控制:top to bottom directionleft to right direction
  • 顯示顏色&字體:skinparam

用例圖舉例

<img src='https://g.gravizo.com/svg?
@startuml;
left to right direction;
skinparam packageStyle rectangle;
actor customer;
actor clerk;
rectangle checkout {;
  customer -- (checkout);
  (checkout) .> (payment) : include;
  (help) .> (checkout) : extends;
  (checkout) -- clerk;
};
@enduml'
alt="用例圖舉例">

gravizo不僅支持PlantUML,還支持Graphviz、UMLGraph以及JSON格式的SVG圖。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章