2
votes

I'm using graphviz/dot to generate a graph.

I want to group nodes and/or edges in the graph into semantic classes, with each class having a set of node and/or edge properties that cascade or inherit similar to CSS. However, if I group a single node into multiple classes, the later attribute declaration will override the earlier attribute declaration, even if that attribute was not specified in the later declaration. In particular, it reverts the value to the default/higher-scoped value.

For example:

node [shape="hexagon", style="filled", fillcolor="lightskyblue1"];
{ node [shape="box"]; a; b; }
{ node [fillcolor="red"]; b; c; }

What I want:

a [shape="box", style="filled", fillcolor="lightskyblue1"];
b [shape="box", style="filled", fillcolor="red"];
c [shape="hexagon", style="filled", fillcolor="red"];

What I get:

a [shape="box", style="filled", fillcolor="lightskyblue1"];
b [shape="hexagon", style="filled", fillcolor="red"];
c [shape="hexagon", style="filled", fillcolor="red"];

Is this possible?

1

1 Answers

0
votes

Different result here.

a [shape="box", style="filled", fillcolor="lightskyblue1"];
b [shape="box", style="filled", fillcolor="lightskyblue1"];
c [shape="hexagon", style="filled", fillcolor="red"];

This looks correct for me. Objects inherit the default attributes on definition (=first occurrence). b is defined on the line with [shape="box"]. There fillcolor="lightskyblue1" is in effect from outer scope.

from http://www.graphviz.org/content/dot-language (highlighting by me):

If a default attribute is defined using a node, edge, or graph statement, or by an attribute assignment not attached to a node or edge, any object of the appropriate type defined afterwards will inherit this attribute value.

graphviz version 2.38.0