Overview
+--------------------------------------------+
| v
+------+ +---------+ +---------+ +--------+ +--------+
| Bonn | --> | Ulm | --> | Bautzen | --> | Berlin | --> | Kassel |
+------+ +---------+ +---------+ +--------+ +--------+
| | ^
| | |
| v |
| +---------+ |
+--------> | Koblenz | ----------------------+
+---------+
Graph::Easy 是一个处理图形DSL的Perl模块,它有如下功能:
- 提供了一种易懂,可读性很强的图形描述语言
- 一种支持 ASCII Art 的基于网格的布局器
- 可以导出为 Graphviz, VCG (Visualizing Compiler Graphs), GDL (Graph Description LAnguages) 和 GraphML 格式。
- 可以从 Graphviz, VCG 和 GDL 导入图像。
Document
http://bloodgate.com/perl/graph/manual/index.html
Install
brew install graphviz
cpan
sudo cpan Graph:Easy
环境变量
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
- 运行
perl Makefile.PL
来创建make文件,同时执行make test
来运行测试套件。 - 如果所有的测试都PASS通过了,以超管理员权限执行编译:
sudo make install
Demo
- 分支
graph-easy <<< '[a]->[b]->[c][b]->[d]->[e]'
+---+ +---+ +---+ +---+
| a | --> | b | --> | d | --> | e |
+---+ +---+ +---+ +---+
|
|
v
+---+
| c |
+---+
- 闭环
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 |
+---+ +---+
- 上下结构
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;}
然后,执行此文件 graph-easy graph-easy.text
+----------+
+-----> | Diigo |
| +----------+
|
|
|
+-------------+ +--------------+ +----------+ +---------------------+
| RSS(Feedly) | --> | | --> | | --> | |
+-------------+ | Instapaper | | IFTTT | | Webtask(Serverless) |
+-------------+ | | | | | |
| WeChat | --> | | | | | |
+-------------+ +--------------+ +----------+ +---------------------+
^ |
| |
| |
+---------+ | +----------+
| Website | +-----> | Evernote |
+---------+ +----------+
边的风格
-> 实线
=> 双实线
.> 点线
~> 波浪线
- > 虚线
.-> 点虚线
..-> dot-dot-dash
= > double-dash
e.g. graph-easy <<< '[hello].>[world]'
+-------+ +-------+
| hello | ..> | world |
+-------+ +-------+