PlantUML组件相对位置异常问题及布局调整咨询
PlantUML组件布局控制方案
当给BottomStretch组件添加内部元素(如portin)后,自动布局会导致组件偏移,可通过以下方法固定相对位置并实现左右对齐:
实现代码
@startuml ' 明确布局方向,避免自动布局干扰 left to right direction component TopLeft component TopRight ' 强制顶部两个组件处于同一水平层级 rank same TopLeft, TopRight TopLeft -[hidden]r- TopRight component BottomStretch { portin port_test } ' 绑定BottomStretch左边缘与TopLeft左边缘对齐 TopLeft -[hidden,d]-- BottomStretch : align left ' 绑定BottomStretch右边缘与TopRight右边缘对齐 TopRight -[hidden,d]-- BottomStretch : align right @enduml
关键逻辑说明
rank same TopLeft, TopRight:强制顶部两个组件在同一水平层,确保初始横向布局稳定- 带
align left/align right的隐藏连线:分别将底部组件的左右边缘与顶部两个组件的对应边缘绑定,即使底部组件内部有内容,也会保持对齐关系,不会出现偏移 left to right direction:明确布局方向,减少自动布局的不确定性,让位置控制更精准
内容的提问来源于stack exchange,提问作者user9893356
相关产品推荐
相关产品推荐

