Overview
+--------------------------------------------+
| v
+------+ +---------+ +---------+ +--------+ +--------+
| Bonn | --> | Ulm | --> | Bautzen | --> | Berlin | --> | Kassel |
+------+ +---------+ +---------+ +--------+ +--------+
| | ^
| | |
| v |
| +---------+ |
+--------> | Koblenz | ----------------------+
+---------+
Graph::Easy 是一個處理圖形DSL的Perl模塊,它有如下功能:
- 提供了一種易懂,可讀性很強(qiáng)的圖形描述語言
- 一種支持 ASCII Art 的基于網(wǎng)格的布局器
- 可以導(dǎo)出為 Graphviz, VCG (Visualizing Compiler Graphs), GDL (Graph Description LAnguages) 和 GraphML 格式。
- 可以從 Graphviz, VCG 和 GDL 導(dǎo)入圖像。
Document
http://bloodgate.com/perl/graph/manual/index.html
Install
brew install graphvizcpansudo cpan Graph:Easy
環(huán)境變量
vim ~/.bash_profile
GRAPH_EASY=/Users/***/.cpan/build/Graph-Easy-0.76-1_zAcK/blib/script
PATH=$GRAPH_EASY:$PATH:.
export PATH
source ~/.bash_profile
中文格式問題解決
- 編輯Node.pm和Easy.pm文件
diff --git a/lib/Graph/Easy.pm b/lib/Graph/Easy.pm
index 0ae40fd..b67bacc 100644
--- a/lib/Graph/Easy.pm
+++ b/lib/Graph/Easy.pm
@@ -1570,7 +1570,9 @@ sub as_ascii
# select 'ascii' characters
$self->{_ascii_style} = 0;
- $self->_as_ascii(@_);
+ my $asc = $self->_as_ascii(@_);
+ $asc =~ s/(\x{FFFF})//g;
+ $asc;
}
sub _as_ascii
diff --git a/lib/Graph/Easy/Node.pm b/lib/Graph/Easy/Node.pm
index b58f538..6d7d7c7 100644
--- a/lib/Graph/Easy/Node.pm
+++ b/lib/Graph/Easy/Node.pm
@@ -1503,6 +1503,9 @@ sub label
$label = $self->_un_escape($label) if !$_[0] && $label =~ /\\[EGHNT]/;
+ # placeholder for han chars
+ $label =~ s/([\x{4E00}-\x{9FFF}])/$1\x{FFFF}/g;
+
$label;
}
- 編譯安裝
cd build/Graph-Easy-0.76-1_zAcK- 運(yùn)行
perl Makefile.PL來創(chuàng)建make文件,同時執(zhí)行make test來運(yùn)行測試套件。 - 如果所有的測試都PASS通過了,以超管理員權(quán)限執(zhí)行編譯:
sudo make install
Demo
- 分支
graph-easy <<< '[a]->[b]->[c][b]->[d]->[e]'
+---+ +---+ +---+ +---+
| a | --> | b | --> | d | --> | e |
+---+ +---+ +---+ +---+
|
|
v
+---+
| c |
+---+
- 閉環(huán)
graph-easy <<< '[a]->[b]->[c]->[b]->[d]->[e]'
+--------------+
| v
| +---+ +---+ +---+ +---+
| | a | --> | b | --> | d | --> | e |
| +---+ +---+ +---+ +---+
| |
| |
| v
| +---+
+----------- | c |
+---+
- 合流
graph-easy <<< '[a]->[b]->[c][d]->[e]->[b]'
+---+ +---+ +---+
| a | --> | b | --> | c |
+---+ +---+ +---+
^
|
|
+---+ +---+
| d | --> | e |
+---+ +---+
- 流程說明
graph-easy <<< '[a]- say hello ->[b]'
+---+ say hello +---+
| a | -----------> | b |
+---+ +---+
- 上下結(jié)構(gòu)
graph-easy <<< 'graph{flow:south;}[上]->[中]->[下]'
+---+
| 上 |
+---+
|
|
v
+---+
| 中 |
+---+
|
|
v
+---+
| 下 |
+---+
- 讀取文本
首先,編輯文本 vim graph-easy.text
[Instapaper] {size: 2,7;}
[RSS(Feedly)] -> [Instapaper]{ origin: RSS(Feedly); offset: 2,0;}
[WeChat] -> [Instapaper]{ origin: WeChat; offset: 2,-6;}
[Website] -> [Instapaper]
[IFTTT]{size: 1,7;}
[Instapaper] -> [Diigo]{ origin: Instapaper; offset: 2,-2;}
[Instapaper] -> [IFTTT]{ origin: Instapaper; offset: 2,0;}
[Instapaper] -> [Evernote]{ origin: Instapaper; offset: 2,2;}
[Webtask(Serverless)]{size: 2,7;}
[IFTTT] -> [Webtask(Serverless)]{ origin: IFTTT; offset: 2,0;}
然后,執(zhí)行此文件 graph-easy graph-easy.text
+----------+
+-----> | Diigo |
| +----------+
|
|
|
+-------------+ +--------------+ +----------+ +---------------------+
| RSS(Feedly) | --> | | --> | | --> | |
+-------------+ | Instapaper | | IFTTT | | Webtask(Serverless) |
+-------------+ | | | | | |
| WeChat | --> | | | | | |
+-------------+ +--------------+ +----------+ +---------------------+
^ |
| |
| |
+---------+ | +----------+
| Website | +-----> | Evernote |
+---------+ +----------+
邊的風(fēng)格
-> 實(shí)線
=> 雙實(shí)線
.> 點(diǎn)線
~> 波浪線
- > 虛線
.-> 點(diǎn)虛線
..-> dot-dot-dash
= > double-dash
e.g. graph-easy <<< '[hello].>[world]'
+-------+ +-------+
| hello | ..> | world |
+-------+ +-------+