【PlantUML系列】流程图(四)

目录

目录

一、基础用法

[1.1 开始和结束](#1.1 开始和结束)

[1.2 操作步骤](#1.2 操作步骤)

[1.3 条件判断](#1.3 条件判断)

[1.4 并行处理](#1.4 并行处理)

[1.5 循环](#1.5 循环)

[1.6 分区](#1.6 分区)

[1.7 泳道](#1.7 泳道)

一、基础用法

1.1 开始和结束

开始一般使用**++start++关键字;结束一般使用++stop/end++** 关键字。基础用法包括:

  • start ... stop

  • start ... end

    @startuml
    start
    :执行操作A;
    stop
    @enduml

1.2 操作步骤

语法为++:operation++ ,其中 operation 是你为该步骤定义的名称。例如:

复制代码
@startuml
:开始;
:执行操作A;
:执行操作B;
:结束;
@enduml

1.3 条件判断

使用PlantUML语法通常使用++if-else++关键字。通常由三种语法:

  • if (...) then (...) ... [else (...) ...] endif
  • if (...) is (...) then ... [else (...) ...] endif
  • if (...) equals (...) then ... [else (...) ...] endif

例如:

复制代码
@startuml
:开始;
:执行操作A;
:判断是否满足条件;
if (满足条件) then (是)
  :执行操作B;
else (否)
  :执行操作C;
endif

if (条件) is (是) then
   :执行操作D;
else
   :执行操作E;
endif

if (条件) equals (是) then
   :执行操作F;
else
   :执行操作G;
endif
:结束;
@enduml

多分支判断使用++elseif++关键字,其中包含水平模式、垂直模式;

  • 水平模式

    @startuml
    start
    if (condition A) then (yes)
    :Text 1;
    elseif (condition B) then (yes)
    :Text 2;
    stop
    (no) elseif (condition C) then (yes)
    :Text 3;
    (no) elseif (condition D) then (yes)
    :Text 4;
    else (nothing)
    :Text else;
    endif
    stop
    @enduml

  • 垂直模式 :使用**!pragma useVerticalIf on**进入垂直模式。

    ​@startuml
    start
    !pragma useVerticalIf on
    if (condition A) then (yes)
    :Text 1;
    elseif (condition B) then (yes)
    :Text 2;
    stop
    (no) elseif (condition C) then (yes)
    :Text 3;
    (no) elseif (condition D) then (yes)
    :Text 4;
    else (nothing)
    :Text else;
    endif
    stop
    @enduml

1.4 并行处理

并行处理可以用 forkjoin 来表示,fork 表示分支开始,merge 表示分支合并。

  • fork ... fork again ... end fork

  • fork ... fork again ... end merge

    @startuml
    start
    fork
    :action 1;
    fork again
    :action 2;
    end fork

    fork
    :action 3;
    fork again
    :action 4;
    end merge
    stop
    @enduml

1.5 循环

循环包括无条件循环(Repeat loop)、有条件循环(While loop),典型的写法包括:

  • repeat ... repeat while (...) is (...) not (...)
  • repeat ... backward ... repeat while (...) is (...) -> (...)
  • while (...) end while

repeat案例:

复制代码
@startuml
start

repeat
  :read data;
  :generate diagrams;
repeat while (more data?) is (yes) not (no)

repeat
  :read data;
  :generate diagrams;
backward :write data;
repeat while (more data?) is (yes)
-> no;
  :next action;

while (check filesize ?) is (not empty)
  :read file;
  backward:log;
endwhile (empty)
:close file;

stop
@enduml

1.6 分区

在PlantUML中,Partition 是用来定义分区的关键字,它允许你将多个活动组合在一起。

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

stop
@enduml

1.7 泳道

在PlantUML中,使用++|Swimlane1|++来表示泳道,例如:

复制代码
@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml

参考资料:New Activity Diagram Beta syntax and features

相关推荐
数据爬坡ing6 天前
软件工程总体设计:从抽象到具体的系统构建之道
数据库·流程图·软件工程·可用性测试·软件需求
zzywxc7876 天前
深入解析大模型落地的四大核心技术:微调、提示词工程、多模态应用 及 企业级解决方案,结合代码示例、流程图、Prompt案例及技术图表,提供可落地的实践指南。
人工智能·深度学习·机器学习·数据挖掘·prompt·流程图·editplus
sjzmj68139 天前
脑洞大开——AI流程图如何改变思维?
人工智能·信息可视化·流程图·数据可视化
风口的程序猿10 天前
Vue自定义流程图式菜单解决方案
流程图·vue-router优化·显式业务流程管理·vue菜单优化·流程式菜单
wcy011212 天前
vue3+vue-flow制作简单可拖拽可增删改流程图
javascript·vue.js·流程图
zzywxc78712 天前
深入探讨AI在测试领域的三大核心应用:自动化测试框架、智能缺陷检测和A/B测试优化,并通过代码示例、流程图和图表详细解析其实现原理和应用场景。
运维·人工智能·低代码·架构·自动化·流程图·ai编程
hetongqiyue13 天前
orbslam2 localMapping流程图
流程图
c_zyer15 天前
Mermaid流程图可视化系统:基于Spring Boot与Node.js的三层架构实现
spring boot·node.js·流程图·mermaid
范纹杉想快点毕业16 天前
基于 C 语言视角:流程图中分支与循环结构的深度解析
c语言·stm32·单片机·设计模式·架构·流程图·uml
火车叨位去194922 天前
用Java实现rpc的逻辑和流程图和核心技术与难点分析
java·rpc·流程图