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

如何让PlantUML中IIngredient抽象类居中,子类环绕排布?

调整PlantUML类图布局:让抽象类居中,子类环绕

当前使用的PlantUML代码

@startuml
'https://plantuml.com/component-diagram


together {
class Rice {

}
class Egg extends IIngredient{

}
class Avocado extends IIngredient{

}
IIngredient <|-- Rice
}

abstract class IIngredient {
  @protected
  List<String>? allergens;
  @protected
  String? name;
  @protected
  int? price;

  String? getAllergens()
  String? getName()
  int? getPrice()
}

class Salmon {

}
class Tuna {

}
IIngredient <|-- Salmon
IIngredient <|-- Tuna

class Sesame extends IIngredient{

}

class Crisp extends IIngredient {

}
@enduml

当前生成的类图效果

当前效果

期望的布局效果

期望布局

修改后的代码(实现居中环绕布局)

@startuml
' 设置布局为环绕中心类
circle IIngredient

abstract class IIngredient {
  @protected
  List<String>? allergens;
  @protected
  String? name;
  @protected
  int? price;

  String? getAllergens()
  String? getName()
  int? getPrice()
}

' 统一继承关系写法,去掉不必要的together块
class Rice extends IIngredient {}
class Egg extends IIngredient {}
class Avocado extends IIngredient {}
class Salmon extends IIngredient {}
class Tuna extends IIngredient {}
class Sesame extends IIngredient {}
class Crisp extends IIngredient {}

@enduml

关键调整说明

  • 移除原代码中的together块,避免强制类聚集,影响自动布局逻辑
  • 添加circle IIngredient指令,让所有继承该抽象类的子类自动环绕在其周围
  • 统一使用extends关键字定义继承关系,简化代码结构
  • 清理类定义中的冗余空行,保持代码整洁

内容的提问来源于stack exchange,提问作者Cyrus the Great

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 17:22:43