You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PlantUML状态图中能否将状态相对其他状态定位?附场景示例

实现PlantUML状态图的水平布局(将MainActivity放在Idle右侧)

没问题!PlantUML完全支持状态的相对定位,能轻松帮你把MainActivity状态放到Idle状态的右侧,让[instruction]和[done]箭头呈现水平方向。

修改后的完整PlantUML脚本

@startuml
skinparam state {
StartColor PaleGreen
EndColor Red
BackgroundColor Gold
BackgroundColor<<Junction>> GreenYellow
BorderColor Gray
FontName Consolas
}
[*] -> Creating
Creating --> Idle : initialised
Idle : wait here for instructions
# 核心定位语法:指定MainActivity在Idle的右侧
state MainActivity right of Idle {
[*] --> DoFirstThing
DoFirstThing --> FirstThingSuccess : [OK]
DoFirstThing --> FirstThingFailed : [not OK]
FirstThingSuccess --> SecondThing
SecondThing --> SecondThingFailed
SecondThing --> SecondThingSuccess
SecondThingSuccess --> WritingReport
SecondThingFailed --> WritingReport
FirstThingFailed --> WritingReport
WritingReport --> [*]
}
Idle --> MainActivity : [instruction]
MainActivity --> Idle : [done]
@enduml

关键改动说明

  • 在定义MainActivity复合状态时,添加right of Idle声明,这是PlantUML的相对定位语法,直接指定该状态的位置在Idle的右侧。
  • 完成这个改动后,Idle到MainActivity的[instruction]箭头,以及MainActivity回到Idle的[done]箭头会自动切换为水平方向,完美匹配你的需求。

如果需要更精细的布局调整,还可以使用其他相对定位关键字:

  • left of <目标状态>:将状态放在目标左侧
  • above <目标状态>:将状态放在目标上方
  • below <目标状态>:将状态放在目标下方
  • 还可以搭配#distance <数值>参数调整状态间的间距,比如state MainActivity right of Idle #distance 30

内容的提问来源于stack exchange,提问作者user11982735

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:58:21