• Use PlantUML to write the Sequence Diagram


    Sequence Diagram

    Back to top

    Basic examples

    Back to top

    The sequence -> is used to draw a message between two participants. Participants do not have to be explicitly declared.

    To have a dotted arrow, you use -->

    It is also possible to use <- and <--. That does not change the drawing, but may improve readability. Note that this is only true for sequence diagrams, rules are different for the other diagrams.

    1. @startuml
    2. Alice -> Bob: Authentication Request
    3. Bob --> Alice: Authentication Response
    4. Alice -> Bob: Another authentication Request
    5. Alice <-- Bob: Another authentication Response
    6. @enduml

     

    Declaring participant

    Back to top

    If the keyword participant is used to declare a participant, more control on that participant is possible.

    The order of declaration will be the (default) order of display.

    Using these other keywords to declare participants will change the shape of the participant representation:

    • actor
    • boundary
    • control
    • entity
    • database
    • collections
    • queue

    1. @startuml
    2. participant Participant as Foo
    3. actor Actor as Foo1
    4. boundary Boundary as Foo2
    5. control Control as Foo3
    6. entity Entity as Foo4
    7. database Database as Foo5
    8. collections Collections as Foo6
    9. queue Queue as Foo7
    10. Foo -> Foo1 : To actor
    11. Foo -> Foo2 : To boundary
    12. Foo -> Foo3 : To control
    13. Foo -> Foo4 : To entity
    14. Foo -> Foo5 : To database
    15. Foo -> Foo6 : To collections
    16. Foo -> Foo7: To queue
    17. @enduml

     

    Rename a participant using the as keyword.

    You can also change the background color of actor or participant.

    1. @startuml
    2. actor Bob #red
    3. ' The only difference between actor
    4. 'and participant is the drawing
    5. participant Alice
    6. participant "I have a really\nlong name" as L #99FF99
    7. /' You can also declare:
    8. participant L as "I have a really\nlong name" #99FF99
    9. '/
    10. Alice->Bob: Authentication Request
    11. Bob->Alice: Authentication Response
    12. Bob->L: Log transaction
    13. @enduml

     

    You can use the order keyword to customize the display order of participants.

    1. @startuml
    2. participant Last order 30
    3. participant Middle order 20
    4. participant First order 10
    5. @enduml

     

    Declaring participant on multiline

    Back to top

    You can declare participant on multi-line.

    1. @startuml
    2. participant Participant [
    3. =Title
    4. ----
    5. ""SubTitle""
    6. ]
    7. participant Bob
    8. Participant -> Bob
    9. @enduml

     

    [Ref. QA-15232]

    Use non-letters in participants

    Back to top

    You can use quotes to define participants. And you can use the as keyword to give an alias to those participants.

    1. @startuml
    2. Alice -> "Bob()" : Hello
    3. "Bob()" -> "This is very\nlong" as Long
    4. ' You can also declare:
    5. ' "Bob()" -> Long as "This is very\nlong"
    6. Long --> "Bob()" : ok
    7. @enduml

     

    Message to Self

    Back to top

    A participant can send a message to itself.

    It is also possible to have multi-line using \n.

    1. @startuml
    2. Alice -> Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
    3. @enduml

     

    1. @startuml
    2. Alice <- Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
    3. @enduml

     

    [Ref. QA-1361]

    Text alignment

    Back to top

    Text alignment on arrows can be set to leftright or center using skinparam sequenceMessageAlign.

    You can also use direction or reverseDirection to align text depending on arrow direction. Further details and examples of this are available on the skinparam page.

    1. @startuml
    2. skinparam sequenceMessageAlign right
    3. Bob -> Alice : Request
    4. Alice -> Bob : Response
    5. @enduml

     

    Text of response message below the arrow

    You can put the text of the response message below the arrow, with the skinparam responseMessageBelowArrow true command.

    1. @startuml
    2. skinparam responseMessageBelowArrow true
    3. Bob -> Alice : hello
    4. Alice -> Bob : ok
    5. @enduml

     

    Change arrow style

    Back to top

    You can change arrow style by several ways:

    • add a final x to denote a lost message
    • use \ or / instead of < or > to have only the bottom or top part of the arrow
    • repeat the arrow head (for example, >> or //) head to have a thin drawing
    • use -- instead of - to have a dotted arrow
    • add a final "o" at arrow head
    • use bidirectional arrow <->

    1. @startuml
    2. Bob ->x Alice
    3. Bob -> Alice
    4. Bob ->> Alice
    5. Bob -\ Alice
    6. Bob \\- Alice
    7. Bob //-- Alice
    8. Bob ->o Alice
    9. Bob o\\-- Alice
    10. Bob <-> Alice
    11. Bob <->o Alice
    12. @enduml

     

    Change arrow color

    Back to top

    You can change the color of individual arrows using the following notation:

    1. @startuml
    2. Bob -[#red]> Alice : hello
    3. Alice -[#0000FF]->Bob : ok
    4. @enduml

     

    Message sequence numbering

    Back to top

    The keyword autonumber is used to automatically add an incrementing number to messages.

    1. @startuml
    2. autonumber
    3. Bob -> Alice : Authentication Request
    4. Bob <- Alice : Authentication Response
    5. @enduml

     

    You can specify a startnumber with autonumber  , and also an increment with autonumber .

    1. @startuml
    2. autonumber
    3. Bob -> Alice : Authentication Request
    4. Bob <- Alice : Authentication Response
    5. autonumber 15
    6. Bob -> Alice : Another authentication Request
    7. Bob <- Alice : Another authentication Response
    8. autonumber 40 10
    9. Bob -> Alice : Yet another authentication Request
    10. Bob <- Alice : Yet another authentication Response
    11. @enduml

     

    You can specify a format for your number by using between double-quote.

    The formatting is done with the Java class DecimalFormat (0 means digit, # means digit and zero if absent).

    You can use some html tag in the format.

    1. @startuml
    2. autonumber "[000]"
    3. Bob -> Alice : Authentication Request
    4. Bob <- Alice : Authentication Response
    5. autonumber 15 "(##)"
    6. Bob -> Alice : Another authentication Request
    7. Bob <- Alice : Another authentication Response
    8. autonumber 40 10 "Message 0 "
    9. Bob -> Alice : Yet another authentication Request
    10. Bob <- Alice : Yet another authentication Response
    11. @enduml

     

    You can also use autonumber stop and autonumber resume  to respectively pause and resume automatic numbering.

    1. @startuml
    2. autonumber 10 10 "[000]"
    3. Bob -> Alice : Authentication Request
    4. Bob <- Alice : Authentication Response
    5. autonumber stop
    6. Bob -> Alice : dummy
    7. autonumber resume "Message 0 "
    8. Bob -> Alice : Yet another authentication Request
    9. Bob <- Alice : Yet another authentication Response
    10. autonumber stop
    11. Bob -> Alice : dummy
    12. autonumber resume 1 "Message 0 "
    13. Bob -> Alice : Yet another authentication Request
    14. Bob <- Alice : Yet another authentication Response
    15. @enduml

     

    Your startnumber can also be a 2 or 3 digit sequence using a field delimiter such as .;,: or a mix of these. For example: 1.1.1 or 1.1:1.

    Automatically the last digit will increment.

    To increment the first digit, use: autonumber inc A. To increment the second digit, use: autonumber inc B.

    1. @startuml
    2. autonumber 1.1.1
    3. Alice -> Bob: Authentication request
    4. Bob --> Alice: Response
    5. autonumber inc A
    6. 'Now we have 2.1.1
    7. Alice -> Bob: Another authentication request
    8. Bob --> Alice: Response
    9. autonumber inc B
    10. 'Now we have 2.2.1
    11. Alice -> Bob: Another authentication request
    12. Bob --> Alice: Response
    13. autonumber inc A
    14. 'Now we have 3.1.1
    15. Alice -> Bob: Another authentication request
    16. autonumber inc B
    17. 'Now we have 3.2.1
    18. Bob --> Alice: Response
    19. @enduml

     

    You can also use the value of autonumber with the %autonumber% variable:

    1. @startuml
    2. autonumber 10
    3. Alice -> Bob
    4. note right
    5. the <U+0025>autonumber<U+0025> works everywhere.
    6. Here, its value is ** %autonumber% **
    7. end note
    8. Bob --> Alice: //This is the response %autonumber%//
    9. @enduml

     

    [Ref. QA-7119]

    Page Title, Header and Footer

    Back to top

    The title keyword is used to add a title to the page.

    Pages can display headers and footers using header and footer.

    1. @startuml
    2. header Page Header
    3. footer Page %page% of %lastpage%
    4. title Example Title
    5. Alice -> Bob : message 1
    6. Alice -> Bob : message 2
    7. @enduml

     

    Splitting diagrams

    Back to top

    The newpage keyword is used to split a diagram into several images.

    You can put a title for the new page just after the newpage keyword. This title overrides the previously specified title if any.

    This is very handy with Word to print long diagram on several pages.

    (Note: this really does work. Only the first page is shown below, but it is a display artifact.)

    1. @startuml
    2. Alice -> Bob : message 1
    3. Alice -> Bob : message 2
    4. newpage
    5. Alice -> Bob : message 3
    6. Alice -> Bob : message 4
    7. newpage A title for the\nlast page
    8. Alice -> Bob : message 5
    9. Alice -> Bob : message 6
    10. @enduml

     

    Grouping message

    Back to top

    It is possible to group messages together using the following keywords:

    • alt/else
    • opt
    • loop
    • par
    • break
    • critical
    • group, followed by a text to be displayed

    It is possible to add a text that will be displayed into the header (for group, see next paragraph 'Secondary group label').

    The end keyword is used to close the group.

    Note that it is possible to nest groups.

    1. @startuml
    2. Alice -> Bob: Authentication Request
    3. alt successful case
    4. Bob -> Alice: Authentication Accepted
    5. else some kind of failure
    6. Bob -> Alice: Authentication Failure
    7. group My own label
    8. Alice -> Log : Log attack start
    9. loop 1000 times
    10. Alice -> Bob: DNS Attack
    11. end
    12. Alice -> Log : Log attack end
    13. end
    14. else Another type of failure
    15. Bob -> Alice: Please repeat
    16. end
    17. @enduml

     

    Secondary group label

    Back to top

    For group, it is possible to add, between[ and ], a secondary text or label that will be displayed into the header.

    1. @startuml
    2. Alice -> Bob: Authentication Request
    3. Bob -> Alice: Authentication Failure
    4. group My own label [My own label 2]
    5. Alice -> Log : Log attack start
    6. loop 1000 times
    7. Alice -> Bob: DNS Attack
    8. end
    9. Alice -> Log : Log attack end
    10. end
    11. @enduml

     

    [Ref. QA-2503]

    Notes on messages

    Back to top

    It is possible to put notes on message using the note left or note right keywords just after the message.

    You can have a multi-line note using the end note keywords.

    1. @startuml
    2. Alice->Bob : hello
    3. note left: this is a first note
    4. Bob->Alice : ok
    5. note right: this is another note
    6. Bob->Bob : I am thinking
    7. note left
    8. a note
    9. can also be defined
    10. on several lines
    11. end note
    12. @enduml

     

    Some other notes

    Back to top

    It is also possible to place notes relative to participant with note left of , note right of or note over keywords.

    It is possible to highlight a note by changing its background color.

    You can also have a multi-line note using the end note keywords.

    1. @startuml
    2. participant Alice
    3. participant Bob
    4. note left of Alice #aqua
    5. This is displayed
    6. left of Alice.
    7. end note
    8. note right of Alice: This is displayed right of Alice.
    9. note over Alice: This is displayed over Alice.
    10. note over Alice, Bob #FFAAAA: This is displayed\n over Bob and Alice.
    11. note over Bob, Alice
    12. This is yet another
    13. example of
    14. a long note.
    15. end note
    16. @enduml

     

    Changing notes shape [hnote, rnote]

    Back to top

    You can use hnote and rnote keywords to change note shapes :

    • hnote for hexagonal note;
    • rnote for rectangle note.

    1. @startuml
    2. caller -> server : conReq
    3. hnote over caller : idle
    4. caller <- server : conConf
    5. rnote over server
    6. "r" as rectangle
    7. "h" as hexagon
    8. endrnote
    9. rnote over server
    10. this is
    11. on several
    12. lines
    13. endrnote
    14. hnote over caller
    15. this is
    16. on several
    17. lines
    18. endhnote
    19. @enduml

     

    [Ref. QA-1765]

    Note over all participants [across]

    Back to top

    You can directly make a note over all participants, with the syntax:

    • note across: note_description

    1. @startuml
    2. Alice->Bob:m1
    3. Bob->Charlie:m2
    4. note over Alice, Charlie: Old method for note over all part. with:\n ""note over //FirstPart, LastPart//"".
    5. note across: New method with:\n""note across""
    6. Bob->Alice
    7. hnote across:Note across all part.
    8. @enduml

     

    [Ref. QA-9738]

    Several notes aligned at the same level [/]

    Back to top

    You can make several notes aligned at the same level, with the syntax /:

    • without / (by default, the notes are not aligned)

    1. @startuml
    2. note over Alice : initial state of Alice
    3. note over Bob : initial state of Bob
    4. Bob -> Alice : hello
    5. @enduml

     

    • with / (the notes are aligned)

    1. @startuml
    2. note over Alice : initial state of Alice
    3. / note over Bob : initial state of Bob
    4. Bob -> Alice : hello
    5. @enduml

     

    [Ref. QA-354]

    Creole and HTML

    Back to top

    It is also possible to use creole formatting:

    1. @startuml
    2. participant Alice
    3. participant "The **Famous** Bob" as Bob
    4. Alice -> Bob : hello --there--
    5. ... Some ~~long delay~~ ...
    6. Bob -> Alice : ok
    7. note left
    8. This is **bold**
    9. This is //italics//
    10. This is ""monospaced""
    11. This is --stroked--
    12. This is __underlined__
    13. This is ~~waved~~
    14. end note
    15. Alice -> Bob : A //well formatted// message
    16. note right of Alice
    17. This is <back:cadetblue><size:18>displayed</size></back>
    18. __left of__ Alice.
    19. end note
    20. note left of Bob
    21. <u:red>This</u> is <color #118888>displayed</color>
    22. **left of Alice Bob**.
    23. end note
    24. note over Alice, Bob
    25. <w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>
    26. end note
    27. @enduml

     

    Divider or separator

    Back to top

    If you want, you can split a diagram using == separator to divide your diagram into logical steps.

    1. @startuml
    2. == Initialization ==
    3. Alice -> Bob: Authentication Request
    4. Bob --> Alice: Authentication Response
    5. == Repetition ==
    6. Alice -> Bob: Another authentication Request
    7. Alice <-- Bob: another authentication Response
    8. @enduml

     

    Reference

    Back to top

    You can use reference in a diagram, using the keyword ref over.

    1. @startuml
    2. participant Alice
    3. actor Bob
    4. ref over Alice, Bob : init
    5. Alice -> Bob : hello
    6. ref over Bob
    7. This can be on
    8. several lines
    9. end ref
    10. @enduml

     

    Delay

    Back to top

    You can use ... to indicate a delay in the diagram. And it is also possible to put a message with this delay.

    1. @startuml
    2. Alice -> Bob: Authentication Request
    3. ...
    4. Bob --> Alice: Authentication Response
    5. ...5 minutes later...
    6. Bob --> Alice: Good Bye !
    7. @enduml

     

    Text wrapping

    Back to top

    To break long messages, you can manually add \n in your text.

    Another option is to use maxMessageSize setting:

    1. @startuml
    2. skinparam maxMessageSize 50
    3. participant a
    4. participant b
    5. a -> b :this\nis\nmanually\ndone
    6. a -> b :this is a very long message on several words
    7. @enduml

     

    Space

    Back to top

    You can use ||| to indicate some spacing in the diagram.

    It is also possible to specify a number of pixel to be used.

    1. @startuml
    2. Alice -> Bob: message 1
    3. Bob --> Alice: ok
    4. |||
    5. Alice -> Bob: message 2
    6. Bob --> Alice: ok
    7. ||45||
    8. Alice -> Bob: message 3
    9. Bob --> Alice: ok
    10. @enduml

     

    Lifeline Activation and Destruction

    Back to top

    The activate and deactivate are used to denote participant activation.

    Once a participant is activated, its lifeline appears.

    The activate and deactivate apply on the previous message.

    The destroy denote the end of the lifeline of a participant.

    1. @startuml
    2. participant User
    3. User -> A: DoWork
    4. activate A
    5. A -> B: << createRequest >>
    6. activate B
    7. B -> C: DoWork
    8. activate C
    9. C --> B: WorkDone
    10. destroy C
    11. B --> A: RequestCreated
    12. deactivate B
    13. A -> User: Done
    14. deactivate A
    15. @enduml

     

    Nested lifeline can be used, and it is possible to add a color on the lifeline.

    1. @startuml
    2. participant User
    3. User -> A: DoWork
    4. activate A #FFBBBB
    5. A -> A: Internal call
    6. activate A #DarkSalmon
    7. A -> B: << createRequest >>
    8. activate B
    9. B --> A: RequestCreated
    10. deactivate B
    11. deactivate A
    12. A -> User: Done
    13. deactivate A
    14. @enduml

     

    Autoactivation is possible and works with the return keywords:

    1. @startuml
    2. autoactivate on
    3. alice -> bob : hello
    4. bob -> bob : self call
    5. bill -> bob #005500 : hello from thread 2
    6. bob -> george ** : create
    7. return done in thread 2
    8. return rc
    9. bob -> george !! : delete
    10. return success
    11. @enduml

     

    Return

    Back to top

    Command return generates a return message with optional text label.

    The return point is that which caused the most recent life-line activation.

    The syntax is return label where label if provided is any string acceptable for conventional messages.

    1. @startuml
    2. Bob -> Alice : hello
    3. activate Alice
    4. Alice -> Alice : some action
    5. return bye
    6. @enduml

     

    Participant creation

    Back to top

    You can use the create keyword just before the first reception of a message to emphasize the fact that this message is actually creating this new object.

    1. @startuml
    2. Bob -> Alice : hello
    3. create Other
    4. Alice -> Other : new
    5. create control String
    6. Alice -> String
    7. note right : You can also put notes!
    8. Alice --> Bob : ok
    9. @enduml

     

    Shortcut syntax for activation, deactivation, creation

    Back to top

    Immediately after specifying the target participant, the following syntax can be used:

    • ++ Activate the target (optionally a color may follow this)
    • -- Deactivate the source
    • ** Create an instance of the target
    • !! Destroy an instance of the target

    1. @startuml
    2. alice -> bob ++ : hello
    3. bob -> bob ++ : self call
    4. bob -> bib ++ #005500 : hello
    5. bob -> george ** : create
    6. return done
    7. return rc
    8. bob -> george !! : delete
    9. return success
    10. @enduml

     

    Then you can mix activation and deactivation, on same line:

    1. @startuml
    2. alice -> bob ++ : hello1
    3. bob -> charlie --++ : hello2
    4. charlie --> alice -- : ok
    5. @enduml

     

    1. @startuml
    2. @startuml
    3. alice -> bob --++ #gold: hello
    4. bob -> alice --++ #gold: you too
    5. alice -> bob --: step1
    6. alice -> bob : step2
    7. @enduml
    8. @enduml

     

    [Ref. QA-4834QA-9573 and QA-13234]

    Incoming and outgoing messages

    Back to top

    You can use incoming or outgoing arrows if you want to focus on a part of the diagram.

    Use square brackets to denote the left "[" or the right "]" side of the diagram.

    1. @startuml
    2. [-> A: DoWork
    3. activate A
    4. A -> A: Internal call
    5. activate A
    6. A ->] : << createRequest >>
    7. A<--] : RequestCreated
    8. deactivate A
    9. [<- A: Done
    10. deactivate A
    11. @enduml

     

    You can also have the following syntax:

    1. @startuml
    2. participant Alice
    3. participant Bob #lightblue
    4. Alice -> Bob
    5. Bob -> Carol
    6. ...
    7. [-> Bob
    8. [o-> Bob
    9. [o->o Bob
    10. [x-> Bob
    11. ...
    12. [<- Bob
    13. [x<- Bob
    14. ...
    15. Bob ->]
    16. Bob ->o]
    17. Bob o->o]
    18. Bob ->x]
    19. ...
    20. Bob <-]
    21. Bob x<-]
    22. @enduml

     

    Short arrows for incoming and outgoing messages

    Back to top

    You can have short arrows with using ?.

    1. @startuml
    2. ?-> Alice : ""?->""\n**short** to actor1
    3. [-> Alice : ""[->""\n**from start** to actor1
    4. [-> Bob : ""[->""\n**from start** to actor2
    5. ?-> Bob : ""?->""\n**short** to actor2
    6. Alice ->] : ""->]""\nfrom actor1 **to end**
    7. Alice ->? : ""->?""\n**short** from actor1
    8. Alice -> Bob : ""->"" \nfrom actor1 to actor2
    9. @enduml

     

    [Ref. QA-310]

    Anchors and Duration

    Back to top

    With teoz it is possible to add anchors to the diagram and use the anchors to specify duration time.

    1. @startuml
    2. !pragma teoz true
    3. {start} Alice -> Bob : start doing things during duration
    4. Bob -> Max : something
    5. Max -> Bob : something else
    6. {end} Bob -> Alice : finish
    7. {start} <-> {end} : some time
    8. @enduml

     

    You can use the -P command-line option to specify the pragma:

    java -jar plantuml.jar -Pteoz=true
    

    [Ref. issue-582]

    Stereotypes and Spots

    Back to top

    It is possible to add stereotypes to participants using << and >>.

    In the stereotype, you can add a spotted character in a colored circle using the syntax (X,color).

    1. @startuml
    2. participant "Famous Bob" as Bob << Generated >>
    3. participant Alice << (C,#ADD1B2) Testable >>
    4. Bob->Alice: First message
    5. @enduml

     

    By default, the guillemet character is used to display the stereotype. You can change this behavious using the skinparam guillemet:

    1. @startuml
    2. skinparam guillemet false
    3. participant "Famous Bob" as Bob << Generated >>
    4. participant Alice << (C,#ADD1B2) Testable >>
    5. Bob->Alice: First message
    6. @enduml

     

    1. @startuml
    2. participant Bob << (C,#ADD1B2) >>
    3. participant Alice << (C,#ADD1B2) >>
    4. Bob->Alice: First message
    5. @enduml

     

    More information on titles

    Back to top

    You can use creole formatting in the title.

    1. @startuml
    2. title __Simple__ **communication** example
    3. Alice -> Bob: Authentication Request
    4. Bob -> Alice: Authentication Response
    5. @enduml

     

    You can add newline using \n in the title description.

    1. @startuml
    2. title __Simple__ communication example\non several lines
    3. Alice -> Bob: Authentication Request
    4. Bob -> Alice: Authentication Response
    5. @enduml

     

    You can also define title on several lines using title and end title keywords.

    1. @startuml
    2. title
    3. <u>Simple</u> communication example
    4. on <i>several</i> lines and using <font color=red>html</font>
    5. This is hosted by <img:sourceforge.jpg>
    6. end title
    7. Alice -> Bob: Authentication Request
    8. Bob -> Alice: Authentication Response
    9. @enduml

     

    Participants encompass

    Back to top

    It is possible to draw a box around some participants, using box and end box commands.

    You can add an optional title or a optional background color, after the box keyword.

    1. @startuml
    2. box "Internal Service" #LightBlue
    3. participant Bob
    4. participant Alice
    5. end box
    6. participant Other
    7. Bob -> Alice : hello
    8. Alice -> Other : hello
    9. @enduml

     

    It is also possible to nest boxes - to draw a box within a box - when using the teoz rendering engine, for example:

    1. @startuml
    2. !pragma teoz true
    3. box "Internal Service" #LightBlue
    4. participant Bob
    5. box "Subteam"
    6. participant Alice
    7. participant John
    8. end box
    9. end box
    10. participant Other
    11. Bob -> Alice : hello
    12. Alice -> John : hello
    13. John -> Other: Hello
    14. @enduml

     

    Removing Foot Boxes

    Back to top

    You can use the hide footbox keywords to remove the foot boxes of the diagram.

    1. @startuml
    2. hide footbox
    3. title Foot Box removed
    4. Alice -> Bob: Authentication Request
    5. Bob --> Alice: Authentication Response
    6. @enduml

     

    Skinparam

    Back to top

    You can use the skinparam command to change colors and fonts for the drawing.

    You can use this command:

    You can also change other rendering parameter, as seen in the following examples:

    1. @startuml
    2. skinparam sequenceArrowThickness 2
    3. skinparam roundcorner 20
    4. skinparam maxmessagesize 60
    5. skinparam sequenceParticipant underline
    6. actor User
    7. participant "First Class" as A
    8. participant "Second Class" as B
    9. participant "Last Class" as C
    10. User -> A: DoWork
    11. activate A
    12. A -> B: Create Request
    13. activate B
    14. B -> C: DoWork
    15. activate C
    16. C --> B: WorkDone
    17. destroy C
    18. B --> A: Request Created
    19. deactivate B
    20. A --> User: Done
    21. deactivate A
    22. @enduml

     

    1. @startuml
    2. skinparam backgroundColor #EEEBDC
    3. skinparam handwritten true
    4. skinparam sequence {
    5. ArrowColor DeepSkyBlue
    6. ActorBorderColor DeepSkyBlue
    7. LifeLineBorderColor blue
    8. LifeLineBackgroundColor #A9DCDF
    9. ParticipantBorderColor DeepSkyBlue
    10. ParticipantBackgroundColor DodgerBlue
    11. ParticipantFontName Impact
    12. ParticipantFontSize 17
    13. ParticipantFontColor #A9DCDF
    14. ActorBackgroundColor aqua
    15. ActorFontColor DeepSkyBlue
    16. ActorFontSize 17
    17. ActorFontName Aapex
    18. }
    19. actor User
    20. participant "First Class" as A
    21. participant "Second Class" as B
    22. participant "Last Class" as C
    23. User -> A: DoWork
    24. activate A
    25. A -> B: Create Request
    26. activate B
    27. B -> C: DoWork
    28. activate C
    29. C --> B: WorkDone
    30. destroy C
    31. B --> A: Request Created
    32. deactivate B
    33. A --> User: Done
    34. deactivate A
    35. @enduml

     

    Changing padding

    Back to top

    It is possible to tune some padding settings.

    1. @startuml
    2. skinparam ParticipantPadding 20
    3. skinparam BoxPadding 10
    4. box "Foo1"
    5. participant Alice1
    6. participant Alice2
    7. end box
    8. box "Foo2"
    9. participant Bob1
    10. participant Bob2
    11. end box
    12. Alice1 -> Bob1 : hello
    13. Alice1 -> Out : out
    14. @enduml

     

    Appendix: Examples of all arrow type

    Back to top

    Normal arrow

    1. @startuml
    2. participant Alice as a
    3. participant Bob as b
    4. a -> b : ""-> ""
    5. a ->> b : ""->> ""
    6. a -\ b : ""-\ ""
    7. a -\\ b : ""-\\\\""
    8. a -/ b : ""-/ ""
    9. a -// b : ""-// ""
    10. a ->x b : ""->x ""
    11. a x-> b : ""x-> ""
    12. a o-> b : ""o-> ""
    13. a ->o b : ""->o ""
    14. a o->o b : ""o->o ""
    15. a <-> b : ""<-> ""
    16. a o<->o b : ""o<->o""
    17. a x<->x b : ""x<->x""
    18. a ->>o b : ""->>o ""
    19. a -\o b : ""-\o ""
    20. a -\\o b : ""-\\\\o""
    21. a -/o b : ""-/o ""
    22. a -//o b : ""-//o ""
    23. a x->o b : ""x->o ""
    24. @enduml

     

    Itself arrow

    1. @startuml
    2. participant Alice as a
    3. participant Bob as b
    4. a -> a : ""-> ""
    5. a ->> a : ""->> ""
    6. a -\ a : ""-\ ""
    7. a -\\ a : ""-\\\\""
    8. a -/ a : ""-/ ""
    9. a -// a : ""-// ""
    10. a ->x a : ""->x ""
    11. a x-> a : ""x-> ""
    12. a o-> a : ""o-> ""
    13. a ->o a : ""->o ""
    14. a o->o a : ""o->o ""
    15. a <-> a : ""<-> ""
    16. a o<->o a : ""o<->o""
    17. a x<->x a : ""x<->x""
    18. a ->>o a : ""->>o ""
    19. a -\o a : ""-\o ""
    20. a -\\o a : ""-\\\\o""
    21. a -/o a : ""-/o ""
    22. a -//o a : ""-//o ""
    23. a x->o a : ""x->o ""
    24. @enduml

     

    Incoming and outgoing messages (with '[', ']')

    Incoming messages (with '[')

    1. @startuml
    2. participant Alice as a
    3. participant Bob as b
    4. [-> b : ""[-> ""
    5. [->> b : ""[->> ""
    6. [-\ b : ""[-\ ""
    7. [-\\ b : ""[-\\\\""
    8. [-/ b : ""[-/ ""
    9. [-// b : ""[-// ""
    10. [->x b : ""[->x ""
    11. [x-> b : ""[x-> ""
    12. [o-> b : ""[o-> ""
    13. [->o b : ""[->o ""
    14. [o->o b : ""[o->o ""
    15. [<-> b : ""[<-> ""
    16. [o<->o b : ""[o<->o""
    17. [x<->x b : ""[x<->x""
    18. [->>o b : ""[->>o ""
    19. [-\o b : ""[-\o ""
    20. [-\\o b : ""[-\\\\o""
    21. [-/o b : ""[-/o ""
    22. [-//o b : ""[-//o ""
    23. [x->o b : ""[x->o ""
    24. @enduml

     

    Outgoing messages (with ']')

    1. @startuml
    2. participant Alice as a
    3. participant Bob as b
    4. a ->] : ""->] ""
    5. a ->>] : ""->>] ""
    6. a -\] : ""-\] ""
    7. a -\\] : ""-\\\\]""
    8. a -/] : ""-/] ""
    9. a -//] : ""-//] ""
    10. a ->x] : ""->x] ""
    11. a x->] : ""x->] ""
    12. a o->] : ""o->] ""
    13. a ->o] : ""->o] ""
    14. a o->o] : ""o->o] ""
    15. a <->] : ""<->] ""
    16. a o<->o] : ""o<->o]""
    17. a x<->x] : ""x<->x]""
    18. a ->>o] : ""->>o] ""
    19. a -\o] : ""-\o] ""
    20. a -\\o] : ""-\\\\o]""
    21. a -/o] : ""-/o] ""
    22. a -//o] : ""-//o] ""
    23. a x->o] : ""x->o] ""
    24. @enduml

     

    Short incoming and outgoing messages (with '?')

    Short incoming (with '?')

    1. @startuml
    2. participant Alice as a
    3. participant Bob as b
    4. a -> b : //Long long label//
    5. ?-> b : ""?-> ""
    6. ?->> b : ""?->> ""
    7. ?-\ b : ""?-\ ""
    8. ?-\\ b : ""?-\\\\""
    9. ?-/ b : ""?-/ ""
    10. ?-// b : ""?-// ""
    11. ?->x b : ""?->x ""
    12. ?x-> b : ""?x-> ""
    13. ?o-> b : ""?o-> ""
    14. ?->o b : ""?->o ""
    15. ?o->o b : ""?o->o ""
    16. ?<-> b : ""?<-> ""
    17. ?o<->o b : ""?o<->o""
    18. ?x<->x b : ""?x<->x""
    19. ?->>o b : ""?->>o ""
    20. ?-\o b : ""?-\o ""
    21. ?-\\o b : ""?-\\\\o ""
    22. ?-/o b : ""?-/o ""
    23. ?-//o b : ""?-//o ""
    24. ?x->o b : ""?x->o ""
    25. @enduml

     

    Short outgoing (with '?')

    1. @startuml
    2. participant Alice as a
    3. participant Bob as b
    4. a -> b : //Long long label//
    5. a ->? : ""->? ""
    6. a ->>? : ""->>? ""
    7. a -\? : ""-\? ""
    8. a -\\? : ""-\\\\?""
    9. a -/? : ""-/? ""
    10. a -//? : ""-//? ""
    11. a ->x? : ""->x? ""
    12. a x->? : ""x->? ""
    13. a o->? : ""o->? ""
    14. a ->o? : ""->o? ""
    15. a o->o? : ""o->o? ""
    16. a <->? : ""<->? ""
    17. a o<->o? : ""o<->o?""
    18. a x<->x? : ""x<->x?""
    19. a ->>o? : ""->>o? ""
    20. a -\o? : ""-\o? ""
    21. a -\\o? : ""-\\\\o?""
    22. a -/o? : ""-/o? ""
    23. a -//o? : ""-//o? ""
    24. a x->o? : ""x->o? ""
    25. @enduml

     

    Specific SkinParameter

    Back to top

    By default

    1. @startuml
    2. Bob -> Alice : hello
    3. Alice -> Bob : ok
    4. @enduml

     

    LifelineStrategy

    • nosolid (by default)

    1. @startuml
    2. skinparam lifelineStrategy nosolid
    3. Bob -> Alice : hello
    4. Alice -> Bob : ok
    5. @enduml

     

    [Ref. QA-9016]

    • solid

    In order to have solid life line in sequence diagrams, you can use: skinparam lifelineStrategy solid

    1. @startuml
    2. skinparam lifelineStrategy solid
    3. Bob -> Alice : hello
    4. Alice -> Bob : ok
    5. @enduml

     

    [Ref. QA-2794]

    style strictuml

    To be conform to strict UML (for arrow style: emits triangle rather than sharp arrowheads), you can use:

    • skinparam style strictuml

    1. @startuml
    2. skinparam style strictuml
    3. Bob -> Alice : hello
    4. Alice -> Bob : ok
    5. @enduml

     

    [Ref. QA-1047]

    Hide unlinked participant

    Back to top

    By default, all participants are displayed.

    1. @startuml
    2. participant Alice
    3. participant Bob
    4. participant Carol
    5. Alice -> Bob : hello
    6. @enduml

     

    But you can hide unlinked participant.

    1. @startuml
    2. hide unlinked
    3. participant Alice
    4. participant Bob
    5. participant Carol
    6. Alice -> Bob : hello
    7. @enduml

     

    [Ref. QA-4247]

    Color a group message

    Back to top

    It is possible to color a group messages:

    1. @startuml
    2. Alice -> Bob: Authentication Request
    3. alt#Gold #LightBlue Successful case
    4. Bob -> Alice: Authentication Accepted
    5. else #Pink Failure
    6. Bob -> Alice: Authentication Rejected
    7. end
    8. @enduml

     

    [Ref. QA-4750 and QA-6410]

    Mainframe

    Back to top

    1. @startuml
    2. mainframe This is a **mainframe**
    3. Alice->Bob : Hello
    4. @enduml

     

    [Ref. QA-4019 and Issue#148]

    Slanted or odd arrows

    Back to top

    You can use the (nn) option (before or after arrow) to make the arrows slanted, where nn is the number of shift pixels.

    [Available only after v1.2022.6beta+]

    1. @startuml
    2. A ->(10) B: text 10
    3. B ->(10) A: text 10
    4. A ->(10) B: text 10
    5. A (10)<- B: text 10
    6. @enduml

     

    1. @startuml
    2. A ->(40) B++: Rq
    3. B -->(20) A--: Rs
    4. @enduml

     

    [Ref. QA-14145]

    1. @startuml
    2. !pragma teoz true
    3. A ->(50) C: Starts\nwhen 'B' sends
    4. & B ->(25) C: \nBut B's message\n arrives before A's
    5. @enduml

     

    [Ref. QA-6684]

    1. @startuml
    2. !pragma teoz true
    3. S1 ->(30) S2: msg 1\n
    4. & S2 ->(30) S1: msg 2
    5. note left S1: msg\nS2 to S1
    6. & note right S2: msg\nS1 to S2
    7. @enduml

     

    [Ref. QA-1072]

  • 相关阅读:
    火狐自定义CSS、高级首选项
    Python升级之路( Lv10 ) 文件操作
    【人工智能Ⅰ】3-遗传算法及其应用
    爬虫面试手册
    Android网络基础面试题之HTTPS的工作流程和原理
    数据结构——线性表的顺序表示和实现
    视图、存储过程、触发器
    Linux操作系统的Web服务器优点
    umich cv-2-1
    代码优化技巧
  • 原文地址:https://blog.csdn.net/moshowgame/article/details/132703216