举几个例子:
用例
用例用圆括号括起来(两个圆括号看起来就像椭圆)。
也可以用关键字usecase 来定义用例。
还可以用关键字as 定义一个别名,这个别名可以在以后定义关系的时候使用。
🎉 Copied!
|
@startuml
(First usecase)
(Another usecase) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml
|
角色用两个冒号包裹起来。
也可以用actor 关键字来定义角色。
还可以用关键字as 来定义一个别名,这个别名可以在以后定义关系的时候使用。
在后面的例子中,我们会看到角色的定义是可选的。
🎉 Copied!
|
@startuml
:First Actor:
:Another\nactor: as Man2
actor Woman3
actor :Last actor: as Person1
@enduml
|
可以将角色的样式从默认的火柴人改成:
- 用户头像样式:
skinparam actorStyle awesome
- 透明人样式:
skinparam actorStyle hollow
火柴人 默认
🎉 Copied!
|
@startuml
:User: --> (Use)
"Main Admin" as Admin
"Use the application" as (Use)
Admin --> (Admin the application)
@enduml
|
用户头像
🎉 Copied!
|
@startuml
skinparam actorStyle awesome
:User: --> (Use)
"Main Admin" as Admin
"Use the application" as (Use)
Admin --> (Admin the application)
@enduml
|
[参见 QA-10493]
透明人
🎉 Copied!
|
@startuml
skinparam actorStyle Hollow
:User: --> (Use)
"Main Admin" as Admin
"Use the application" as (Use)
Admin --> (Admin the application)
@enduml
|
[参见 PR#396]
如果想定义跨越多行的用例描述,可以用双引号将其裹起来。
还可以使用这些分隔符:
-- (横线)
.. (虚线)
== (双横线)
__ (下划线)
并且还可以在分隔符中间放置标题。
🎉 Copied!
|
@startuml
usecase UC1 as "You can use
several lines to define your usecase.
You can also use separators.
--
Several separators are possible.
==
And you can add titles:
..Conclusion..
This allows large description."
@enduml
|
您可以一使用包来对角色或用例进行分组。
🎉 Copied!
|
@startuml
left to right direction
actor Guest as g
package Professional {
actor Chef as c
actor "Food Critic" as fc
}
package Restaurant {
usecase "Eat Food" as UC1
usecase "Pay for Food" as UC2
usecase "Drink" as UC3
usecase "Review" as UC4
}
fc --> UC4
g --> UC1
g --> UC2
g --> UC3
@enduml
|
您可以使用rectangle 来改变包的外观。
🎉 Copied!
|
@startuml
left to right direction
actor "Food Critic" as fc
rectangle Restaurant {
usecase "Eat Food" as UC1
usecase "Pay for Food" as UC2
usecase "Drink" as UC3
}
fc --> UC1
fc --> UC2
fc --> UC3
@enduml
|
用箭头--> 连接角色和用例。
横杠- 越多,箭头越长。
通过在箭头定义的后面加一个冒号及文字的方式来添加标签。
在这个例子中,User并没有定义,而是直接拿来当做一个角色使用。
🎉 Copied!
|
@startuml
User -> (Start)
User --> (Use the application) : A small label
:Main Admin: ---> (Use the application) : This is\nyet another\nlabel
@enduml
|
如果一个角色或者用例继承于另一个,那么可以用<|-- 符号表示。
🎉 Copied!
|
@startuml
:Main Admin: as Admin
(Use the application) as (Use)
User <|-- Admin
(Start) <|-- (Use)
@enduml
|
可以用note left of , note right of ,
note top of , note bottom of 等关键字给一个对象添加注释。
注释还可以通过note 关键字来定义,然后用.. 连接其他对象。
🎉 Copied!
|
@startuml
:Main Admin: as Admin
(Use the application) as (Use)
User -> (Start)
User --> (Use)
Admin ---> (Use)
note right of Admin : This is an example.
note right of (Use)
A note can also
be on several lines
end note
note "This note is connected\nto several objects." as N2
(Start) .. N2
N2 .. (Use)
@enduml
|
用 <<
和 >> 来定义角色或者用例的构造类型。
🎉 Copied!
|
@startuml
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml
|
默认情况下,类之间的链接有两个破折号-- ,并且是垂直方向的。
可以通过像这样放一个破折号(或点)来使用水平链接。
🎉 Copied!
|
@startuml
:user: --> (Use case 1)
:user: -> (Use case 2)
@enduml
|
你也可以通过反转链接来改变方向。
🎉 Copied!
|
@startuml
(Use case 1) <.. :user:
(Use case 2) <- :user:
@enduml
|
也可以通过在箭头内添加left ,right ,up
或down 关键字来改变箭头方向。
🎉 Copied!
|
@startuml
:user: -left-> (dummyLeft)
:user: -right-> (dummyRight)
:user: -up-> (dummyUp)
:user: -down-> (dummyDown)
@enduml
|
你可以通过只使用方向的第一个字符来缩短箭头(例如,-d- ,而不是
-down- )
或两个第一个字符(-do- )。
请注意,你不应该滥用这个功能:Graphviz通常在没有
调整的情况下给出良好的结果。
并使用 left to right direction 参数。
🎉 Copied!
|
@startuml
left to right direction
:user: -left-> (dummyLeft)
:user: -right-> (dummyRight)
:user: -up-> (dummyUp)
:user: -down-> (dummyDown)
@enduml
|
用newpage 关键字将图示分解为多个页面。
🎉 Copied!
|
@startuml
:actor1: --> (Usecase1)
newpage
:actor2: --> (Usecase2)
@enduml
|
默认从上往下构建图示。
🎉 Copied!
|
@startuml
'default
top to bottom direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
|
你可以用left to right direction 命令改变图示方向。
🎉 Copied!
|
@startuml
left to right direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
|
用skinparam改变字体和颜色。
可以在如下场景中使用:
你也可以给构造的角色和用例指定特殊颜色和字体。
🎉 Copied!
|
@startuml
skinparam handwritten true
skinparam usecase {
BackgroundColor DarkSeaGreen
BorderColor DarkSlateGray
BackgroundColor<< Main >> YellowGreen
BorderColor<< Main >> YellowGreen
ArrowColor Olive
ActorBorderColor black
ActorFontName Courier
ActorBackgroundColor<< Human >> Gold
}
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml
|
🎉 Copied!
|
@startuml
left to right direction
skinparam packageStyle rectangle
actor customer
actor clerk
rectangle checkout {
customer -- (checkout)
(checkout) .> (payment) : include
(help) .> (checkout) : extends
(checkout) -- clerk
}
@enduml
|
你可以添加/ 来制作业务用例。
业务用例
🎉 Copied!
|
@startuml
(First usecase)/
(Another usecase)/ as (UC2)
usecase/ UC3
usecase/ (Last\nusecase) as UC4
@enduml
|
商业行为者
🎉 Copied!
|
@startuml
:First Actor:/
:Another\nactor:/ as Man2
actor/ Woman3
actor/ :Last actor: as Person1
@enduml
|
[Ref.QA-12179]
你可以使用以下的内联式符号改变单个箭头的颜色或样式。
#color;line.[bold|dashed|dotted];text:color
🎉 Copied!
|
@startuml
actor foo
foo --> (bar) : normal
foo --> (bar1) #line:red;line.bold;text:red : red bold
foo --> (bar2) #green;line.dashed;text:green : green dashed
foo --> (bar3) #blue;line.dotted;text:blue : blue dotted
@enduml
|
[参考QA-3770和QA-3816]
[参见部署图或类图的类似功能]
你可以用以下符号改变单个元素的颜色或样式。
#[color|back:color];line:color;line.[bold|dashed|dotted];text:color
🎉 Copied!
|
@startuml
actor a
actor b #pink;line:red;line.bold;text:red
usecase c #palegreen;line:green;line.dashed;text:green
usecase d #aliceblue;line:blue;line.dotted;text:blue
@enduml
|
[参考QA-5340和改编自QA-6852]
Simple example
🎉 Copied!
|
@startuml
allowmixing
actor Actor
usecase Usecase
json JSON {
"fruit":"Apple",
"size":"Large",
"color": ["Red", "Green"]
}
@enduml
|
[Ref. QA-15481]
For another example, see on JSON page.
|
|