Рассмотрим несколько примеров:
Заметьте, что Вы можете отключить тени, используя команду skinparam shadowing false.
Use Case Diagram
Let's have a few examples:
Прецеденты
Прецеденты заключаются в две скобки (потому что две скобки выглядят как овал).
Вы можете использовать usecase для создания прецедента.
также вы можете создать псевдоним, используя as keyword. Этот пседоним
будет использоваться позже во время определения связей
@startuml
(First usecase)
(Another usecase) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml
Usecases
Use cases are enclosed using between parentheses (because two
parentheses looks like an oval).
You can also use the usecase keyword to define a
usecase.
And you can define an alias, using the as keyword.
This alias will be used later, when defining relations.
@startuml
(First usecase)
(Another usecase) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml
Актёры
Определить актёра можно заключив его значение между дветочиями.
Также Вы можете использовать ключевое слово actor для определения актёра.
И вы можете создать псевдоним, используя ключевое слово as. Этот псевдоним будет использован позднее, при определении отношений.
Мы увидим, что определения актеров не обязательны.
@startuml
:First Actor:
:Another\nactor: as Men2
actor Men3
actor :Last actor: as Men4
@enduml
Actors
The name defining an actor is enclosed between colons.
You can also use the actor keyword to define an actor.
An alias can be assigned using the as keyword and can be used later instead of the actor's name, e. g. when defining relations.
You can see from the following examples, that the actor definitions are optional.
@startuml
:First Actor:
:Another\nactor: as Man2
actor Woman3
actor :Last actor: as Person1
@enduml
Change Actor style
You can change the actor style from stick man (by default) to:
an awesome man with the skinparam actorStyle awesome command;
a hollow man with the skinparam actorStyle hollow command.
Stick man (by default)
@startuml
:User: --> (Use)
"Main Admin" as Admin
"Use the application" as (Use)
Admin --> (Admin the application)
@enduml
Awesome man
@startuml
skinparam actorStyle awesome
:User: --> (Use)
"Main Admin" as Admin
"Use the application" as (Use)
Admin --> (Admin the application)
@enduml
Если вы хотите описание на несколько строк, можете использовать кавычки.
Вы также можете использовать следующие разделители: --..==__.
И вы можете вставлять заголовки внутри разделителей.
@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
Usecases description
If you want to have a description spanning several lines, you can use quotes.
You can also use the following separators:
-- (dashes)
.. (periods)
== (equals)
__ (underscores)
By using them pairwise and enclosing text between them, you can created separators with titles.
@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
Использование пакетов
Чтобы сгруппировать актёров или прецеденты, можно использовать пакеты.
@startuml
left to right direction
actor "Food Critic" as fc
package Restaurant {
usecase "Eat Food" as UC1
usecase "Pay for Food" as UC2
usecase "Drink" as UC3
}
fc --> UC1
fc --> UC2
fc --> UC3
@enduml
Для изменения венешнего вида пакета можно воспользоваться rectangle.
@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
Use package
You can use packages to group actors or use cases.
@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
You can use rectangle to change the display of the package.
@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 не определён ранее
и используется как актёр.
@startuml
User -> (Start)
User --> (Use the application) : A small label
:Main Admin: ---> (Use the application) : This is\nyet another\nlabel
@enduml
Basic example
To link actors and use cases, the arrow --> is
used.
The more dashes - in the arrow, the longer the
arrow.
You can add a label on the arrow, by adding a :
character in the arrow definition.
In this example, you see that User has not been defined
before, and is used as an actor.
@startuml
User -> (Start)
User --> (Use the application) : A small label
:Main Admin: ---> (Use the application) : This is\nyet another\nlabel
@enduml
Расширение
Если один актёр/прецедент расширяют другой, вы можете использовать символ <|--.
@startuml
:Main Admin: as Admin
(Use the application) as (Use)
User <|-- Admin
(Start) <|-- (Use)
@enduml
Extension
If one actor/use case extends another one, you can use the symbol <|--.
@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
, а затем прикреплена к другому объекту используя символ ...
@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
Using notes
You can use the note left of , note right of ,
note top of , note bottom of keywords to
define notes related to a single object.
A note can be also define alone with the note
keywords, then linked to other objects using the .. symbol.
@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
Шаблоны
Вы можете добавить шаблоны когда определяете актёров и прецеденты, используя <<
и >>.
@startuml
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml
Stereotypes
You can add stereotypes while defining actors and use cases using << and >>.
@startuml
User << Human >>
:Main Database: as MySql << Application >>
(Start) << One Shot >>
(Use the application) as (Use) << Main >>
User -> (Start)
User --> (Use)
MySql --> (Use)
@enduml
Смена направления стрелок
По умолчанию, связи между классами имеют два тире -- и вертикально ориентированны.
можно использовать горизонтальные связи, с помощью написание одного тире (или точки), вот так:
@startuml
:user: --> (Use case 1)
:user: -> (Use case 2)
@enduml
Вы так же можете изменить направление с помощью переворачивания связи:
@startuml
(Use case 1) <.. :user:
(Use case 2) <- :user:
@enduml
Так же возможно сменить направление добавляя ключевые слова left, right, up
или down внутри стрелки:
Вы можете записать короче, используя только первый символ названия направления
(например, -d- вместо -down-) или первые два
символа (-do-).
Пожалуйста, помните, что Вы не должны использовать эту функциональность без реальной необходимости: GraphViz
обычно даёт хороший результат без дополнительных настроек.
Changing arrows direction
By default, links between classes have two dashes -- and are vertically oriented.
It is possible to use horizontal link by putting a single dash (or dot) like this:
@startuml
:user: --> (Use case 1)
:user: -> (Use case 2)
@enduml
You can also change directions by reversing the link:
@startuml
(Use case 1) <.. :user:
(Use case 2) <- :user:
@enduml
It is also possible to change arrow direction by adding left, right, up
or down keywords inside the arrow:
You can shorten the arrow by using only the first character of the direction (for example, -d- instead of
-down-)
or the two first characters (-do-).
Please note that you should not abuse this functionality : Graphviz gives usually good results without
tweaking.
And with the left to right direction parameter:
@startuml
left to right direction
:user: -left-> (dummyLeft)
:user: -right-> (dummyRight)
:user: -up-> (dummyUp)
:user: -down-> (dummyDown)
@enduml
Разделение диаграмм
Ключевое слово newpage используется для разделения диаграмм на несколько страниц или изображений.
Общее поведение по умолчанию - построение диаграмм сверху вниз.
@startuml
'default
top to bottom direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
Вы можете изменить направление на слева напрво используя команду left to right direction. Часто результат с таким направлением выглядит лучше.
@startuml
left to right direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
Left to right direction
The general default behavior when building diagram is top to bottom.
@startuml
'default
top to bottom direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
You may change to left to right using the left to right direction command.
The result is often better with this direction.
@startuml
left to right direction
user1 --> (Usecase 1)
user2 --> (Usecase 2)
@enduml
Skinparam
Вы можете использовать команду skinparam для изменения шрифтов и цветов диаграммы
Вы можете использовать данную команду :
В определении диаграммы, как любую другую команду,
В подключенном файле,
В конфигурационном файле, указанном в командной строке в задании ANT.
Вы можете задать цвет или шрифт для актёров или прецедентов с шаблонами.
@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
Skinparam
You can use the skinparam
command to change colors and fonts for the drawing.
You can use this command :
In the diagram definition, like any other commands,
You can define specific color and fonts for stereotyped actors and usecases.
@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
Полноценный пример
@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
Complete example
@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
Business Use Case
You can add / to make Business Use Case.
Business Usecase
@startuml
(First usecase)/
(Another usecase)/ as (UC2)
usecase/ UC3
usecase/ (Last\nusecase) as UC4
@enduml
Business Actor
@startuml
:First Actor:/
:Another\nactor:/ as Man2
actor/ Woman3
actor/ :Last actor: as Person1
@enduml
@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