如何将PlantUML活动图中多个反向'no'箭头合并为单个箭头?
合并PlantUML活动图中多个'no'反向箭头的实现方法
原始问题场景
给定的活动图代码:
@startuml start while (Work to do?) is (found) if (Question 2 ?) then (yes) if (Question 3 ?) then (yes) if (Question 4 ?) then (yes) if (Question 5 ?) then (yes) :Success; break; else (no) endif else (no) endif else (no) endif else (no) endif endwhile (no more) end @enduml
上述代码生成的活动图中存在多个表示no的反向箭头(显示为多个方形节点),需求是将所有no分支的箭头合并为单个,汇总到同一节点。
实现方案:使用节点标记统一分支目标
可以实现,通过PlantUML的**节点标记(#标记名)**功能,将所有no分支的跳转目标指定为同一个节点,即可合并反向箭头。
修改后的代码
@startuml start #work_check:Work to do?; while (found) is (no more) if (Question 2 ?) then (yes) if (Question 3 ?) then (yes) if (Question 4 ?) then (yes) if (Question 5 ?) then (yes) :Success; break; else (no) -> #work_check; endif else (no) -> #work_check; endif else (no) -> #work_check; endif else (no) -> #work_check; endif endwhile end @enduml
说明
- 给循环的判断节点添加
#work_check标记,明确节点的唯一标识; - 所有
no分支通过-> #work_check;直接跳转到该标记节点,替代默认的反向箭头; - 最终生成的活动图中,所有
no分支会汇总到同一个判断节点,不会再出现多个独立的反向箭头方形。
内容的提问来源于stack exchange,提问作者bux




