Plantuml 两个类之间的几个箭头

发布于 2025-01-20 04:05:27 字数 2015 浏览 2 评论 0 原文

我试图绘制一个类图,其中两个类之间的几种关系是用多重性定义的。

默认情况下,结果很糟糕:

@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

默认布局的输出

使用 skinparam Nodesep 200 会好一点,但多重性仍然关闭:

节点数为 200 的输出

我还尝试过使用 skinparam linetype ortho,它看起来很有前途,但一旦我添加了 hide Circle隐藏方法...

使用线型正交、隐藏圆和隐藏方法输出

更不用说最终我还想添加一个关联类,这确实毁了它:

带有关联类的输出

这是最终的代码:

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 正确绘制它?

I am trying to draw a class diagram where several relationships between two classes are defined with multiplicities.

By default, the results are horrible:

@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

With skinparam nodesep 200 it is a little better, but the multiplicities are still off:

Output with nodesep 200

I also tried with skinparam linetype ortho, which looked promising, but gets messed up as soon as I also add hide circle and hide methods

Output with linetype ortho, hide circle and hide methods

Not to mention that eventually I would also like to add an association class, which really ruins it:

Output with association class

Here is the final code:

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

My question is: is there a way to draw this properly with PlantUML?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

通知家属抬走 2025-01-27 04:05:27

我不知道如何直接达到更清晰的箭头布局的目标,但您可以通过使用 Person 作为四个子类(例如 Actor、Director、Producer 和 ScreenplayWriter)的泛化来避免该问题。每一个都有单独的箭头,它可能会让你的图表总体上更清晰(当然,后者取决于你的品味和图表的目的)

I don’t know how to directly reach your goal of a more legible arrow layout but you could avoid the problem by using Person as a generalisation for four sub-classes such as Actor, Director, Producer and ScreenplayWriter. Each of these would have separate arrows and it might make your diagramme also generally clearer (the latter is, of course, subject to your taste and the diagramme’s purpose)

赏烟花じ飞满天 2025-01-27 04:05:27

您必须使课程看起来更大,因此将有更多的协会渲染空间。没有Skinparam(唯一的一个是最小的)。但是有了一个技巧,您可以使班级身体更大。

planuml示例

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

You have to make class appear bigger, so there will be more space for associations to render. There is no skinparam for that (the only one is for minWidth). But with a trick, you can make class body bigger.

planuml example

planuml code:

@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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文