GraphViz DOT有向图 (三)node节点丰富内容

节点分类

节点的形状可以是以下任意一种:

  • Record-based Nodes 记录节点
  • Polygon-based Nodes 图形节点
  • User-defined Nodes 用户自定义节点

GraphViz支持html,node节点label内容可以是HTML标签

Record-based Nodes 记录节点

node record点节定义

无需定义, 直接使用,即可生成节点

digraph g {
    node [shape = record,height=.1];
    "node0" -> "node4";
    "node0" -> "node1";
    "node1" -> "node2";
    "node1" -> "node3";
    "node4" -> "node6";
    "node4" -> "node5";
}

也可以显式的定义节点

digraph g {
    node [shape = record,height=.1];
    node0;
    node1;
    node2;
    node3;
    node4;
    node5;
    node6;

    "node0" -> "node4";
    "node0" -> "node1";
    "node1" -> "node2";
    "node1" -> "node3";
    "node4" -> "node6";
    "node4" -> "node5";
}

在这里插入图片描述

node使用label属性

node label属性自定义node显示的内容

digraph g {
    node [shape = record,height=.1];
    node0 [label="node0 第一个开始节点"];
    node1;
    node2;
    node3;
    node4;
    node5;
    node6;

    "node0" -> "node4";
    "node0" -> "node1";
    "node1" -> "node2";
    "node1" -> "node3";
    "node4" -> "node6";
    "node4" -> "node5";
}

在这里插入图片描述

使用"\n", “\l” and "\r"分割内容为多行

  • \n换行居中对齐
  • \l 靠左对齐
  • \r 靠右对齐
digraph g {
    node [shape = record,height=.1];
    node0 [label="node0 \n第一个开始节点\l节点说明\r是这样子\l对齐的是吧\l靠对齐"];
    node1[label="第一行说明\n第二行\l"];
    node2[label="第一行说明\n第二行\r"];
    node3[label="第一行说明\n第二行\n"];
    node4[label="第一行说明\n第二行"]
    node5;
    node6;

    "node0" -> "node4";
    "node0" -> "node1";
    "node1" -> "node2";
    "node1" -> "node3";
    "node4" -> "node6";
    "node4" -> "node5";
}

在这里插入图片描述

node节点包含数据并且定义PORT

使用 <x> | 分割节点,展示多列内容

digraph g {
    node [shape = record,height=.1];
    node0[label = "G\n开始节点"];
    node1[label = "<f1> E|<f2> "];
    node2[label = "<f0> |<f1> B|<f2> "];
    node3[label = "<f1> F "];
    node4[label = "<f0> |<f1> R|<f2> "];
    node5[label = "<f0> |<f1> H|<f2> "];
    node6[label = "<f0> |<f1> Y|<f2> y2 | <f3> y3 | <f4> y4 "];

    "node0" -> "node4":f1;
    "node0" -> "node1":f1;
    "node1":f1 -> "node2":f1;
    "node1":f2 -> "node3":f1;
    "node4":f2 -> "node6":f3;
    "node4":f0 -> "node5":f1;
}

在这里插入图片描述

分割多行或多列

node shape值为 record 或者Mrecord 时, 节点就是记录节点,其内容由label定义。

  • record 正方型
  • Mrecord 圆角正方型

rankdir值不同时,分割行或者列相互转换,自已体会
在这里插入图片描述

// 用 | 分割多列
// 用 <x> 标记行的port值,箭头可指向其准确位置 
// 用{ | } 分割多行
digraph g{

    a1[shape="record" label="a|b|c|d"];
	a2[shape="Mrecord" label="a|b|c|d"];
	b1[shape="record" label="{a|b|c|d}"];
	b2[shape="Mrecord" label="{<f1> a|<f2> b|<f3> c| <f4>d}"];
	c[shape="Mrecord" label="<f1> c1|<f2> c2|<f3> c3| <f4>c4"]

	a1->a2;
	b1->b2:f3
	c:f2->a2;
}

嵌套用法

{} | 嵌套使用,行包含列,列包含行
在这里插入图片描述

// {} | 嵌套使用,行包含列,列包含行
digraph g{
	c[shape="Mrecord" label="<f1> c1|<f2> c2|<f3> c3| <f4>c4"]
	d[shape="record" label="{<fa1> aa |<fa2> bb}|<f2> c2"];
	e[shape="record" label="{ {<w1> aa1 |<w2> aaaa2} |<fa2> bb|<f2> c2}"];
	c:f2->d:fa2;
	c:f3->e:w2;
}

起名规范,用struct前缀,代表节点是数据结构体

digraph g{
	struct_c[shape="Mrecord" label="<f1> c1|<f2> c2|<f3> c3| <f4>c4"]
	struct_d[shape="record" label="{<fa1> aa |<fa2> bb}|<f2> c2"];
	struct_e[shape="record" label="{ {<w1> aa1 |<w2> aaaa2} |<fa2> bb|<f2> c2}"];
	struct_c:f2->struct_d:fa2;
	struct_c:f3->struct_e:w2;
}

node节点使用html标签

  • label<{html}> html table做为node节点内容
digraph g {
    node [shape = record,height=.1];
    node0[label=<
    <TABLE>
    <tr><td>a</td></tr>
    <tr><td>b</td></tr>
    <tr><td>c</td></tr>
    </TABLE>>];
    node1[label = "<f1> E|<f2> "];
    node2[label = "<f0> |<f1> B|<f2> "];
    node3[label = <
  <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR><TD ROWSPAN="3"><FONT COLOR="red">hello</FONT><BR/>world</TD>
  <TD COLSPAN="3">b</TD>
  <TD ROWSPAN="3" BGCOLOR="lightgrey">g</TD>
  <TD ROWSPAN="3">h</TD>
  </TR>
  <TR><TD>c</TD>
  <TD PORT="here">d</TD>
  <TD>e</TD>
  </TR>
  <TR><TD COLSPAN="3">f</TD>
  </TR>
  </TABLE>>];
    node4[label = "<f0> |<f1> R|<f2> "];
    node5[label = "<f0> |<f1> H|<f2> "];
    node6[label = "<f0> |<f1> Y|<f2> y2 | <f3> y3 | <f4> y4 "];

    "node0" -> "node4":f1;
    "node0" -> "node1":f1;
    "node1":f1 -> "node2":f1;
    "node1":f2 -> "node3";
    "node4":f2 -> "node6":f3;
    "node4":f0 -> "node5":f1;
}

在这里插入图片描述

html节点定义PORT

节点label属性的内容可以是html,通常情况是一个tabel,可以指定其属性样式等html所支持的标签。

digraph { 
    d[label=<<table><tr><td PORT="f2">11</td><td>22</td></tr><tr><td>33</td><td PORT="l3">44</td></tr></table>>];

    c->d:f2;
    e->d:l3;
}

在这里插入图片描述

node节点使用图片

待补充

Polygon-based Nodes 图形节点样式表

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

User-defined Nodes 用户自定义节点

使用PostScript自定义节点的形状,有兴趣的同学可以参考官方文档说和案例

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值