Mac使用Graph Easy(純文本流程圖)

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 graphviz
  • cpan
  • sudo 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;
   }
  • 編譯安裝
    1. cd build/Graph-Easy-0.76-1_zAcK
    2. 運(yùn)行perl Makefile.PL來創(chuàng)建make文件,同時執(zhí)行make test來運(yùn)行測試套件。
    3. 如果所有的測試都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 |
+-------+     +-------+
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容