GitHubのMarkdownファイルでMermaid記法がサポートされたので作図まとめてみました。

https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/

Mermaid[^Mermaid]はコードで作図することができるツールです。
いままではmermaid.jsが必要でしたが、今回GitHubのMarkdownファイルで、Mermaid記法がサポートされました。

それに伴い、Mermaidで表現できる図についてまとめてみました。
なお簡単にMermaidを試す方法として、Live Editor[^LiveEditor]もあります。

# 可能な作図一覧

## フローチャート（Flowchart）

https://mermaid.js.org/syntax/flowchart.html

```
graph TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
```

![mermaid-diagram-20220215195953.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/5ce942d3-23cb-4586-1425-bb1124f51ef1.png)


## シーケンス図（Sequence diagram）

https://mermaid.js.org/syntax/sequenceDiagram.html

```
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-diagram-20220215200116.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/71aeda90-ba7e-dc01-b55b-7a9c19d4a526.png)


## クラス図（Class diagram）

https://mermaid.js.org/syntax/classDiagram.html

```
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-diagram-20220215200235.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/56f2b568-7f81-4d3f-bd39-2332bbd9c0bf.png)


## ステート図（State diagram）

https://mermaid.js.org/syntax/stateDiagram.html

```
stateDiagram-v2
    [*] --> Still
    Still --> [*]
    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
```

![mermaid-diagram-20220215200334.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/77af03e2-5308-b960-42a5-9c359cf79b7c.png)


## ER図（Entity Relationship Diagram）

https://mermaid.js.org/syntax/entityRelationshipDiagram.html

```
erDiagram
          CUSTOMER }|..|{ DELIVERY-ADDRESS : has
          CUSTOMER ||--o{ ORDER : places
          CUSTOMER ||--o{ INVOICE : "liable for"
          DELIVERY-ADDRESS ||--o{ ORDER : receives
          INVOICE ||--|{ ORDER : covers
          ORDER ||--|{ ORDER-ITEM : includes
          PRODUCT-CATEGORY ||--|{ PRODUCT : contains
          PRODUCT ||--o{ ORDER-ITEM : "ordered in"
```

![mermaid-diagram-20220215200419.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/56a915e6-3266-e94d-6d83-545acd30e6ba.png)


## ジャーニーマップ（User Journey Diagram）

https://mermaid.js.org/syntax/userJourney.html

```
  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: 3: Me
```

![mermaid-diagram-20220215200508.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/6f03c275-8291-0692-cda0-a962b2966e5c.png)


## ガント図（Gantt diagram）

https://mermaid.js.org/syntax/gantt.html

```
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-diagram-20220215200551.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/7559eeac-ed3c-b9c9-bd31-e875700a9064.png)


## 円グラフ（Pie chart diagram）

https://mermaid.js.org/syntax/pie.html

```
pie title Pets adopted by volunteers
    "Dogs" : 386
    "Cats" : 85
    "Rats" : 15
```

![mermaid-diagram-20220215200634.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/8e184e32-c11f-d258-5d67-c9ef5d8f621f.png)


## 要求図（Requirement Diagram）

https://mermaid.js.org/syntax/requirementDiagram.html

```
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-diagram-20220215200737.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/6280/4ba064a5-ba53-d752-2f85-0774473e6caf.png)

# 脚注

[^Mermaid]: https://mermaid.js.org/
[^LiveEditor]:https://mermaid-js.github.io/mermaid-live-editor