HOMEUP

Graphviz レコードに関して

ノードの形(shape)にrecordMrecordを指定してやると一つのノードを分割してラベルを描画することができます。

record Mrecord

graphviz shape=record

ソースは↓。

// sample.dot
//
digraph sample {
	label = "A|B|{C|D|{E|F}}|G";
	test [ shape = record, label = "A|B|{C|D|{E|F}}|G" ];
}

分割はlabelの文字列を|で区切って指定します。"{"と"}"で囲まれた部分では分割の方向を変更します。(横で分割している場合には"{"と"}"で囲まれた部分は縦で分割されます}

コードの shape = recordshape = Mrecordに変更すると↓のように角丸長方形で描画されます。

Graphviz レコード shape = Mrecord

レコード内の要素をエッジでつなぐ

graphviz shape=Mrecord

↑のグラフではA、Bの要素にポートを指定してレコード内の要素を継いでいます。

ノードでのポートの指定はラベルの文字列内で<ポート>で指定します。エッジを継ぐときはノード:ポートで指定します。コード↓。

// sample_edge.dot
//
digraph sample_edge {
	node1 [ shape = Mrecord, label = "<a>A|<b>B" ];
	node2 [ shape = Mrecord, label = "<a>A'|C|{D|E|<b>B'}" ];
	node1:a -> node2:a;
	node1:b -> node2:b;
}

HTML形式でのラベルの設定

ノードのラベルの部分をHTMLのTABLEタグで記述することもできます。もちろんポートの設定とかも行えるので複雑なレコード形式のノードを手作業で作成する時は結構分かりやすいです。

FONTタグとかも使用できるので恰好のいい複雑なグラフも作成できますネ。HTMLでのグラフの作成は別のページでもう少し詳しく書こうと思っていますがここではレコード形式のノードのサンプルをあげます。

Graphviz record type node by html

↑のようなグラフになります。

コードは↓。

// record型のノードをHTMLで
// sample_html.dot
digraph sample_html {
	node [ shape = plaintext ];
	n0 [ label = <
	    <table border="0" cellborder="1" cellspacing="0">
	    <tr><td colspan="2">labelにはHTMLも使えます</td></tr>
	    <tr><td>こっちの方が</td><td>分かりやすい人も多いかも</td></tr>
	    <tr><td colspan="2">cellborderとかcellspacingを
	    指定してやらないと普通のテーブルみたいです</td></tr>
	    </table>> ];
	n1 [ label = <
	    <table border="1">
	    <tr><td port="p1">こんな感じです</td>
	    <td>This</td><td>is</td><td>a</td><td>test.</td></tr>
	    <tr><td bgcolor="#eeffff;" colspan="5">^^;</td></tr>
	    </table>> ];
	n0 -> n1:p1;
}

サンプル

graphviz sample

こんなグラフを作るプログラム、ありそうですね。このグラフは手描きです (^^;

コードは↓。

// sample1.dot
//
digraph sample1 {
	label = "'(this is (a test))";
	size = "3.0, 3.0";
	{ rank = same;
		n0 [ shape = record, label = "<car>・|<cdr>・" ];
		n1 [ shape = record, label = "<car>・|<cdr>・" ];
		n2 [ shape = record, label = "<car>・|<cdr>・" ];
		n_nil1 [ shape = plaintext, label = "NIL" ];
	}
	{ rank = same;
		n3 [ shape = record, label = "<car>・|<cdr>・" ];
		n4 [ shape = record, label = "<car>・|<cdr>・" ];
		n_this [ shape = plaintext, label = "THIS" ];
		n_is [ shape = plaintext, label = "IS" ];
		n_nil2 [ shape = plaintext, label = "NIL" ];
	}
	{ rank = same;
		n_a [ shape = plaintext, label = "A" ];
		n_test [ shape = plaintext, label = "TEST" ];
	}
	//
	n0:car -> n_this;
	n1:car -> n_is;
	n3:car -> n_a;
	n4:car -> n_test;
	n4:cdr -> n_nil2;
	n0:cdr -> n1:car;
	n1:cdr -> n2:car;
	n2:car -> n3:car;
	n2:cdr -> n_nil1;
	n3:cdr -> n4:car;
}
HOMEUP