美文网首页
plantUML语法(-)时序图

plantUML语法(-)时序图

作者: 浮生半梦6 | 来源:发表于2017-10-11 10:26 被阅读0次

    一.时序图
    (1) -> 来绘制参与者之间传递的消息, 而不必显式地声明参与者。
        -->绘制一个虚线箭头。(<-  <--)
      注意:仅适用与时序图 其他示意图规则是不同的
     
    实例:  语法 
       @startuml
        Alice -> Bob: Authentication Request
        Bob --> Alice: Authentication Response
        Alice -> Bob: Another authentication Request
        Alice <-- Bob: another authentication Response
        @enduml

    (2)声明参与者(Declaring participant)
        声明参与者的关键字有 actor,boundary,control,entity,database,collections
        关键字as用于重命名参与者
        @startuml
            actor Foo1
            boundary Foo2
            control Foo3
            entity Foo4
          database Foo5
          collections Foo6
          Foo1 -> Foo2 : To boundary
          Foo1 -> Foo3 : To control
          Foo1 -> Foo4 : To entity
          Foo1 -> Foo5 : To database
          Foo1 -> Foo6 : To collections
          actor Bob #red
          participant Alice
        participant "I have a really\nlong name" as L #99FF99
        /' You can also declare:  participant L as "I have a really\nlong name"  #99FF99 '/
        Alice->Bob: Authentication Request
        Bob->Alice: Authentication Response
        Bob->L: Log transaction
        @enduml
    (3)给自己发消息(Message to self)
        @startuml
        Alice->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
        @enduml
    (4)修改箭头样式(Change arrow style)
       
    表示一条丢失的消息:末尾加x
      让箭头只有上半部分或者下半部分:将<和>替换成\或者/
      细箭头:将箭头标记写两次 (如>>或//)
      虚线箭头:用--替代-
      箭头末尾加圈:->o
      双向箭头:<->
    示例 
    @startuml
     Bob ->x Alice    Bob -> Alice
     Bob ->> Alice    Bob -\ Alice
     Bob \\- Alice      Bob //-- Alice
     Bob ->o Alice    Bob o\\-- Alice
     Bob <-> Alice    Bob <->o Alice
    @enduml

    (5)修改箭头颜色(Change arrow color)
        @startuml
        Bob -[#red]> Alice : hello
        Alice -[#0000FF]->Bob : ok
        @enduml
    (6)对消息序列编号(Message sequence numbering)
        @startuml
          autonumber  1 2 "<font color=red><b>messge 0"  /** 第一个数字代表初始值 第二个代表步长(step) */
         
    Bob -> Alice : Authentication Request
          Bob <- Alice : Authentication Response
          autonumber stop
          Bob -> Alice : dummy
          autonumber resume "<font color=red><b>message 0"
          Bob -> Alice : Yet another authentication Request
          Bob <- Alice : Yet another authentication Response
      @enduml
      注意:(1)autonumber  1 2  "<font color=red><b>message"
                  /** 第一个数字代表初始值 第二个代表步长(step) */ 
              (2)autonumber stop和autonumber resume 'increment' 'format'来表示暂停或继续使用自动编号
    (7)分割示意图(Splitting diagrams) 
        newpage关键字分割几页  本地不成功
    (8)组合消息
        关键字 alt/else , opt,loop,par,break,critical,group, 后面紧跟着消息内容
        注意:
              (1)可以在标头(header)添加需要显示的文字(group除外)。关键词end用来结束分                组.分组可以嵌套使用。
              (2)可以使用note left of,note right of或note over在节点(participant)的相对位              置放置注释。
    示例: 
    @startuml
       
    Alice -> Bob: Authentication Request
        note left:this is frist note /**添加注释(左侧)*/
        alt successful case
          Bob -> Alice: Authentication Accepted
        note right: this is right note  /**添加注释(左侧)*/
      else some kind of failure
          Bob -> Alice: Authentication Failure
          group My own label
          Alice -> Log : Log attack start
          loop 1000 times
          Alice -> Bob: DNS Attack
          end
          Alice -> Log : Log attack end
      end
      else Another type of failure
      Bob -> Alice: Please repeat
      note  left    /**添加多行注释(左侧)*/
            this is a note
          last note
      end note  /**添加多行注释(左侧) 以end note结束*/
      end
      @enduml
    (9)改变备注框的形状
        可以使用hnote和rnote这两个关键字来修改备注框的形状
        示例:
       
    @startuml
      caller -> server : conReq
      hnote over caller : idle
      caller <- server : conConf
      rnote over server
         "r" as rectangle
         "h" as hexagon
      endrnote
     @enduml
    (10)分隔符 
         
    可以通过使用==关键词来将你的图表分割多个步骤。
    (11)引用
       
    可以在图中通过使用ref over关键词来实现引用
        @startuml
        participant Alice
        actor Bob
        ref over Alice, Bob : init
        Alice -> Bob : hello
        ref over Bob
        This can be on
        several lines
        end ref
        @enduml
    (12)延迟
      可以使用...来表示延迟,并且还可以给延迟添加注释。
    (13)空间
      你可以使用|||来增加空间  ||45||指定增加的空间
    (14)生命线的激活与撤销
          关键字activate和deactivate用来表示参与者的生命活动。运行给生命线添加颜色。
         
    一旦参与者被激活,它的生命线就会显示出来。
          activate和deactivate适用于以上情形。
          destroy表示一个参与者的生命线的终结。
        示例:
          @startuml
            participant User
            User -> A: DoWork
            activate A
           
    A -> B: << createRequest >>
          activate B
          B -> C: DoWork
          activate C
          C --> B: WorkDone
          destroy C
          B --> A: RequestCreated
          deactivate B
          A -> User: Done
          deactivate A
          @enduml
    (15)创建参与者
          关键字create放在第一次接收到消息之前,以强调本次消息实际上是在创建新的对象
    (16)进入和发出消息
          如果只想关注部分图示,你可以使用进入和发出箭头。使用方括号[和]表示图示的左、右两侧。
          @startuml
          [-> A: DoWork
          activate A
       A -> A: Internal call
        activate A
        A ->] : << createRequest >>
        A<--] : RequestCreated
        deactivate A
        [<- A: Done
        deactivate A
        @enduml
    (17)构造类型和圈点
        可以使用<<和>>给参与者添加构造类型。在构造类型中,你可以使用(X,color)格式的语法添加一个圆圈圈起来的字符。
     默认使用guillemet字符来显示构造类型。 你可以使用外观参数guillemet来修改显示行为。
    (18)包裹参与者
       
    可以使用box和end box画一个盒子将参与者包裹起来。还可以在box关键字之后添加标题或者背景颜色
      @startuml
        box "Internal Service" #LightBlue
        participant Bob
        participant Alice
        end box
        participant Other
        Bob -> Alice : hello
        Alice -> Other : hello
        @enduml
    (19)移除脚注
      使用hide footbox关键字移除脚注
      @startuml
      hide footbox
      title Footer removed
      Alice -> Bob: Authentication Request
      Bob --> Alice: Authentication Response
      @enduml
    (20)外观参数(skinparam)
        使用skinparam命令改变颜色和字体。
      @startuml
       skinparam sequenceArrowThickness 2
       skinparam roundcorner 20
          skinparam maxmessagesize 60
          skinparam sequenceParticipant underline
        actor User
        participant "First Class" as A
        participant "Second Class" as B
        participant "Last Class" as C
        User -> A: DoWork
          activate A
          A -> B: Create Request
          activate B
          B -> C: DoWork
          activate C
          C --> B: WorkDone
          destroy C
          B --> A: Request Created
          deactivate B
          A --> User: Done
          deactivate A
    @enduml

    /**********************************************************************************************/
    参考文档 http://plantuml.com/
     

    相关文章

      网友评论

          本文标题:plantUML语法(-)时序图

          本文链接:https://www.haomeiwen.com/subject/rbvvyxtx.html