markdown 流程图js_Markdown 进阶 - PlantUML 绘图

PlantUML是一个开源的UML图形绘制工具,适用于Markdown和HTML,提供了包括流程图、时序图、Gantt图在内的多种图表。它可以看作是Graphviz的封装,相比Mermaid.js,PlantUML支持更多图形类型。安装PlantUML需要先装GraphViz,然后在VSCode中安装Markdown Preview Enhanced和PlantUML扩展,即可在Markdown文件中使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文使用 Zhihu On VSCode 创作并发布

PlantUML 是基于 Java 语言的开源 UML(Unified Modeling Language)图形绘制工具,因为其可以单独绘图,又可以嵌入 Markdown 以及 HTML,因而被不少开发文档采用。PlantUML 可以看作是著名绘图工具 Graphviz 的封装。相比于 Graphviz 的 Geek 风,PlantUML 的颜值更高。而与 Mermaid.js 相比,其支持的图形种类更为多样。

PlantUML 支持的图形可简单分为三种类型

  • 基本类:流程图、时序图、Gantt 图
  • 工程类:类图、实体关系图、用例图、组件图
  • 导图类:思维导图、组织结构导图
    当然在上述提及的图形之外,PlantUML 还支持一些其他的图形,详情请见官网
https://plantuml.com​plantuml.com

关于 PlantUML 的使用也不复杂,先安装 GraphViz,建议使用包管理器安装

关于包管理器的使用,本专栏里有专门的介绍,这里不再赘述

对 Windows,使用 Scoop 或 Chocolatey

scoop install graphviz
choco install graphviz

对 MacOS,使用 Homebrew

brew cask install graphviz

在 VSCode 中,安装2个扩展

  • Markdown Preview Enhanced
  • PlantUML

5073acb200f2919daaffb86caeb10936.png

然后,就可以在 Markdown 愉快地使用 PlantUML 了。

基本类型

流程图

e32d0794816a4147f6147499f62f8d98.png
@startuml

start
:new page;
if (Page.onSecurityCheck) then (true)
  :Page.onInit();
  if (isForward?) then (no)
    if (continue processing?) then (no)
      stop
    endif

    if (isPost?) then (yes)
      :Page.onPost();
    else (no)
      :Page.onGet();
    endif
    :Page.onRender();
  endif
else (false)
endif

stop

@enduml

时序图

e1d2d1330d2c9bea6951c2ec99e8ab03.png
@startuml

== Initialization ==

Alice -> Bob: : Can you solve: <math>ax^2+bx+c=0</math>
Bob --> Alice: <math>x = (-b+-sqrt(b^2-4ac))/(2a)</math>
activate Alice #FFBBBB
note left: this is a first note

Alice -> Bob: Another dialogue
deactivate Alice

Alice <-- Bob: Another dialogue

@enduml

Gantt 图

3edd361b8a8cf96a6036495c7eb501bd.png
@startuml
[Prototype design] lasts 13 days and is colored in Lavender/LightBlue

[Test prototype] lasts 9 days and is colored in Coral/Green and starts 3 days after [Prototype design]'s end

[Write tests] lasts 5 days and ends at [Prototype design]'s end

[Hire tests writers] lasts 6 days and ends at [Write tests]'s start

[Init and write tests report] is colored in Coral/Green

[Init and write tests report] starts 1 day before [Test prototype]'s start and ends at [Test prototype]'s end
@enduml

工程类

类图

9247dd4f062660aa89515404a66f0944.png
@startuml
Class01 <|-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
@enduml

状态图

1d71c992ddd3118ea923d9e154aa45c0.png
@startuml
scale 350 width
[*] --> NotShooting

state NotShooting {
  [*] --> Idle
  Idle --> Configuring : EvConfig
  Configuring --> Idle : EvConfig
}

state Configuring {
  [*] --> NewValueSelection
  NewValueSelection --> NewValuePreview : EvNewValue
  NewValuePreview --> NewValueSelection : EvNewValueRejected
  NewValuePreview --> NewValueSelection : EvNewValueSaved

  state NewValuePreview {
     State1 -> State2
  }

}
@enduml

实体关系图

60ec0ff845608c68488768ee4db04c66.png
@startuml

' hide the spot
hide circle

' avoid problems with angled crows feet
skinparam linetype ortho

entity "Entity01" as e01 {
  *e1_id : number <<generated>>
  --
  *name : text
  description : text
}

entity "Entity02" as e02 {
  *e2_id : number <<generated>>
  --
  *e1_id : number <<FK>>
  other_details : text
}

entity "Entity03" as e03 {
  *e3_id : number <<generated>>
  --
  e1_id : number <<FK>>
  other_details : text
}

e01 ||..o{ e02
e01 |o..o{ e03

@enduml

用例图

b34c4da16e54578fe8a53b89e329fb81.png
@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

组件图

4188461ae349e0d2980a2075d1dfd851.png
@startuml

package "Some Group" {
  HTTP - [First Component]
  [Another Component]
}

node "Other Groups" {
  FTP - [Second Component]
  [First Component] --> FTP
}

cloud {
  [Example 1]
}

database "MySql" {
  folder "This is my folder" {
    [Folder 3]
  }
  frame "Foo" {
    [Frame 4]
  }
}

[Another Component] --> [Example 1]
[Example 1] --> [Folder 3]
[Folder 3] --> [Frame 4]

@enduml

导图类

思维导图

f26d49647089447abfe7612794284ee0.png
@startmindmap
+ OS
++ Ubuntu
+++ Linux Mint
+++ Kubuntu
+++ Lubuntu
+++ KDE Neon
++ LMDE
++ SolydXK
++ SteamOS
++ Raspbian
-- Windows 95
-- Windows 98
-- Windows NT
--- Windows 8
--- Windows 10

header
My super header
endheader

center footer My super footer

legend right
  Short
  legend
endlegend
@endmindmap

组织结构导图

5dec8625939c1f857c600d2083bd363d.png
@startwbs
+ New Job
++ Decide on Job Requirements
+++ Identity gaps
+++ Review JDs
++++ Sign-Up for courses
++++ Volunteer
++++ Reading
++- Checklist
+++- Responsibilities
+++- Location
++ CV Upload Done
+++ CV Updated
++++ Spelling & Grammar
++++ Check dates
---- Skills
+++ Recruitment sites chosen
@endwbs

@startwbs
+ New Job
++ Decide on Job Requirements
+++ Identity gaps
+++ Review JDs
++++ Sign-Up for courses
++++ Volunteer
++++ Reading
++- Checklist
+++- Responsibilities
+++- Location
++ CV Upload Done
+++ CV Updated
++++ Spelling & Grammar
++++ Check dates
---- Skills
+++ Recruitment sites chosen
@endwbs
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值