There are basically three possibilities.
- set default attributes before creating node
- globally - valid for all subsequent node creations
- locally in the subgraph - valid for node creation only inside the subgraph
- create nodes with explicit attributes
- Assign attributes to a group of nodes after creation.
Parameters 1 and 2 allow only one group per node, since creation is a single event. Option 3 allows a different grouping for each assignment.
set default attributes globally before creating node
digraph {
x
node [shape=box color=red]
a1, a2
node [shape=circle color=blue]
b1, b2
y
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}

set default attributes locally before creating node
digraph {
x
{
node [shape=box color=red]
a1, a2
}
{
node [shape=circle color=blue]
b1, b2
}
y
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}

create nodes with explicit attributes
digraph {
x
a1, a2 [shape=box color=red]
b1, b2 [shape=circle color=blue]
y
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}

assign attributes to group of nodes after creation
digraph {
x
a1, a2, b1, b2
a1, a2 [shape=box]
b1, b2 [shape=circle]
a1, b2 [color=red]
b1, a2 [color=blue]
y
x->{a1 a2}
a1->{b1 b2}
a2->{b1 b2}
{b1,b2}->y
}

source
share