[英]Groups of nodes with the same attributes in GraphViz file
在GraphViz
的dot
语言中,我想描述一个双模网络。 所以我有两种不同类型的节点。 例如,一个小组可以包含人们如何阅读以及另一个小组可以包含人们正在阅读的书籍。
我想给这两组中的节点赋予不同的外观( shape
, color
等)。 如何在一个语句中指定一组节点的属性。 目的是能够在一个地方更改每组节点的外观,而不是在所有单个节点描述中。
这可以通过属性继承来完成,但我不知道dot
语言是否具有这个概念。
原则上有三种可能性
选项1和2每个节点仅允许一个组,因为创建是单个事件。 选项3允许为每个分配进行不同的分组。
在创建节点之前全局设置默认属性
digraph {
x // node with current defaults
// set default
node [shape=box color=red]
// create with default values
a1, a2
// set default
node [shape=circle color=blue]
// create with default values
b1, b2
y // node with current defaults
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}
在创建节点之前在本地设置默认属性
digraph {
x // node with current defaults
{
// set default
node [shape=box color=red]
// create with default values
a1, a2
}
{
// set default
node [shape=circle color=blue]
// create with default values
b1, b2
}
y // node with current defaults
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}
创建具有显式属性的节点
digraph {
x // node with current defaults
// create with explicit attributes
a1, a2 [shape=box color=red]
// create with explicit attributes
b1, b2 [shape=circle color=blue]
y // node with current defaults
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}
在创建后将属性分配给一组节点
digraph {
x // node with current defaults
// create with default values
a1, a2, b1, b2
// assign shape
a1, a2 [shape=box]
b1, b2 [shape=circle]
// assign color
a1, b2 [color=red]
b1, a2 [color=blue]
y // node with current defaults
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}
可以使用node
关键字对图中的所有节点执行此操作,也可以使用edge
关键字对图中的所有边进行此操作。 这也可以在逐个节点或逐个边缘的基础上完成。
整个图形或子图的示例:
digraph
{
subgraph readers
{
node[shape=box; color=red;]
r1; r2; r3;
}
subgraph books
{
node[shape=circle; color=blue;]
b1; b2; b3;
}
r1->{b1 b2}
r2->{b2 b3}
r3->{b1 b2 b3}
}
这会给你图:
每节点属性的示例:
digraph
{
n1[shape=triangle];
n2[shape=star];
n3[shape=square];
n1->n2->n3
}
会给出图表:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.