--- weight: 5 title: "主题文档 - mermaid Shortcode" date: 2020-03-03T15:29:59+08:00 lastmod: 2020-03-03T15:29:59+08:00 draft: false author: "Dillon" authorLink: "https://dillonzq.com" description: "mermaid shortcode 使用 Mermaid 库提供绘制图表和流程图的功能." images: ["featured-image.png"] resources: - name: "featured-image" src: "featured-image.png" tags: ["shortcodes"] categories: ["documentation"] hiddenFromHomePage: true --- `mermaid` shortcode 使用 [Mermaid](https://mermaidjs.github.io/) 库提供绘制图表和流程图的功能. [mermaid](https://mermaidjs.github.io/) 是一个可以帮助你在文章中绘制图表和流程图的库, 类似 Markdown 的语法. 只需将你的 mermaid 代码插入 `mermaid` shortcode 中即可. ## 流程图 {#flowchart} 一个 **流程图** `mermaid` 示例: ```markdown {{}} graph LR; A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two] {{}} ``` 呈现的输出效果如下: {{< mermaid >}} graph LR; A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two] {{< /mermaid >}} ## 时序图 {#sequence-diagram} 一个 **时序图** `mermaid` 示例: ```markdown {{}} sequenceDiagram participant Alice participant Bob Alice->>John: Hello John, how are you? loop Healthcheck John->John: Fight against hypochondria end Note right of John: Rational thoughts
prevail... John-->Alice: Great! John->Bob: How about you? Bob-->John: Jolly good! {{}} ``` 呈现的输出效果如下: {{< mermaid >}} sequenceDiagram participant Alice participant Bob Alice->>John: Hello John, how are you? loop Healthcheck John->John: Fight against hypochondria end Note right of John: Rational thoughts
prevail... John-->Alice: Great! John->Bob: How about you? Bob-->John: Jolly good! {{< /mermaid >}} ## 甘特图 {#gantt} 一个 **甘特图** `mermaid` 示例: ```markdown {{}} gantt dateFormat YYYY-MM-DD title Adding GANTT diagram to mermaid excludes weekdays 2014-01-10 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 {{}} ``` 呈现的输出效果如下: {{< mermaid >}} gantt dateFormat YYYY-MM-DD title Adding GANTT diagram to mermaid excludes weekdays 2014-01-10 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 {{< /mermaid >}} ## 类图 {#class-diagram} 一个 **类图** `mermaid` 示例: ```markdown {{}} classDiagram Animal <|-- Duck Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() } {{}} ``` 呈现的输出效果如下: {{< mermaid >}} classDiagram Animal <|-- Duck Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() } {{< /mermaid >}} ## 状态图 {#state-diagram} 一个 **状态图** `mermaid` 示例: ```markdown {{}} stateDiagram-v2 [*] --> Still Still --> [*] Still --> Moving Moving --> Still Moving --> Crash Crash --> [*] {{}} ``` 呈现的输出效果如下: {{< mermaid >}} stateDiagram-v2 [*] --> Still Still --> [*] Still --> Moving Moving --> Still Moving --> Crash Crash --> [*] {{< /mermaid >}} ## Git 图 {#git-graph} 一个 **Git 图** `mermaid` 示例: ```markdown {{}} gitGraph commit commit branch develop checkout develop commit commit checkout main merge develop commit commit {{}} ``` 呈现的输出效果如下: {{< mermaid >}} gitGraph commit commit branch develop checkout develop commit commit checkout main merge develop commit commit {{< /mermaid >}} ## 实体关系图 {#entity-relationship-diagram} 一个 **实体关系图** `mermaid` 示例: ```markdown {{}} erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE-ITEM : contains CUSTOMER }|..|{ DELIVERY-ADDRESS : uses {{}} ``` 呈现的输出效果如下: {{< mermaid >}} erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE-ITEM : contains CUSTOMER }|..|{ DELIVERY-ADDRESS : uses {{< /mermaid >}} ## 用户体验旅程图 {#user-journey} 一个 **用户体验旅程图** `mermaid` 示例: ```markdown {{}} journey title My working day section Go to work Make tea: 5: Me Go upstairs: 3: Me Do work: 1: Me, Cat section Go home Go downstairs: 5: Me Sit down: 5: Me {{}} ``` 呈现的输出效果如下: {{< mermaid >}} journey title My working day section Go to work Make tea: 5: Me Go upstairs: 3: Me Do work: 1: Me, Cat section Go home Go downstairs: 5: Me Sit down: 5: Me {{< /mermaid >}} ## 饼图 {#pie} 一个 **饼图** `mermaid` 示例: ```markdown {{}} pie "Dogs" : 386 "Cats" : 85 "Rats" : 15 {{}} ``` 呈现的输出效果如下: {{< mermaid >}} pie "Dogs" : 386 "Cats" : 85 "Rats" : 15 {{< /mermaid >}} ## 依赖图 {#requirement-diagram} 一个 **依赖图** `mermaid` 示例: ```markdown {{}} requirementDiagram requirement test_req { id: 1 text: the test text. risk: high verifymethod: test } element test_entity { type: simulation } test_entity - satisfies -> test_req {{}} ``` 呈现的输出效果如下: {{< mermaid >}} requirementDiagram requirement test_req { id: 1 text: the test text. risk: high verifymethod: test } element test_entity { type: simulation } test_entity - satisfies -> test_req {{< /mermaid >}}