很早以前我就了解到了使用typora可以画图这件事,应该说是当我知道typora这个软件时,很大一部分程序上,typora这款软件极大的方便了我记录自己的学习笔记,发博客等,通过picGo,我可以方便快捷的使用github的免费存储空间。同时,我可以更快捷方便的通过hexo来发布我编辑的文章到我的博客。而当我了解到typora画图之后,似乎我又发现了新大陆,借此记录了自己学习typora画图的一些语法以及技巧,使用体验真的很好的画图软件——typora

1.流程图

2.时序图

3.状态图

4.类图

5.甘特图

流程图

语法解释:graph 关键字就是声明一张流程图,TD 表示的是方向,这里的含义是 Top-Down 由上至下。

1
2
3
4
5
6
7
8
9
graph LR;
a["起点!"]==粗线带文字==>b;
b{菱形节点}-->c;
a-.-虚线带文字-.->d((具有圆边的节点));
b---|不带箭头的线|e;
e--带箭头的线-->f;
c>非对称形状]-->e;
d--实现特殊字符-->g["特殊字符:#9829;"];
style a fill:lightblue,stroke:black,stroke-width:4px

子图的语法规范

1
2
3
4
5
6
7
8
9
10
11
12
graph TB
c1-->a2
b1 --> a
subgraph one
a1-->a2
end
subgraph two
b1-->b2
end
subgraph three
c1-->c2
end

样式链接

1
2
3
4
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

1
2
3
4
5
graph TD
B["fa:fa-twitter 和平"]
B-->C[fa:fa-ban 禁止]
B-->D(fa:fa-spinner);
B-->E(A fa:fa-camera-retro 也许?);

时序图

语法解释:->> 代表实线箭头,-->> 则代表虚线。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sequenceDiagram
Alice->>Jhon: 你好啊!
activate Jhon
Jhon-->>+Alice: 你好,最近怎么样!
deactivate Jhon
Alice->>-Jhon: 挺好的,学了Typora画图,你呢?
loop every minute
note over Alice,Jhon:数秒之后~~~
end
par Jhon思考时间
rect rgb(100,215,180)
Jhon-->>Jhon: 心理活动,我要不要也学一学#9829;
end
end

一些比较复杂的时序图:

1
2
3
4
5
6
7
8
9
sequenceDiagram
Alice ->> Bob: Hello Bob, how are you?
Bob-->>John: How about you John?
Bob--x Alice: I am good thanks!
Bob-x John: I am good thanks!
Note right of John: Bob thinks a long<br/>long time, so long<br/>that the text does<br/>not fit on a row.
Note left of Alice: what does he think about?
Bob-->Alice: Checking with John...
Alice->John: Yes... John, how are you?

状态图

语法解释:[*] 表示开始或者结束,如果在箭头右边则表示结束。

1
2
3
4
stateDiagram
[*]--> s1
s1-->s2
s2-->[*]

类图

语法解释:<|-- 表示继承,+ 表示 public- 表示 private,学过 Java 的应该都知道。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()
}

甘特图

甘特图一般用来表示项目的计划排期,目前在工作中经常会用到。

语法也非常简单,从上到下依次是图片标题、日期格式、项目、项目细分的任务。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
gantt
title 工作计划 3.8~3.12
dateFormat YYYY-MM-DD
excludes weekends
section 运控项目
Completed task :done, des1, 2021-03-06,2021-03-09
Active task :active, des2, 2021-03-09, 3d
Future task :crit, des3, after des2, 5d
Future task2 : des4, after des3, 5d
section 站控项目
实现弹出式消息框 :a1, 2021-03-01, 2d
继续下一项目 :after a1, 2d
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

甘特图简单用法:

1
2
3
4
5
gantt
apple :a, 2017-07-20, 30d
banana :crit, b, 2017-07-23, 1d
cherry :active, c, after b a, 1d

关于甘特图的input和output的format

在甘特图中有两个属性一个为dateFormat,用以控制甘特图时间的输入;另一个为axisFormat,用以控制甘特图输出时间的格式,两者均可以根据下边两个表来实现自定义的时间格式。

以下为input的dateFormat:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Input       Example             Description:
YYYY 2014 4 digit year
YY 14 2 digit year
Q 1..4 Quarter of year. Sets month to first month in quarter.
M MM 1..12 Month number
MMM MMMM January..Dec Month name in locale set by moment.locale()
D DD 1..31 Day of month
Do 1st..31st Day of month with ordinal
DDD DDDD 1..365 Day of year
X 1410715640.579 Unix timestamp
x 1410715640579 Unix ms timestamp
H HH 0..23 24 hour time
h hh 1..12 12 hour time used with a A.
a A am pm Post or ante meridiem
m mm 0..59 Minutes
s ss 0..59 Seconds
S 0..9 Tenths of a second
SS 0..99 Hundreds of a second
SSS 0..999 Thousandths of a second
Z ZZ +12:00 Offset from UTC as +-HH:mm, +-HHmm, or Z

Example:

1
dateFormat YYYY-MM-DD

这个是output的axisFormat:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
%a - abbreviated weekday name.
%A - full weekday name.
%b - abbreviated month name.
%B - full month name.
%c - date and time, as "%a %b %e %H:%M:%S %Y".
%d - zero-padded day of the month as a decimal number [01,31].
%e - space-padded day of the month as a decimal number [ 1,31]; equivalent to %_d.
%H - hour (24-hour clock) as a decimal number [00,23].
%I - hour (12-hour clock) as a decimal number [01,12].
%j - day of the year as a decimal number [001,366].
%m - month as a decimal number [01,12].
%M - minute as a decimal number [00,59].
%L - milliseconds as a decimal number [000, 999].
%p - either AM or PM.
%S - second as a decimal number [00,61].
%U - week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
%w - weekday as a decimal number [0(Sunday),6].
%W - week number of the year (Monday as the first day of the week) as a decimal number [00,53].
%x - date, as "%m/%d/%Y".
%X - time, as "%H:%M:%S".
%y - year without century as a decimal number [00,99].
%Y - year with century as a decimal number.
%Z - time zone offset, such as "-0700".
%% - a literal "%" character.

Example:

1
axisFormat  %Y-%m-%d