3,graph语法学习

来源:http://soft.xiaoshujiang.com/docs/grammar/feature/mermaid/#mermaid_5

本文在Vue主题下效果更好

概述

Generation of diagram and flowchart from text in a similar manner as markdown

通过 mermaid 可以实现以纯文本的方式绘制流程图,序列图,甘特图等。

小书匠编辑器在 markdown 强大的优势下,更是无缝集成了 mermaid 的所有功能,用户不需要任何配置,只要打开了语法开关,就可以使用所有 mermaid 图例功能。再加上小书匠的实时预览功能,可以马上查看到输入的 mermaid 代码生成的效果图。大大提高了用户绘图的速度。

使用

元数据标识: grammar_mermaid

想要使用该语法,需要在设置>扩展语法 里把mermaid选项打开。或者在每篇文章的元数据里通过 grammar_mermaid 进行控制。系统默认关闭mermaid语法功能

mermaid 提供了流程图,序列图,甘特图等多种图形效果

mermaid的语法为代码块语法的执行功能,语言为 mermaid

示例

​```mermaid!
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
如上内容效果如下:

```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```

# mermaid

## 流程图

因为 mermaid 支持不同图表,所以所有的流程图需要以 `graph` 开头

### 图表方向

在 `graph` 的后方添加流程图的显示方向

*   TB -从上到下
*   BT - 从下到上
*   RL - 从右到左
*   LR - 从左到右
*   TD - 跟 TB 一样,从上到下

​```mermaid!
graph LR
Start --> Stop

如上内容效果如下:

````mermaid
graph LR
    Start --> Stop
​```mermaid!
graph TB
    Start --> Stop
```
如上内容效果如下:

````mermaid
graph TB
    Start --> Stop
```

### 节点形状

#### 默认结点

​```mermaid!
graph TB
id

如上内容效果如下:

````mermaid
graph TB
    id
带文字说明的结点
​```mermaid
graph LR
    id1[This is the text in the box]
```
如上内容效果如下:

````mermaid
graph LR
    id1[This is the text in the box]
```

#### 带圆角文字说明的结点

​```mermaid!
graph LR
id1(This is the text in the box)

如上内容效果如下:

````mermaid
graph LR
    id1(This is the text in the box)
带文字说明的圆形结点
​```mermaid!
graph LR
    id1((This is the text in the circle))
```
如上内容效果如下:

````mermaid
graph LR
    id1((This is the text in the circle))
```

#### 带文字说明的飘带结点

​```mermaid!
graph LR
id1>This is the text in the box]

如上内容效果如下:

````mermaid
graph LR
    id1>This is the text in the box]
带文字说明的菱形结点
​```mermaid!
graph LR
    id1{This is the text in the box}
```
如上内容效果如下:

````mermaid
graph LR
    id1{This is the text in the box}
```

### 结点间的连线

结点间可以有不同形式的连接,比如实线,虚线,带箭头的线等

#### 带箭头的线

​```mermaid!
graph LR
A–>B

如上内容效果如下:

````mermaid
graph LR
    A-->B
没有任何修饰的线
​```mermaid!
graph LR
    A --- B
```
如上内容效果如下:

````mermaid
graph LR
    A --- B
```

#### 在线上有描述文字的线

​```mermaid!
graph LR
A-- This is the text —B

或者

​```mermaid!
graph LR
A—|This is the text|B

如上内容效果如下:

````mermaid
graph LR
    A-- This is the text ---B
This is the text
A
B
有箭头同时带上文字描述的线
​```mermaid!
graph LR
    A-->|text|B
```
如上内容效果如下:
```mermaid
graph LR
    A-- text -->B
```

​```mermaid!
graph LR
A–>|text|B

如上内容效果如下:
```mermaid
graph LR
    A-- text -->B
点状形式的线
​```mermaid!
graph LR;
   A-.->B;
```
如上内容效果如下:

````mermaid
graph LR;
   A-.->B;
```

#### 加粗的线

​```mermaid!
graph LR
A ==> B

如上内容效果如下:

````mermaid
graph LR
   A ==> B
带文字加粗的线
​```mermaid!
graph LR
   A == text ==> B
```
如上内容效果如下:

````mermaid
graph LR
   A == text ==> B
```

### 子图表



```
subgraph 子图表名称
    子图表中的描述语句...
end
```

示例代码

​```mermaid!
graph TB
c1–>a2
subgraph one
a1–>a2
end
subgraph two
b1–>b2
end
subgraph three
c1–>c2
end

如上内容效果如下:

````mermaid
graph TB
    c1-->a2
    subgraph one
    a1-->a2
    end
    subgraph two
    b1-->b2
    end
    subgraph three
    c1-->c2
    end

结点样式自定义

​```mermaid!
graph LR
    id1(Start)-->id2(Stop)
    style id1 fill:#f9f,stroke:#333,stroke-width:4px
    style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5
```
如上内容效果如下:

````mermaid
graph LR
    id1(Start)-->id2(Stop)
    style id1 fill:#f9f,stroke:#333,stroke-width:4px
    style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5
```

### 跟 fontawesome 字体的集成

使用 `fa: #图表名称#` 的语法添加 fontawesome

​```mermaid!
graph TD
B[“fa:fa-twitter for peace”]
B–>C[fa:fa-ban forbidden]
B–>D(fa:fa-spinner);
B–>E(A fa:fa-camera-retro perhaps?);

如上内容效果如下:

````mermaid
graph TD
    B["fa:fa-twitter for peace"]
    B-->C[fa:fa-ban forbidden]
    B-->D(fa:fa-spinner);
    B-->E(A fa:fa-camera-retro perhaps?);

序列图

https://mermaidjs.github.io/sequenceDiagram.html

因为 mermaid 支持不同图表,所以所有的序列图需要以 sequenceDiagram 开头

sequenceDiagram
    [参与者1][连线][参与者2]:消息文本
    ...

参与者

​```mermaid!
sequenceDiagram
    participant John
    participant Alice
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
```
如上内容效果如下:

````mermaid
sequenceDiagram
    participant John
    participant Alice
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
```

### 别名

​```mermaid!
sequenceDiagram
participant A as Alice
participant J as John
A->>J: Hello John, how are you?
J->>A: Great!

如上内容效果如下:

````mermaid
sequenceDiagram
    participant A as Alice
    participant J as John
    A->>J: Hello John, how are you?
    J->>A: Great!

连线

6种不同类型的连线

TypeDescription
->不带箭头的实线
–>不带箭头的虚线
->>带箭头的实线
–>>带箭头的虚线
-x末端为叉的实线(表示异步)
–x末端为叉的虚线(表示异步)

消息文本

消息显示在连线的上方

[参与者1][连线][参与者2]:消息文本

活动中

在消息线末尾增加 + ,则消息接收者进入当前消息的“活动中”状态;
在消息线末尾增加 - ,则消息接收者离开当前消息的“活动中”状态。

或者使用以下语法直接说明某个参与者进入/离开“活动中”状态:

activate 参与者
deactivate 参与者
​```mermaid!
sequenceDiagram
    Alice->>John: Hello John, how are you?
    activate John
    John-->>Alice: Great!
    deactivate John
```

如上内容效果如下:

```mermaid
sequenceDiagram
    Alice->>+John: Hello John, how are you?
    John-->>-Alice: Great!
```
在同一个参与者上面可以叠加多个活动中状态

​```mermaid!
sequenceDiagram
Alice->>+John: Hello John, how are you?
Alice->>+John: John, can you hear me?
John–>>-Alice: Hi Alice, I can hear you!
John–>>-Alice: I feel great!

如上内容效果如下:

````mermaid
sequenceDiagram
    Alice->>+John: Hello John, how are you?
    Alice->>+John: John, can you hear me?
    John-->>-Alice: Hi Alice, I can hear you!
    John-->>-Alice: I feel great!

标注

可以对流程图进行标注,标注位置支持 左侧, 右侧横跨 三种方式

Note 位置表述 参与者: 标注文字

其中位置表述可以为

表述含义
right of右侧
left of左侧
over在当中,可以横跨多个参与者
​```mermaid!
sequenceDiagram
    participant John
    Note right of John: Text in note
```
如上内容效果如下:

````mermaid
sequenceDiagram
    participant John
    Note right of John: Text in note
```

​```mermaid!
sequenceDiagram
participant John
Note left of John: Text in note

如上内容效果如下:

````mermaid
sequenceDiagram
    participant John
    Note left of John: Text in note
​```mermaid!
sequenceDiagram
    Alice->John: Hello John, how are you?
    Note over Alice,John: A typical interaction
```
如上内容效果如下:

````mermaid
sequenceDiagram
    Alice->>John: Hello John, how are you?
    Note over Alice,John: A typical interaction
```

###  循环

语法如下

```
loop 循环的条件
    循环体描述语句
end
```

示例

​```mermaid!
sequenceDiagram
Alice->John: Hello John, how are you?
loop Every minute
John–>Alice: Great!
end

如上内容效果如下:

````mermaid
sequenceDiagram
    Alice->>John: Hello John, how are you?
    loop Every minute
        John-->>Alice: Great!
    end

条件选择

语法如下

alt 条件 1 描述
    分支 1 描述语句
else 条件 2 描述 # else 分支可选
    分支 2 描述语句
else ...
    ...
end

如果遇到可选的情况,即没有 else 分支的情况,使用如下语法:

opt 条件描述
    分支描述语句
end

示例

​```mermaid!
sequenceDiagram
    Alice->>Bob: Hello Bob, how are you?
    alt is sick
        Bob->>Alice: Not so good :(
    else is well
        Bob->>Alice: Feeling fresh like a daisy
    end
    opt Extra response
        Bob->>Alice: Thanks for asking
    end
```
如上内容效果如下:

````mermaid
sequenceDiagram
    Alice->>Bob: Hello Bob, how are you?
    alt is sick
        Bob->>Alice: Not so good :(
    else is well
        Bob->>Alice: Feeling fresh like a daisy
    end
    opt Extra response
        Bob->>Alice: Thanks for asking
    end
```

### 自定义样式

mermaid 在生成序列图时,会定义很多 class, 配合上小书匠的自定义 css 样式,用户可以进行更个性化的样式控制

下面列出的是 mermaid 生成的 class 

| Class        | Description                                                 |
| ------------ | ----------------------------------------------------------- |
| actor        | Style for the actor box at the top of the diagram.          |
| text.actor   | Styles for text in the actor box at the top of the diagram. |
| actor-line   | The vertical line for an actor.                             |
| messageLine0 | Styles for the solid message line.                          |
| messageLine1 | Styles for the dotted message line.                         |
| messageText  | Defines styles for the text on the message arrows.          |
| labelBox     | Defines styles label to left in a loop.                     |
| labelText    | Styles for the text in label for loops.                     |
| loopText     | Styles for the text in the loop box.                        |
| loopLine     | Defines styles for the lines in the loop box.               |
| note         | Styles for the note box.                                    |
| noteText     | Styles for the text on in the note boxes.                   |


## 甘特图

https://mermaidjs.github.io/gantt.html

> A Gantt chart is a type of bar chart, first developed by Karol Adamiecki in 1896, and independently by Henry Gantt in the 1910s, that illustrates a project schedule. Gantt charts illustrate the start and finish dates of the terminal elements and summary elements of a project.

甘特图是一类条形图,由Karol Adamiechi在1896年提出, 而在1910年Henry Gantt也独立的提出了此种图形表示。通常用在对项目终端元素和总结元素的开始及完成时间进行的描述。


语法 

```
gantt
       dateFormat  时间格式
       title 标题

       section 小节标题
       任务描述            :状态,    起始节点, 时间段
```

| 标记       | 简介               |
| ---------- | ------------------ |
| title      | 标题               |
| dateFormat | 日期格式           |
| section    | 模块               |
| done       | 已经完成           |
| active     | 当前正在进行       |
|            | 后续待处理         |
| crit       | 关键阶段           |
| 日期缺失   | 默认从上一项完成后 |

关于日期的格式可以参考: http://momentjs.com/docs/#/parsing/string-format/

关于 Scale 的格式可以参考: https://github.com/mbostock/d3/wiki/Time-Formatting

示例

​```mermaid!
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2014-01-12 , 12d
another task : 24d

如上内容效果如下:

````mermaid
gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2014-01-01, 30d
    Another task     :after a1  , 20d
    section Another
    Task in sec      :2014-01-12  , 12d
    another task      : 24d

一个更加复杂的例子

​```mermaid!
gantt
       dateFormat  YYYY-MM-DD
       title Adding GANTT diagram functionality to mermaid

       section A section
       Completed task            :done,    des1, 2014-01-06,2014-01-08
       Active task               :active,  des2, 2014-01-09, 3d
       Future task               :         des3, after des2, 5d
       Future task2              :         des4, after des3, 5d

       section Critical tasks
       Completed task in the critical line :crit, done, 2014-01-06,24h
       Implement parser and jison          :crit, done, after des1, 2d
       Create tests for parser             :crit, active, 3d
       Future task in critical line        :crit, 5d
       Create tests for renderer           :2d
       Add to mermaid                      :1d

       section Documentation
       Describe gantt syntax               :active, a1, after des1, 3d
       Add gantt diagram to demo page      :after a1  , 20h
       Add another diagram to demo page    :doc1, after a1  , 48h

       section Last section
       Describe gantt syntax               :after doc1, 3d
       Add gantt diagram to demo page      :20h
       Add another diagram to demo page    :48h
```
如上内容效果如下:

````mermaid
gantt
       dateFormat  YYYY-MM-DD
       title Adding GANTT diagram functionality to mermaid

       section A section
       Completed task            :done,    des1, 2014-01-06,2014-01-08
       Active task               :active,  des2, 2014-01-09, 3d
       Future task               :         des3, after des2, 5d
       Future task2              :         des4, after des3, 5d

       section Critical tasks
       Completed task in the critical line :crit, done, 2014-01-06,24h
       Implement parser and jison          :crit, done, after des1, 2d
       Create tests for parser             :crit, active, 3d
       Future task in critical line        :crit, 5d
       Create tests for renderer           :2d
       Add to mermaid                      :1d

       section Documentation
       Describe gantt syntax               :active, a1, after des1, 3d
       Add gantt diagram to demo page      :after a1  , 20h
       Add another diagram to demo page    :doc1, after a1  , 48h

       section Last section
       Describe gantt syntax               :after doc1, 3d
       Add gantt diagram to demo page      :20h
       Add another diagram to demo page    :48h
```

# 疑问

# 相关

1. [mermaid 官网](http://knsv.github.io/mermaid/index.html)
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
TensorFlow是一个广泛使用的开源机器学习框架,适合进行深度学习项目的开发。学习TensorFlow的路线主要包括环境配置、基础语法学习、基本概念理解、框架与源码分析等步骤。具体如下: 1. **环境配置**:首先需要安装Python和TensorFlow。确保你的计算机满足TensorFlow运行的系统要求,然后通过pip或conda安装TensorFlow库。 2. **Python基础语法**:掌握Python编程语言的基础语法学习TensorFlow的前提。你需要熟悉变量、控制流、函数、类等基础概念。 3. **TensorFlow基本概念**:理解TensorFlow的核心概念,如张量(Tensor)、计算图(Computation Graph)、会话(Session)等。这些是构建和训练模型的基础。 4. **TensorFlow框架和源码分析**:深入学习TensorFlow的架构设计,了解其内部工作原理。这有助于你更高效地使用TensorFlow解决问题。 5. **实践操作**:通过实际案例来学习如何使用TensorFlow构建、训练和测试模型。你可以从简单的模型开始,逐步增加难度,例如从MNIST手写数字识别开始,再逐步尝试更复杂的数据集和网络结构。 6. **高级应用**:学习如何使用TensorFlow的高级功能,比如可视化工具TensorBoard,以及如何将训练好的模型进行量化、压缩和移植到移动设备上。 7. **理论与实践结合**:阅读相关的学术论文和技术博客,理解最新的理论模型和技术发展。尝试自己实现论文中的模型,或者在实际项目中应用学到的知识。 8. **持续学习**:技术是不断发展的,持续关注TensorFlow的更新和社区动态,学习新的技术和最佳实践。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值