UML - 如何垂直对齐带有子类的类图

3
在附加的UML图中有5个类,我想知道如何使A、B和C类的顶部垂直对齐,而子类保持对齐。请查看我的UML代码和截图。
非常感谢您的支持!:) 当前的外观:

enter image description here

它应该看起来像什么(绘制编辑):

enter image description here

UML - 代码:

@startuml TestClassDiagram
scale 800 width
skinparam SameClassWidth true
skinparam ClassFontSize 15

class classA {
{field}  - attribute1  : int
{field}  - attribute2  : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}

class classB {
{field}  - attribute1 : int
{field}  - attribute2 : int
{method} + method1(void)
{method} + method2(void)
}
class classBchild     {
{method} + method1(void)    
}

class classC {
{field}  - attribute1  : int
{field}  - attribute2  : int
{field}  - attribute3  : int
{field}  - attribute4  : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}
class classCchild {
{method} + method1(void)   
}

classB <|-- classBchild
classC <|-- classCchild

@enduml

从互联网上找到的其他问题来看,似乎不可能。 - albert
谢谢你的快速回复,Albert!这很令人悲伤 :-P - HKC72
1个回答

2

目前 PlantUML 没有对齐类的功能。

如果我们在所有元素之间添加箭头,就可以清楚地看到 PlantUML 的尝试:

它只是将所有图表从中间对齐。

使用此方法,我们可以创建一个“黑客”方式,通过填充类定义与额外的换行符直到它们都相同大小,有点实现您想要的结果:

@startuml
skinparam {
    SameClassWidth true
    ClassFontSize 15
}

class A as "classA" {
    {field}  - attribute1  : int
    {field}  - attribute2  : int


    __
    {method} + method1(void)
    {method} + method2(void)
    {method} + method3(void)
    {method} + method4(void)
    {method} + method5(void)
}

class B as "classB" {
    {field}  - attribute1 : int
    {field}  - attribute2 : int


    __
    {method} + method1(void)
    {method} + method2(void)



}

class Bc as "classBchild"     {
    {method} + method1(void)    
}

class C as "classC" {
    {field}  - attribute1  : int
    {field}  - attribute2  : int
    {field}  - attribute3  : int
    {field}  - attribute4  : int

    {method} + method1(void)
    {method} + method2(void)
    {method} + method3(void)
    {method} + method4(void)
    {method} + method5(void)
}

class Cc as "classCchild" {
    {method} + method1(void)   
}

B <|-- Bc
C <|-- Cc
@enduml

1
太好了!这个解决方案对我来说与所请求的格式具有相同的价值 :) 非常感谢!!! - HKC72

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接