如何与 emacs 及 org-mode 整合使用

  • 参考
  • org 例子

    1
    2
    3
    
    @startuml
    Alice -> Bob: like
    @enduml

与 org-mode 共用

方法:通过 org-babel 实现 参考:

与 markdown 共用

外部程序解析法

直接编写法

参考:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<img src='https://g.gravizo.com/svg?
 digraph G {
   main -> parse -> execute;
   main -> init;
   main -> cleanup;
   execute -> make_string;
   execute -> printf
   init -> make_string;
   main -> printf;
   execute -> compare;
 }
'/>

活动图(基本流程图)

说明:Activity Diagram, 活动图就是通常意义上的基本流程图。 参考:

开始结束节点

  • 开始

    • start
  • 结束

    • stop
    • end (中间画 X 的图形)

分支语句

if

switch

if 语句绘图风格

  • 风格

    • 水平展示(默认风格)
    • 竖直展示

      • !pragma useVerticalIf on

平行语句

fork

split

循环语句

  • repeat

    • do while
  • while
  • break 中断循环

goto 语句,随意跳转

注释 note

关键值: note

  • 单行注释

    1
    
    note: a single line note
    • 注意:使用 : 分割注释内容
  • 多行注释

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    @startuml
    start
    :开始节点;
    
    note
    This is my multiple line note
    second line
    end note
    @enduml
    • 注意:

      • 开始声明用: note
      • 结束声明用: end note

注释位置

  • 右侧: note right
  • 左侧: note left
  • 悬浮: floating

    • 特点:不带指向箭头
    • floating note left
    • floating note right

箭头和连接线 arrow and lines

  • 取消连接线(取消箭头)

    • -[hidden]->
    • kill
    • detach
  • 箭头样式

    • 虚线: -[dotted]->
    • 颜色: -[#red]->
    • 颜色 + 虚线: -[#red, dotted]->
  • 连接线(箭头)上的文字

    • eg: ->This is the text

连接器 connector

作用:用于,在一个地方声明连接到什么,在另一个地方再声明续接的是什么。

  • 关键字

    • (char)
    • eg: (A), (Z)

分组

  • 工具

    • group
    • partition
    • package
    • rectangle
    • card

泳道图 swimlanes

  • 泳道声明

    • |Swimlane1|
    • |Swimlane2|
    • |我的泳道|
    • 注意:通过语法格式声明泳道,和名称无关
  • 带颜色泳道

    • |#red|Swimlane3|
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml

多个分支

  • 两种方法

    • fork

      • 通过粗线把多个分支聚合在引擎
    • split

节点形状

  • SDL (Specification and Description Language)
  • 通过把 :节点; 结尾的 ; 换成下列符号,来改变

    • | : 两端双竖线,用来表示 子流程
    • < : 改变右端
    • > : 改变右端
    • / : 右斜平行四边形, 用于处理环节节点
    • \\ : 左斜平行四边形
    • ] : 长方形
    • } : < content >

风格 style

作用: 控制展示(绘图风格) 控制关键字: skinparam

条件语句风格 Condition Style

作用:控制条件语句所在节点的展示形式

  • 相关条件

    • if
    • while (循环)
  • 风格

    • inside (默认风格)

      • skinparam conditionStyle inside
      • 说明:条件说明文字放置在条件节点形状内部(inside)
      • 注意:这里条件节点形状不是菱形
    • diamond

      • 钻石风格
      • 说明:条件节点是菱形,文字放在外部
    • insideDiamond(或 Foo1)

      • 说明:条件文字在菱形内部

调节节点结尾风格 Condtion End Style

作用:控制多个条件的分支聚合在一起的方式

  • 风格

    • diamond (默认风格)

      • 通过一个内部为空的菱形连接
      • skinparam ConditionEndStyle hline
    • horizontal line (hline)

      • 通过一条水平线连接

全局风格

说明:

  • 默认不设置,即:

    • 全部是无颜色填充的线框绘制

使用方法:

  • 类似 css 的方法,声明 stylesheet

eg:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@startuml
<style>
activityDiagram {
  BackgroundColor #33668E
  BorderColor #33668E
  FontColor #888
  FontName arial

  diamond {
    BackgroundColor #ccf
    LineColor #00FF00
    FontColor green
    FontName arial
    FontSize 15
  }
  arrow {
    FontColor gold
    FontName arial
    FontSize 15
  }
  partition {
    LineColor red
    FontColor green
    RoundCorner 10
    BackgroundColor PeachPuff
  }
  note {
    FontColor Blue
    LineColor Navy
    BackgroundColor #ccf
  }
}
document {
   BackgroundColor transparent
}
</style>
start
:init;
-> test of color;
if (color?) is (<color:red>red) then
:print red;
else
:print not red;
note right: no color
endif
partition End {
:end;
}
-> this is the end;
end
@enduml

Visio 风格控制

1
2
3
!pragma useVerticalIf on
skinparam conditionStyle insideDiamond
skinparam ConditonEndStyle hline

注释语法(粗体等)

时序图 Sequence Diagram

参考:

说明:

  • 又名序列图、循序图,描述按各对象间按时间的先后发送消息的顺序。

时序图中的元素

  • 角色 Actor
  • 对象 Object
  • 生命线 LifeLine
  • 控制焦点 Activation
  • 消息 Message

    • 自关联消息: -> 表示,实心箭头
    • 同步消息: -> 表示, 实线 + 实心箭头
    • 异步消息: ->> 表示,实线 + 大于号(空心箭头)
    • 返回消息: <<– 表示, 小于号(空心箭头) + 实线
  • 组合片断

箭头表示

  • 箭头类型:

    • x : 表示消息丢失
    • / 或 \ : 半实线箭头
    • // 或 \\ : 半空心箭头
    • << 或 >> 空心箭头
  • (箭杆)线型:

    • - : 实线
    • --: 空心线
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@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