PlantUml + VS code 绘图体验

hxy    2020-05-16 17:06

        现阶段各种绘图方式正逐渐从“所见即所得” 到 “所想即所得”转变,越来越多的人倾向于使用代码生成绘图,不仅样式美观,还省去了大量调整工作,并且修改起来极为方便。类似的思想可见 LaTex 的流行、Graphviz, pycharts等。当然,今天关注的是 PlantUml,一个功能强大的生成图工具。包括且不限于以下功能: 根据官网对PlantUml的介绍,同时还支持以下非UML图: PlantUml提供了在线演示的功能, 输入少量代码即可生成时序图,示例如下:
Bob->Alice : hello
生成时序图效果如下:

这么强大的功能,怎么能少的了VS Code呢,于是在VS Code 的应用商店搜索 plantuml 安装插件,即可享受丝滑般绘图体验。
安装完成后,新建 demo.pu 文件(支持*.wsd, *.pu, *.puml, *.plantuml, *.iuml格式,选了一个最简短的扩展名),输入如下代码:
@startuml
用户 -> 认证中心: 登录操作
认证中心 -> 缓存: 存放(key=token+ip,value=token)token

用户 <- 认证中心 : 认证成功返回token
用户 -> 认证中心: 下次访问头部携带token认证
认证中心 <- 缓存: key=token+ip获取token
其他服务 <- 认证中心: 存在且校验成功则跳转到用户请求的其他服务
其他服务 -> 用户: 信息
@enduml
即可得到如下时序图:
再来看几个其他例子:
用例图:
@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
活动图:
@startuml
start

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

stop
@enduml
组织结构图:

注意:有些 UML图需要安装graphviz工具包,并设置环境变量。 
@startuml
skinparam rectangle<<behavior>> {
	roundCorner 25
}
sprite $bProcess jar:archimate/business-process
sprite $aService jar:archimate/application-service
sprite $aComponent jar:archimate/application-component

rectangle "Handle claim"  as HC <<$bProcess>><<behavior>> #Business
rectangle "Capture Information"  as CI <<$bProcess>><<behavior>> #Business
rectangle "Notify\nAdditional Stakeholders" as NAS <<$bProcess>><<behavior>> #Business
rectangle "Validate" as V <<$bProcess>><<behavior>> #Business
rectangle "Investigate" as I <<$bProcess>><<behavior>> #Business
rectangle "Pay" as P <<$bProcess>><<behavior>> #Business

HC *-down- CI
HC *-down- NAS
HC *-down- V
HC *-down- I
HC *-down- P

CI -right->> NAS
NAS -right->> V
V -right->> I
I -right->> P

rectangle "Scanning" as scanning <<$aService>><<behavior>> #Application
rectangle "Customer admnistration" as customerAdministration <<$aService>><<behavior>> #Application
rectangle "Claims admnistration" as claimsAdministration <<$aService>><<behavior>> #Application
rectangle Printing <<$aService>><<behavior>> #Application
rectangle Payment <<$aService>><<behavior>> #Application

scanning -up-> CI
customerAdministration  -up-> CI
claimsAdministration -up-> NAS
claimsAdministration -up-> V
claimsAdministration -up-> I
Payment -up-> P

Printing -up-> V
Printing -up-> P

rectangle "Document\nManagement\nSystem" as DMS <<$aComponent>> #Application
rectangle "General\nCRM\nSystem" as CRM <<$aComponent>>  #Application
rectangle "Home & Away\nPolicy\nAdministration" as HAPA <<$aComponent>> #Application
rectangle "Home & Away\nFinancial\nAdministration" as HFPA <<$aComponent>>  #Application

DMS .up.|> scanning
DMS .up.|> Printing
CRM .up.|> customerAdministration
HAPA .up.|> claimsAdministration
HFPA .up.|> Payment

legend left
Example from the "Archisurance case study" (OpenGroup).
See
==
<$bProcess> :business process
==
<$aService> : application service
==
<$aComponent> : application component
endlegend
@enduml
树状图:
@startmindmap
+ OS
++ Ubuntu
+++ Linux Mint
+++ Kubuntu
+++ Lubuntu
+++ KDE Neon
++ LMDE
++ SolydXK
++ SteamOS
++ Raspbian
-- Windows 95
-- Windows 98
-- Windows NT
--- Windows 8
--- Windows 10
@endmindmap




参考资料:
  1. https://plantuml.com/zh/
Last Modified: 2020-07-01 15:08
Views: 111
免责声明:网站内容仅供个人学习记录,禁做商业用途。 版权所有 © 2017-2020 NEUSNCP个人学习笔记 辽ICP备17017855号-2