Skip to content

PlantUML#

  • Plantuml 是一个支持用文本描述生成UML图的工具.
  • plantuml website

使用#

安装vscode 中 Markdown Preview Enhanced 插件。 该插件内置 plantuml.jar 包,不需要另外安装。 需要安装Java 环境,并添加到环境变量。 该插件同时可使用mermaid 画图。

plantuml 程序#

apt install plantuml
#usage

# channel.puml : file to gen
# -tsvg : gen channel.svg
# -o .  : gen file channel.svg in cur folder
plantuml channel.puml -tsvg -o .

example#

活动图#

示例:

@startuml
start
: muti process;
fork
  :process1;
  repeat: step0
    #lightgreen : step1;
    -[#blue]->
    note left : run step1
    if (err?) then (Y)
        -[#blue,dashed]-> 
        : clear;
        -[#blue,dashed]-> 
        break
    endif
    -[#blue,dashed]->  N ;
    : step2;
  repeat while (cond ?)
fork again
  :process2;
  group #lightgreen g1
    floating note right : g1 group
    :step2.1;
    :step2.2;
  end group
end fork
stop
@enduml

渲染:

509.
400. PlantUML version 1.2026.3beta6 / 97f0f40 [2026-04-02 17:46:40 UTC][From string (line 7) ] @startuml<style>root {--base: #1e1e2e ...... ( skipping 644 lines )...} .external_system {BackGroundColor: var(--overlay1)} .external_container {BackGroundColor: var(--overlay2)} .node {BackgroundColor: var(--mantle)FontColor: var(--text)}</style>start: muti process;fork:process1;repeat: step0Syntax Error? (Assumed diagram type: activity)

泳道 (swimlanes)#

示例:

@startuml
|#palegreen|f| fisherman
|c| cook
|#gold|e| eater
|f|
start
:go fish;
|c|
:fry fish;
|e|
:eat fish;
stop
@enduml

渲染:

go fishfry fisheat fishfishermancookeater
go fishfry fisheat fishfishermancookeater

定时图#

示例:

@startuml
clock   "Clock_0"   as C0 with period 50
clock   "Clock_1"   as C1 with period 50 pulse 15 offset 10
binary  "Binary"  as B
concise "Concise" as C
robust  "Robust"  as R
analog  "Analog"  as A

@0
C is Idle
R is Idle
A is 0

note top of C : first

@R
@0 <-> @100 : 100 ms

@100
B is high
C is Waiting
R is Processing
A is 3

@300
R is Waiting
A is 1
@enduml

渲染:

Clock_0Clock_1BinaryConciseIdleWaitingfirstRobustIdleProcessingWaiting100 msAnalog0.03.0050100300
Clock_0Clock_1BinaryConciseIdleWaitingfirstRobustIdleProcessingWaiting100 msAnalog0.03.0050100300

Network#

示例:

@startuml
!include <office/Servers/application_server>
!include <office/Servers/database_server>

nwdiag {
  group {
    color = "#FFaaaa";
    web01;
    db01;
  }
  group {
    color = "#aaaaFF";
    web02 [description = "<$application_server>\n web02"];
    db02  [description = "<$database_server>\n db01"];
  }
  network dmz {
      color = "lightblue"
      address = "210.x.x.x/24"

      web01 [address = "210.x.x.1"];
      web02 [address = "210.x.x.2"];
  }
  network internal {
      address = "172.x.x.x/24";

      web01 [address = "172.x.x.1"];
      web02 [address = "172.x.x.2"];
      db01 ;
      db02 ;
  }
}
@enduml

渲染:

400. PlantUML version 1.2026.3beta6 / 97f0f40 [2026-04-02 17:46:40 UTC][From string (line 6) ] @startuml<style>root {--base: #303446 ...... ( skipping 645 lines )... .external_system {BackGroundColor: var(--overlay1)} .external_container {BackGroundColor: var(--overlay2)} .node {BackgroundColor: var(--mantle)FontColor: var(--text)}</style>sprite $application_server #office#servers/application_server:application_server sprite $database_server #office#servers/database_server:database_server  nwdiag {Syntax Error? (Assumed diagram type: sequence)
400. PlantUML version 1.2026.3beta6 / 97f0f40 [2026-04-02 17:46:40 UTC][From string (line 6) ] @startuml<style>root {--base: #1e1e2e ...... ( skipping 645 lines )... .external_system {BackGroundColor: var(--overlay1)} .external_container {BackGroundColor: var(--overlay2)} .node {BackgroundColor: var(--mantle)FontColor: var(--text)}</style>sprite $application_server #office#servers/application_server:application_server sprite $database_server #office#servers/database_server:database_server  nwdiag {Syntax Error? (Assumed diagram type: sequence)

MindMap#

示例:

@startmindmap
*[#lightgreen] root node
** some first level node
***_ second level node
***_ another second level node
***_ foo
***_ bar
***_ foobar
** another first level node
@endmindmap

渲染:

root nodesome first level nodesecond level nodeanother second level nodefoobarfoobaranother first level node
root nodesome first level nodesecond level nodeanother second level nodefoobarfoobaranother first level node

WBS#

示例:

@startwbs
+[#SkyBlue] Project
++ Part One
+++ Task 1.1
++++ LeftTask 1.2
+++ Task 1.3
++ Part Two
+++ Task 2.1
+++ Task 2.2
---_ Task 2.2.1 To the left boxless
---_ Task 2.2.2 To the Left boxless
+++_ Task 2.2.3 To the right boxless
@endwbs

渲染:

Part OneTask 1.1LeftTask 1.2Task 1.3Part TwoTask 2.2.1 To the left boxlessTask 2.2.2 To the Left boxlessTask 2.1Task 2.2Task 2.2.3 To the right boxlessProject
Part OneTask 1.1LeftTask 1.2Task 1.3Part TwoTask 2.2.1 To the left boxlessTask 2.2.2 To the Left boxlessTask 2.1Task 2.2Task 2.2.3 To the right boxlessProject

json/yaml#

示例:

@startjson
#highlight "lastName"
#highlight "address" / "city"
#highlight "phoneNumbers" / "0" / "number"
{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 28,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}
@endjson

渲染:

@startjson
#highlight "lastName"
#highlight "address" / "city"
#highlight "phoneNumbers" / "0" / "number"
{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 28,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}
@endjson

Theme 配置#

  • https://the-lum.github.io/puml-themes-gallery/themes/index.html