Plantuml两个类之间有多个箭头。

3
我正在尝试绘制一个类图,其中定义了两个类之间的多个关系和多重性。默认情况下,结果很糟糕。
@startuml

class Movie {
    genres: String[]
    minutes: Integer
    movie_id: String
    rating: Float
    title: String
    type: String
    votes: Integer
    year: Integer
}

class Person {
    birthYear: Integer
    deathYear: Integer
    name: String
    person_id: String
}

Person "0..*" -> "1..*" Movie : acted_in
Person "0..*" -> "1..*" Movie : directed
Person "0..*" -> "1..*" Movie : produced
Person "0..*" -> "1..*" Movie : wrote

@enduml

Output of default layout

使用skinparam nodesep 200可以改善一些,但是多重性仍然存在问题:

Output with nodesep 200

我还尝试了skinparam linetype ortho,看起来很有前途,但是一旦我也添加了hide circlehide methods,它就变得混乱了...

Output with linetype ortho, hide circle and hide methods

不要忘记,最终我还想添加一个关联类,这真的会破坏它:

Output with association class

这是最终代码:

skinparam nodesep 200
skinparam linetype ortho
hide circle
hide methods

class Movie {
    genres: String[]
    minutes: Integer
    movie_id: String
    rating: Float
    title: String
    type: String
    votes: Integer
    year: Integer
}

class Person {
    birthYear: Integer
    deathYear: Integer
    name: String
    person_id: String
}

Person "0..*" -> "1..*" Movie : acted_in
Person "0..*" -> "1..*" Movie : directed
Person "0..*" -> "1..*" Movie : produced
Person "0..*" -> "1..*" Movie : wrote
(Person,Movie) .. Role

class Role {
    name: String
}

@enduml

我的问题是:是否有一种方法可以使用PlantUML正确绘制这个图形?

尝试让关联类上升?(人物,电影) .up. 角色 - Fuhrmanator
2个回答

1
我不知道如何直接实现更易读的箭头布局,但您可以通过将“人”作为四个子类(演员、导演、制片人和编剧)的概括来避免这个问题。每个子类都有单独的箭头,这可能会使您的图表也更加清晰(当然,这取决于您的口味和图表的目的)。

谢谢,这是一个好的观点。不幸的是,对于我的目的,我需要原样的图表。 - bp99

0
你需要让类显示得更大,这样就会有更多的空间来渲染关联。目前没有针对这个的skinparam(唯一的一个是minWidth)。但是通过一个技巧,你可以让类的主体变大。 planuml example planuml代码:

@startuml

skinparam ranksep 150
skinparam linetype ortho
left to right direction
hide methods
skinparam style strictuml


class Movie {
    genres: String[]
    minutes: Integer
    movie_id: String
    rating: Float
    title: String
    type: String
    votes: Integer
    year: Integer
    \n\n\n\n\n\n
}

class Person {
    birthYear: Integer
    deathYear: Integer
    name: String
    person_id: String
    \n\n\n\n\n\n\n
}

(Person,Movie) . Role
Person "0..*" - " 1..* " Movie : acted_in
Person "0..*" -> " 1..* " Movie : directed
Person "0..*" -> " 1..* " Movie : produced
Person "\n\n0..*" - "\n\n1..*" Movie : wrote

class Role {
    name: String
}
@enduml


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