In principal there are three possibilities
- set default attributes before creating a node
- globally - valid for all following node creations
- locally in a subgraph - valid for node creations within subgraph only
- create nodes with explicit attributes
- assign attributes to a group of nodes after creation.
Options 1 and 2 allow only one group per node as creation is a single event. Option 3 allows different grouping for each assignment.
set default attributes globally before creating a node
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
}
set default attributes locally before creating a node
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
}
create nodes with explicit attributes
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
}
assign attributes to a group of nodes after creation
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
}