Install
HomeBrew的使用及其安装,请查阅 HomeBrew
cpan(类似npm)是perl的软件包管理器,Mac系统集成了perl无需单独安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| brew install graphviz cpan
sudo cpan Graph:Easy
graph-easy --version
|
rules
节点就是你要输出的某个单词,节点分为单节点和复合节点
- 单节点 [xx]
1 2 3 4 5 6 7
| echo "[ShangHai]" | graph-easy graph-easy <<< "[ShangHai]"
+----------+ | ShangHai | +----------+
|
- 复合节点 [xx | xx | xx]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| graph-easy <<< "[ShangHai | ShenZhen | BeiJing]"
+----------+----------+---------+ | ShangHai | ShenZhen | BeiJing | +----------+----------+---------+
graph-easy <<< "[ShangHai | ShenZhen | BeiJing || China]"
+----------+----------+---------+ | ShangHai | ShenZhen | BeiJing | +----------+----------+---------+ | China | +----------+
|
- 节点内的文本换行和对其
1 2 3 4 5 6 7 8 9 10 11 12
| graph-easy <<< "[ShangHai ShenZhen\n\l Beijing\c LangFang\r QingHai]"
+-------------------+ | ShangHai ShenZhen | | | | Beijing | | LangFang | | QingHai | +-------------------+
|
连接线,设置节点之间使用连接使用什么样式的线条
- 无方向连接线,必须使用两个中划线 (--)
1 2 3 4 5 6
| graph-easy <<< "[ShangHai] -- [China]"
+----------+ +-------+ | ShangHai | --- | China | +----------+ +-------+
|
- 实线方向箭(->)
1 2 3 4 5 6
| graph-easy <<< "[ShangHai] -> [China]"
+----------+ +-------+ | ShangHai | --> | China | +----------+ +-------+
|
- 双向箭(<->)
1 2 3 4 5 6
| graph-easy <<< "[ShangHai] <-> [China]"
+----------+ +-------+ | ShangHai | <--> | China | +----------+ +-------+
|
- 双实线(=>)
- 点线(.>)
- 波浪线(~>)
- 虚线(- >)
- 点虚线(.- >)
- 点点虚线(.- >)
- . - = ~可自由组合
回指
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| graph-easy <<< "[ShangHai] -> [China] -> [ShangHai]"
+----------------+ v | +----------+ +-------+ | ShangHai | --> | China | +----------+ +-------+
graph-easy <<< "[ShangHai] -> [ShangHai]"
+------+ v | +----------+ | ShangHai | +----------+
|
多指
1 2 3 4 5 6 7 8 9 10 11 12
| graph-easy <<< "[ShangHai],[ShenZhen],[BeiJing] -> [China]"
+---------+ +----------+ +----------+ | BeiJing | --> | China | <-- | ShenZhen | +---------+ +----------+ +----------+ ^ | | +----------+ | ShangHai | +----------+
|
css样式设置边框线(其它css基础样式也行,样式必须放置在花括号内)
1 2 3 4 5 6
| [ShangHai] - message -> [China]{border:1px solid red} [ShangHai] - message -> [China]{border:none}
|
群组线框(()小括号扩起来)
1 2 3 4 5 6 7 8 9 10 11
| graph-easy <<< "(group: [TongZhou] -> [BeiJing]) [BeiJing] -> [China]"
+ - - - - - - - - - - - - - - -+ ' group: ' ' ' ' +----------+ +---------+ ' +-------+ ' | TongZhou | --> | BeiJing | ' --> | China | ' +----------+ +---------+ ' +-------+ ' ' + - - - - - - - - - - - - - - -+
|
注释
- 在生成ASCII码的源文件中注释使用#号加空格的方式
- 连接线注解,节点连线之间的说明(- 文字说明 ->)【注释两侧是有空格的,且注释文本是中文的话会乱】
1 2 3 4 5 6 7
| graph-easy <<< "[ShangHai] - message -> [China]" graph-easy <<< "[ShangHai] --> {label: "message"} [China]"
+----------+ message +-------+ | ShangHai | ---------> | China | +----------+ +-------+
|
连接方向
- 通过{flow:down}键值对设置
值有 west | left、east | right、north | up、south | down,可理解为地图的上北下南左西右东
1 2 3 4 5 6 7 8 9 10 11 12
| graph-easy <<< "[ShangHai]{flow:down} - message -> [China]"
+----------+ | ShangHai | +----------+ | | message v +----------+ | China | +----------+
|
output
除了上述示例中直接在终端输出外,Graph:Easy 还支持多格式的文件输出
- --input= 指定源文件
1 2
| graph-easy --input=example.txt graph-easy example.txt
|
- --output= 设置输出文件名及其格式
1 2
| graph-easy example.txt --output=index.html graph-easy example.txt index.html
|
- --xx 输出文件未设置格式时可使用此方法指定文件的格式
1
| graph-easy example.txt index --html
|
更多信息请查阅 Graph:Easy