该文章Github地址:https://github.com/AntonyCheng/typora-notes/tree/master/chapter03-mermaid
在此介绍一下作者开源的SpringBoot项目初始化模板(Github仓库地址:https://github.com/AntonyCheng/spring-boot-init-template & CSDN文章地址:https://blog.csdn.net/AntonyCheng/article/details/136555245),该模板集成了最常见的开发组件,同时基于修改配置文件实现组件的装载,除了这些,模板中还有非常丰富的整合示例,同时单体架构也非常适合SpringBoot框架入门,如果觉得有意义或者有帮助,欢迎Star & Issues & PR!
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()
}
classDiagram
class BankAccount{
+String owner
+Bigdecimal balance
+deposit(amount)
+withdraw(amount)
}
class ClassName,另一种是ClassName <|-- SubClassName,前者是通过关键字class显式定义,后者是通过两类的关系隐式定义:classDiagram
class 1900sharehome
1900ShareHome <|-- Typora
()是否存在来区分属性和函数/方法。那些()被视为函数/方法,而其他被视为属性。classDiagram
class bankaccount{
+String owner
+BigDecimal balance
+deposit(amount)
+withdrawal(amount)
}
classDiagram
class BankAccount
BankAccount : +String owner
BankAccount : +BigDecimal balance
BankAccount : +deposit(amount)
BankAccount : +withdrawal(amount)
返回类型:可以用返回的数据类型来定义:
classDiagram
class BankAccount{
+String owner
+BigDecimal balance
+deposit(amount)int
+withdrawal(amount)bool
}
通用类型:可以用通用类型来进行成员的定义,例如List,用于字段,参数和返回类型,方法是将类型包含在~内,且该方法不支持嵌套:
classDiagram
class Class~Shape~{
int id
List~int~ position
setPoints(List~int~ points)
getPoints() List~int~
}
Class : -List~String~ messages
Class : +setMessages(-List~String~messages)
Class : +getMessages() List~Sring~
可视度:对于一些有特殊可视性的类成员,一般把以下元素放置在成员名字之前:
| 字符 | 意义 |
|---|---|
+ | 公开 |
- | 私人 |
# | 受保护 |
~ | 内部 |
classDiagram
class ClassName{
+Public
-Private
#Protected
~Package/Internal
}
[ClassA][Arrow][ClassB]
| 样式 | 描述 |
|---|---|
| <|– | 实心三角箭头 |
| *– | 菱形箭头 |
| o– | 空心菱形箭头 |
| –> | 向量箭头 |
| – | 实线 |
| …> | 虚线向量箭头 |
| …|> | 虚线三角箭头 |
| … | 虚线 |
classDiagram
classA <|-- classB
classC *-- classD
classE o-- classF
classG <-- classH
classI -- classJ
classK <.. classL
classM <|.. classN
classO .. classP
[ClassA][Arrow][ClassB]:LabelText
classDiagram
classA --|> classB : Inheritance
classC --* classD : Composition
classE --o classF : Aggregation
classG --> classH : Association
classI -- classJ : Link(Solid)
classK ..> classL : Dependency
classM ..|> classN : Realization
classO .. classP : Link(Dashed)
| 样式 | 意义 |
|---|---|
| <|-- | 左实心三角箭头实线 |
| <-- | 左向量箭头实线 |
| --* | 实心菱形箭头实线 |
| --o | 空心菱形箭头实线 |
| --|> | 右实心箭头实线 |
| --> | 右向量箭头实线 |
| 样式 | 意义 |
| <|.. | 左实心三角箭头虚线 |
| <.. | 左向量箭头虚线 |
| ..* | 实心菱形箭头虚线 |
| ..o | 空心菱形箭头虚线 |
| ..|> | 右实心箭头虚线 |
| ..> | 右向量箭头虚线 |
| 基数选项 | 意义 |
|---|---|
| 1 | 只有一个 |
| 0…1 | 零或一 |
| 1…* | 一个或多个 |
| ***** | 许多 |
| n | n个 |
| 0…n | 零到n个 |
| 1…n | 一到n个 |
**中:[ClassA]"Number"[Arrow]"Number"[ClassB]:LabelText
classDiagram
A"1"--|>"n"B
<> 表示一个接口类<> 表示抽象类<> 表示一个服务器<> 表示一个举例类classDiagram
class ClassName
<> ClassName
ClassName : Element!
ClassName : Element!()
这是一个比较复杂的用法,下面来一个简单的:
classDiagram
class ClassName{
<>
element!
element!()
}
%%进行注释,例如下:classDiagram
%% class Classname{
%%red
%%blue()
%%}
class ClassName{
red
blue()
}
classDiagram
class Student{
-idCard:IdCard
+id()
}
class IdCard{
-id : int
-name : string
+id()
}
class Bike{
-id : int
-name : String
+id()
}
Student --o IdCard : comment
Bike --o IdCard : comment
例如下:
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
比较旧的渲染器:
stateDiagram
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
Typora能够兼容两者的渲染id描述:stateDiagram-v2
s1
id:stateDiagram-v2
state "This is a state description" as s2
:来引出id:stateDiagram-v2
s2:This is a state description
-->来作为状态转换的语法,当我们要定义两个状态之间的转换时:stateDiagram-v2
s1-->s2
stateDiagram-v2
s1-->s2:This is a transition
Mermaid里面有两个特殊的状态——开始和结束,我们通常用[*]来表示它们:stateDiagram-v2
[*]-->A
A-->[*]
state关键字,后面跟一个id和{},例如下:stateDiagram-v2
[*]-->A
state A{
[*]-->S1
S1-->S2
S2-->[*]
}
stateDiagram-v2
[*]-->A
state A {
[*]-->B
state B {
[*]-->C
state C {
[*]-->D
state D {
[*]-->E
E-->[*]
}
}
}
}
stateDiagram-v2
[*]-->First
state First {
[*]-->F
F-->[*]
}
First-->Second
state Second {
[*]-->S
S-->[*]
}
First-->Third
state Third {
[*]-->T
T-->[*]
}
Second-->[*]
Third-->[*]
stateDiagram-v2
[*] --> IsPositive
IsPositive --> if_else
if_else --> False: if n<0
if_else --> True: if n>=0
<> <> 在图中指定一个叉:stateDiagram-v2
state fork_state <>
[*] --> fork_state
fork_state --> State2
fork_state --> State3
state join_state <>
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]
stateDiagram-v2
State1: The state with a note
%%第一种方法
note right of State1
Important information! You can write notes.
end note
%%第一种方法
State1 --> State2
%%第二种方法
note left of State2 : This is the note to the left.
%%第二种方法
stateDiagram-v2
[*] --> Active
state Active {
[*] --> A
A --> B : 123
B --> A : 123
--
[*] --> C
C --> D : 456
D --> C : 456
--
[*] --> E
E --> F : 789
F --> E : 789
}
Mermaid里面用%%来进行语句的注释。CUSTOMER实体类型将简称为CUSTOMER实体。但从技术上讲,实体是实体类型的抽象实例,这就是 ER 图所显示的 - 抽象实例,以及它们之间的关系。erDiagram
customer ||--o{ order : places
order ||--|{ line-item : contains
customer }|..|{ delivery-adderss : uses
| 左箭头 | 右箭头 | 意义 |
|---|---|---|
| ` | o` | `o |
| ` | ` | |
}o | o{ | 零个或者多个(无上限) |
| `} | ` | ` |
Mermaid中算是最简单的图了,没有过多的语法,就下面这一个实例就能实现这样一个有趣的图像:journey
title My working day
%% section表示选择要做的事情大体方向,其下是事情的各个细节
section Go to work
%% Doing : number : poeple (number代表心情,5为满分,0为最低分)(poeple代表人物)
Make tea:5:Me
Go upstairs:3:Me
Do work:1:Me,Cat
section Go home
Go downstairs:5:Me
Sit down:5:Me
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section A
A task : a1,2021-01-01,30d
Another task : after a1,20d
section B
B task : 2021-03-21,40d
Another task : 40d
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram functionality to mermaid
excludes weekends
%% (`excludes` accepts specific dates in YYYY-MM-DD format, days of the week ("sunday") or "weekends", but not the word "weekdays".)
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
Functionality added :milestone, 2014-01-25, 0d
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
gantt
apple : a,2021-01-01,30d
banana : crit,b,2021-01-04,4d
cherry : active,c,after a,7d
dog : d,after b,3d
titlesection关键字开始一行并为其命名。(请注意,与整个图表的标题)不同,此名称是必需的。milestone来表示:milestone_name milestone : milestone, m, BeginTime, KeepingTime
T I M E = B e g i n T i m e + K e e p i n g T i m e 2 TIME=\frac{BeginTime+KeepingTime}{2} TIME=2BeginTime+KeepingTime
gantt
dateFormat HH:mm
axisFormat %H:%M
Initial milestone : milestone, m1, 17:49,2min
taska2 : 10min
taska3 : 5min
Final milestone : milestone, m2, 18:14, 2min
dateFormat YYYY-MM-DDMermaid支持的格式如下:| 输入 | 样例 | 描述 |
|---|---|---|
| YYYY | 2021 | 四位数年份 |
| YY | 21 | 两位数年份 |
| Q | 1……4 | 季度 |
| M MM | 1……12 | 月份(数字) |
| MMM MMMM | January……Dec | 月份(英文) |
| D DD | 1……31 | 日(月中) |
| Do | 1st……31st | 日(英文缩写排序) |
| DDD DDDD | 1……365 | 日(年中) |
| X | 1410715640.579 | Unix 时间戳 |
| x | 1410715640579 | Unix ms 时间戳 |
| H HH | 0……23 | 小时(24时制) |
| h hh | 1……12 | 小时(12时制,和a、A搭配使用) |
| a A | am pm | 上、下午 |
| m mm | 0……59 | 分钟 |
| s ss | 0……59 | 秒 |
| S | 0……9 | 分秒 |
| SS | 0……99 | 厘秒 |
| SSS | 0……999 | 毫秒 |
| Z ZZ | +12:00 | 时差 |
axisFormat %Y-%m-%d
Mermaid所支持的格式化输出:%a - 缩写的工作日名称。
%A - 完整的工作日名称。
%b - 缩写的月份名称。
%B - 完整的月份名称。
%c - 日期和时间,如“%a %b %e %H:%M:%S %Y”。
%d - 十进制数 [01,31] 月份的零填充日期。
%e - 十进制数 [1,31] 的月份中以空格填充的日期;相当于 %_d。
%H - 小时(24 小时制),十进制数 [00,23]。
%I - 小时(12 小时制)作为十进制数 [01,12]。
%j - 以十进制数表示的一年中的第几天 [001,366]。
%m - 十进制数的月份 [01,12]。
%M - 十进制数 [00,59] 的分钟。
%L - 十进制数的毫秒数 [000, 999]。
%p - 上午或下午。
%S - 秒为十进制数 [00,61]。
%U - 一年中的周数(星期日作为一周的第一天)作为十进制数 [00,53]。
%w - 工作日为十进制数 [0(Sunday),6]。
%W - 一年中的周数(星期一作为一周的第一天)作为十进制数 [00,53]。
%x - 日期,如“%m/%d/%Y”。
%X - 时间,如“%H:%M:%S”。
%y - 没有世纪的年份,十进制数 [00,99]。
%Y - 以世纪为十进制数的年份。
%Z - 时区偏移量,例如“-0700”。
%% - 文字“%”字符。
pie title pie_title
"A":50
"B":40
"C":10
Mermaid中画一个饼图是非常容易的:关键字以pie开始,随后设置标题title,然后将每个标签Label用引号" "括起来,随后跟上冒号:,最后写上该标签所占比例即可。
pie
titie TitleName
"ElementA":numberA
"ElementB":numberB
···
pie
title Mobile Phone
"Sumsung":18.4
"Apple":13.6
"Xiaomi":9.9
"Vivo":7.4
"OPPO":8.0
"Others":42.6