2021-01-02 17:55:31 +03:00
|
|
|
|
---
|
2022-03-27 15:01:30 +03:00
|
|
|
|
icon: material/graph-outline
|
2021-01-02 17:55:31 +03:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Diagrams
|
|
|
|
|
|
|
|
|
|
Diagrams help to communicate complex relationships and interconnections between
|
|
|
|
|
different technical components, and are a great addition to project
|
2021-10-03 21:28:52 +03:00
|
|
|
|
documentation. Material for MkDocs integrates with [Mermaid.js], a very
|
2021-01-02 17:55:31 +03:00
|
|
|
|
popular and flexible solution for drawing diagrams.
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Mermaid.js]: https://mermaid-js.github.io/mermaid/
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
2023-01-01 21:17:33 +03:00
|
|
|
|
[:octicons-tag-24: 8.2.0][Diagrams support]
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
This configuration enables native support for [Mermaid.js] diagrams. Material
|
|
|
|
|
for MkDocs will automatically initialize the JavaScript runtime when a page
|
|
|
|
|
includes a `mermaid` code block:
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
markdown_extensions:
|
2021-01-02 18:43:46 +03:00
|
|
|
|
- pymdownx.superfences:
|
2021-01-02 17:55:31 +03:00
|
|
|
|
custom_fences:
|
|
|
|
|
- name: mermaid
|
2021-07-18 18:50:45 +03:00
|
|
|
|
class: mermaid
|
2021-01-05 20:50:08 +03:00
|
|
|
|
format: !!python/name:pymdownx.superfences.fence_code_format
|
2021-01-02 17:55:31 +03:00
|
|
|
|
```
|
|
|
|
|
|
2021-10-05 00:36:31 +03:00
|
|
|
|
No further configuration is necessary. Advantages over a custom integration:
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
- [x] Works with [instant loading] without any additional effort
|
2021-01-02 17:55:31 +03:00
|
|
|
|
- [x] Diagrams automatically use fonts and colors defined in `mkdocs.yml`[^1]
|
2021-10-10 13:19:14 +03:00
|
|
|
|
- [x] Fonts and colors can be customized with [additional style sheets]
|
|
|
|
|
- [x] Support for both, light and dark color schemes – _try it on this page!_
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
|
|
|
|
[^1]:
|
2021-10-03 21:28:52 +03:00
|
|
|
|
While all [Mermaid.js] features should work out-of-the-box, Material for
|
2021-10-05 00:36:31 +03:00
|
|
|
|
MkDocs will currently only adjust the fonts and colors for flowcharts,
|
2023-02-03 13:06:10 +03:00
|
|
|
|
sequence diagrams, class diagrams, state diagrams and entity relationship
|
|
|
|
|
diagrams. See the section on [other diagrams] for more information why this
|
2022-04-24 13:52:45 +03:00
|
|
|
|
is currently not implemented for all diagrams.
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2022-02-17 19:20:36 +03:00
|
|
|
|
[Diagrams support]: https://github.com/squidfunk/mkdocs-material/releases/tag/8.2.0
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[instant loading]: ../setup/setting-up-navigation.md#instant-loading
|
2021-10-10 13:19:14 +03:00
|
|
|
|
[additional style sheets]: ../customization.md#additional-css
|
2022-04-24 13:52:45 +03:00
|
|
|
|
[other diagrams]: #other-diagrams
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
2021-07-18 18:50:45 +03:00
|
|
|
|
### Using flowcharts
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Flowcharts] are diagrams that represent workflows or processes. The steps
|
2021-07-18 18:50:45 +03:00
|
|
|
|
are rendered as nodes of various kinds and are connected by edges, describing
|
2022-01-10 16:31:58 +03:00
|
|
|
|
the necessary order of steps:
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2022-01-11 12:19:33 +03:00
|
|
|
|
```` markdown title="Flow chart"
|
2021-01-02 17:55:31 +03:00
|
|
|
|
``` mermaid
|
|
|
|
|
graph LR
|
|
|
|
|
A[Start] --> B{Error?};
|
|
|
|
|
B -->|Yes| C[Hmm...];
|
|
|
|
|
C --> D[Debug];
|
|
|
|
|
D --> B;
|
|
|
|
|
B ---->|No| E[Yay!];
|
|
|
|
|
```
|
|
|
|
|
````
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
<div class="result" markdown>
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2021-06-15 12:03:15 +03:00
|
|
|
|
``` mermaid
|
|
|
|
|
graph LR
|
|
|
|
|
A[Start] --> B{Error?};
|
|
|
|
|
B -->|Yes| C[Hmm...];
|
|
|
|
|
C --> D[Debug];
|
|
|
|
|
D --> B;
|
|
|
|
|
B ---->|No| E[Yay!];
|
|
|
|
|
```
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Flowcharts]: https://mermaid-js.github.io/mermaid/#/flowchart
|
2021-01-02 17:55:31 +03:00
|
|
|
|
|
2021-07-18 18:50:45 +03:00
|
|
|
|
### Using sequence diagrams
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Sequence diagrams] describe a specific scenario as sequential interactions
|
2021-07-18 18:50:45 +03:00
|
|
|
|
between multiple objects or actors, including the messages that are exchanged
|
2022-01-10 16:31:58 +03:00
|
|
|
|
between those actors:
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
2022-01-11 12:19:33 +03:00
|
|
|
|
```` markdown title="Sequence diagram"
|
2021-07-18 18:50:45 +03:00
|
|
|
|
``` mermaid
|
|
|
|
|
sequenceDiagram
|
2022-12-07 23:24:41 +03:00
|
|
|
|
autonumber
|
2021-07-18 18:50:45 +03:00
|
|
|
|
Alice->>John: Hello John, how are you?
|
|
|
|
|
loop Healthcheck
|
|
|
|
|
John->>John: Fight against hypochondria
|
|
|
|
|
end
|
|
|
|
|
Note right of John: Rational thoughts!
|
|
|
|
|
John-->>Alice: Great!
|
|
|
|
|
John->>Bob: How about you?
|
|
|
|
|
Bob-->>John: Jolly good!
|
|
|
|
|
```
|
|
|
|
|
````
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
<div class="result" markdown>
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
``` mermaid
|
|
|
|
|
sequenceDiagram
|
2022-12-07 23:24:41 +03:00
|
|
|
|
autonumber
|
2021-07-18 18:50:45 +03:00
|
|
|
|
Alice->>John: Hello John, how are you?
|
|
|
|
|
loop Healthcheck
|
|
|
|
|
John->>John: Fight against hypochondria
|
|
|
|
|
end
|
|
|
|
|
Note right of John: Rational thoughts!
|
|
|
|
|
John-->>Alice: Great!
|
|
|
|
|
John->>Bob: How about you?
|
|
|
|
|
Bob-->>John: Jolly good!
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Sequence diagrams]: https://mermaid-js.github.io/mermaid/#/sequenceDiagram
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
### Using state diagrams
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[State diagrams] are a great tool to describe the behavior of a system,
|
2021-07-18 18:50:45 +03:00
|
|
|
|
decomposing it into a finite number of states, and transitions between those
|
2022-01-10 16:31:58 +03:00
|
|
|
|
states:
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
2022-01-11 12:19:33 +03:00
|
|
|
|
```` markdown title="State diagram"
|
2021-07-18 18:50:45 +03:00
|
|
|
|
``` mermaid
|
|
|
|
|
stateDiagram-v2
|
2022-01-10 16:31:58 +03:00
|
|
|
|
state fork_state <<fork>>
|
|
|
|
|
[*] --> fork_state
|
|
|
|
|
fork_state --> State2
|
|
|
|
|
fork_state --> State3
|
|
|
|
|
|
|
|
|
|
state join_state <<join>>
|
|
|
|
|
State2 --> join_state
|
|
|
|
|
State3 --> join_state
|
|
|
|
|
join_state --> State4
|
|
|
|
|
State4 --> [*]
|
2021-07-18 18:50:45 +03:00
|
|
|
|
```
|
|
|
|
|
````
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
<div class="result" markdown>
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
``` mermaid
|
|
|
|
|
stateDiagram-v2
|
2022-01-10 16:31:58 +03:00
|
|
|
|
state fork_state <<fork>>
|
|
|
|
|
[*] --> fork_state
|
|
|
|
|
fork_state --> State2
|
|
|
|
|
fork_state --> State3
|
|
|
|
|
|
|
|
|
|
state join_state <<join>>
|
|
|
|
|
State2 --> join_state
|
|
|
|
|
State3 --> join_state
|
|
|
|
|
join_state --> State4
|
|
|
|
|
State4 --> [*]
|
2021-07-18 18:50:45 +03:00
|
|
|
|
```
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[State diagrams]: https://mermaid-js.github.io/mermaid/#/stateDiagram
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
### Using class diagrams
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Class diagrams] are central to object oriented programing, describing the
|
2021-07-18 18:50:45 +03:00
|
|
|
|
structure of a system by modelling entities as classes and relationships between
|
2022-01-10 16:31:58 +03:00
|
|
|
|
them:
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
2022-01-11 12:19:33 +03:00
|
|
|
|
```` markdown title="Class diagram"
|
2021-07-18 18:50:45 +03:00
|
|
|
|
``` mermaid
|
|
|
|
|
classDiagram
|
|
|
|
|
Person <|-- Student
|
|
|
|
|
Person <|-- Professor
|
|
|
|
|
Person : +String name
|
|
|
|
|
Person : +String phoneNumber
|
|
|
|
|
Person : +String emailAddress
|
|
|
|
|
Person: +purchaseParkingPass()
|
|
|
|
|
Address "1" <-- "0..1" Person:lives at
|
|
|
|
|
class Student{
|
|
|
|
|
+int studentNumber
|
|
|
|
|
+int averageMark
|
|
|
|
|
+isEligibleToEnrol()
|
|
|
|
|
+getSeminarsTaken()
|
|
|
|
|
}
|
|
|
|
|
class Professor{
|
|
|
|
|
+int salary
|
|
|
|
|
}
|
|
|
|
|
class Address{
|
|
|
|
|
+String street
|
|
|
|
|
+String city
|
|
|
|
|
+String state
|
|
|
|
|
+int postalCode
|
|
|
|
|
+String country
|
|
|
|
|
-validate()
|
|
|
|
|
+outputAsLabel()
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
````
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
<div class="result" markdown>
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
``` mermaid
|
|
|
|
|
classDiagram
|
|
|
|
|
Person <|-- Student
|
|
|
|
|
Person <|-- Professor
|
|
|
|
|
Person : +String name
|
|
|
|
|
Person : +String phoneNumber
|
|
|
|
|
Person : +String emailAddress
|
|
|
|
|
Person: +purchaseParkingPass()
|
|
|
|
|
Address "1" <-- "0..1" Person:lives at
|
|
|
|
|
class Student{
|
|
|
|
|
+int studentNumber
|
|
|
|
|
+int averageMark
|
|
|
|
|
+isEligibleToEnrol()
|
|
|
|
|
+getSeminarsTaken()
|
|
|
|
|
}
|
|
|
|
|
class Professor{
|
|
|
|
|
+int salary
|
|
|
|
|
}
|
|
|
|
|
class Address{
|
|
|
|
|
+String street
|
|
|
|
|
+String city
|
|
|
|
|
+String state
|
|
|
|
|
+int postalCode
|
|
|
|
|
+String country
|
|
|
|
|
-validate()
|
|
|
|
|
+outputAsLabel()
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[Class diagrams]: https://mermaid-js.github.io/mermaid/#/classDiagram
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
### Using entity-relationship diagrams
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
An [entity-relationship diagram] is composed of entity types and specifies
|
2021-07-18 18:50:45 +03:00
|
|
|
|
relationships that exist between entities. It describes inter-related things in
|
2022-01-10 16:31:58 +03:00
|
|
|
|
a specific domain of knowledge:
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
2022-01-11 12:19:33 +03:00
|
|
|
|
```` markdown title="Entity-relationship diagram"
|
2021-07-18 18:50:45 +03:00
|
|
|
|
``` mermaid
|
|
|
|
|
erDiagram
|
|
|
|
|
CUSTOMER ||--o{ ORDER : places
|
|
|
|
|
ORDER ||--|{ LINE-ITEM : contains
|
|
|
|
|
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
|
|
|
|
|
```
|
|
|
|
|
````
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
<div class="result" markdown>
|
2021-07-18 18:50:45 +03:00
|
|
|
|
|
|
|
|
|
``` mermaid
|
|
|
|
|
erDiagram
|
|
|
|
|
CUSTOMER ||--o{ ORDER : places
|
|
|
|
|
ORDER ||--|{ LINE-ITEM : contains
|
|
|
|
|
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-10 16:31:58 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
|
[entity-relationship diagram]: https://mermaid-js.github.io/mermaid/#/entityRelationshipDiagram
|
2022-04-24 13:52:45 +03:00
|
|
|
|
|
|
|
|
|
### Other diagram types
|
|
|
|
|
|
|
|
|
|
Besides the diagram types listed above, [Mermaid.js] provides support for
|
|
|
|
|
[pie charts], [gantt charts], [user journeys], [git graphs] and
|
|
|
|
|
[requirement diagrams], all of which are not officially supported by Material
|
|
|
|
|
for MkDocs. Those diagrams should still work as advertised by [Mermaid.js], but
|
|
|
|
|
we don't consider them a good choice, mostly as they don't work well on mobile.
|
|
|
|
|
|
|
|
|
|
[pie charts]: https://mermaid-js.github.io/mermaid/#/pie
|
|
|
|
|
[gantt charts]: https://mermaid-js.github.io/mermaid/#/gantt
|
|
|
|
|
[user journeys]: https://mermaid-js.github.io/mermaid/#/user-journey
|
|
|
|
|
[git graphs]: https://mermaid-js.github.io/mermaid/#/gitgraph
|
|
|
|
|
[requirement diagrams]: https://mermaid-js.github.io/mermaid/#/requirementDiagram
|