常见图形案例

PlantUML

Sequence Diagram 时序图

http://plantuml.com/sequence-diagram

常见图形案例 - 图1

  1. @startuml
    skinparam sequenceArrowThickness 2
    skinparam roundcorner 20
    skinparam maxmessagesize 60
    skinparam sequenceParticipant underline

  2. actor User
    participant "First Class" as A
    participant "Second Class" as B
    participant "Last Class" as C

  3. User -> A: DoWork
    activate A

  4. A -> B: Create Request
    activate B

  5. B -> C: DoWork
    activate C
    C —> B: WorkDone
    destroy C

  6. B —> A: Request Created
    deactivate B

  7. A —> User: Done
    deactivate A

  8. @enduml

交互草图

更多文档请查看 http://plantuml.com/salt

常见图形案例 - 图2

  1. @startuml
    (*) —> "
    {{
    salt
    {+
    <b>an example
    choose one option
    ()one
    ()two
    [ok]
    }
    }}
    " as choose

  2. choose -right-> "
    {{
    salt
    {+
    <b>please wait
    operation in progress
    <&clock>
    [cancel]
    }
    }}
    " as wait
    wait -right-> "
    {{
    salt
    {+
    <b>success
    congratulations!
    [ok]
    }
    }}
    " as success

  3. wait -down-> "
    {{
    salt
    {+
    <b>error
    failed, sorry
    [ok]
    }
    }}
    "
    @enduml

Activity Diagram 活动图

详细文档 http://plantuml.com/activity-diagram-beta#sdl

常见图形案例 - 图3

  1. @startuml

  2. start
    :ClickServlet.handleRequest();
    :new page;
    if (Page.onSecurityCheck) then (true)
    :Page.onInit();
    if (isForward?) then (no)
    :Process controls;
    if (continue processing?) then (no)
    stop
    endif

  3. if (isPost?) then (yes)
    :Page.onPost();
    else (no)
    :Page.onGet();
    endif
    :Page.onRender();
    endif
    else (false)
    endif

  4. if (do redirect?) then (yes)
    :redirect process;
    else
    if (do forward?) then (yes)
    :Forward request;
    else (no)
    :Render page template;
    endif
    endif

  5. stop

  6. @enduml

Gantt Diagram 甘特图

详细文档 http://plantuml.com/gantt-diagram

常见图形案例 - 图4

  1. @startgantt
    [Task1] lasts 10 days
    then [Task2] lasts 4 days
    Phase Two
    then [Task3] lasts 5 days
    then [Task4] lasts 6 days
    @endgantt

Timing Diagram

http://plantuml.com/timing-diagram

常见图形案例 - 图5

  1. @startuml
    robust "DNS Resolver" as DNS
    robust "Web Browser" as WB
    concise "Web User" as WU

  2. @0
    WU is Idle
    WB is Idle
    DNS is Idle

  3. @+100
    WU -> WB : URL
    WU is Waiting
    WB is Processing

  4. @+200
    WB is Waiting
    WB -> DNS@+50 : Resolve URL

  5. @+100
    DNS is Processing

  6. @+300
    DNS is Idle
    @enduml

Deployment Diagram

http://plantuml.com/deployment-diagram

常见图形案例 - 图6

  1. @startuml

  2. node node1
    node node2
    node node3
    node node4
    node node5
    node1 node2 : label1
    node1 .. node3 : label2
    node1 ~~ node4 : label3
    node1 == node5

  3. @enduml

Component Diagram

http://plantuml.com/component-diagram

You can use several keywords to group components and interfaces together:

  • package
  • node
  • folder
  • frame
  • cloud
  • database

常见图形案例 - 图7

  1. @startuml

  2. package "Some Group" {
    HTTP - [First Component]
    [Another Component]
    }

  3. node "Other Groups" {
    FTP - [Second Component]
    [First Component] —> FTP
    }

  4. cloud {
    [Example 1]
    }

  5. database "MySql" {
    folder "This is my folder" {
    [Folder 3]
    }
    frame "Foo" {
    [Frame 4]
    }
    }

  6. [Another Component] —> [Example 1]
    [Example 1] —> [Folder 3]
    [Folder 3] —> [Frame 4]

  7. @enduml

Class Diagram 类图

http://plantuml.com/class-diagram

You can use the interface, annotation and enum keywords too.

常见图形案例 - 图8

  1. @startuml

  2. abstract class AbstractList
    abstract AbstractCollection
    interface List
    interface Collection

  3. List <|— AbstractList
    Collection <|— AbstractCollection

  4. Collection <|- List
    AbstractCollection <|- AbstractList
    AbstractList <|— ArrayList

  5. class ArrayList {
    Object[] elementData
    size()
    }

  6. enum TimeUnit {
    DAYS
    HOURS
    MINUTES
    }

  7. annotation SuppressWarnings

  8. @enduml

Use Case Diagram 用例图

http://plantuml.com/use-case-diagram

常见图形案例 - 图9

  1. @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

Graphviz

Graphviz 画一个 Hash Table

常见图形案例 - 图10

  1. digraph g {
  2. rankdir=LR;
  3. node [shape=record,width=01,height=.1];
  4. a[label="<1>Hash Table|<2>Node|<3>Node|...|<4>TreeNode"];
  5. {
  6. node1[label="{<1>A1|<2>A2|...|An}"]
  7. node2[label="{<1>B1|<2>B2|...|Bn}"]
  8. subgraph cluster_treenode{
  9. penwidth=0;
  10. node[shape=circle];
  11. root[label="", style=filled,fillcolor=black,width=.2];
  12. n1[label="", style=filled,fillcolor=red,width=.2]
  13. n2[label="", style=filled,fillcolor=black,width=.2]
  14. n3[label="", style=filled,fillcolor=black,width=.2]
  15. n4[label="", style=filled,fillcolor=red,width=.2]
  16. n5[label="", style=filled,fillcolor=black,width=.2]
  17. n6[label="", style=filled,fillcolor=black,width=.2]
  18. root->n1;
  19. n1->n2;
  20. n1->n3;
  21. root->n4;
  22. n4->n5;
  23. n4->n6;
  24. }
  25. }
  26.  
  27. a:2:e->node1:1 [style=dashed];
  28. a:3:e->node2:1;
  29. a:4:e->root;
  30. }

Graphviz 画证书链

常见图形案例 - 图11

  1. digraph G {
  2. nodesep=1.0 // increases the separation between nodes
  3. "Class 3 Public Primary Certification Authority" [style=filled, fillcolor=green]
  4. "VeriSign Class 3 Public Primary Certification Authority - G5" [style=filled, fillcolor=cyan]
  5. "DigiCert Global Root G2" [style=filled, fillcolor=cyan]
  6. "DigiCert Global CA G2" [style=filled, fillcolor=peru]
  7. "Server证书" [style=filled, fillcolor=peru]
  8. "Class 3 Public Primary Certification Authority"->{"VeriSign Class 3 Public Primary Certification Authority - G5"}
  9. "VeriSign Class 3 Public Primary Certification Authority - G5"->{"DigiCert Global Root G2"}
  10. "DigiCert Global Root G2"->{"DigiCert Global CA G2"}
  11. "DigiCert Global CA G2"->{"Server证书"}
  12. }

Graphviz 画公司部门结构

常见图形案例 - 图12

  1. digraph hierarchy {
  2. nodesep=1.0 // increases the separation between nodes
  3. node [shape=box] //All nodes will this shape
  4. edge [color="#D9D9D9", style=dashed] //All the lines look like this
  5.  
  6. 总经理->{市场部 人事部 技术部}
  7. 市场部->{销售处 广告处}
  8. 技术部->IT经理
  9. {rank=same;IT经理 销售处 广告处} // Put them on the same level
  10. }

Graphviz 画模块依赖图

常见图形案例 - 图13

  1. digraph G {
  2. main -> parse -> execute;
  3. main -> init;
  4. main -> cleanup;
  5. execute -> make_string;
  6. execute -> printf
  7. init -> make_string;
  8. main -> printf;
  9. execute -> compare;
  10. }

若有收获,就赏束稻谷吧

35 颗稻谷