Global subgraph style statements

Hello! I have quite a few graphs with a lot of subgraphs. To style these I use a global style for subgraphs as seen in the example below (simplified).
digraph g
graph [rankdir=LR];
subgraph [style="rounded, filled", color=red, fillcolor=khaki, fontsize=10];
node [shape=box, style="rounded,filled", color=red, fillcolor=khaki, fontsize=8];

subgraph cluster0
1 [label="First"];
2 [label="Second"];

1 -> 2;
I've tried with both 2.30 (stable) and 2.31.20130325 (snapshot) but both are throwing a syntax error on the subgraph styling, I guess this has to do with the new stricter parser. This has been working just fine with previous graphviz versions. Is this a bug in the new parser or has it intentionally been deprecated? If deprecated, is there another way to do this without bloating up the .dot file with style statements for every subgraph?

Okay, I was wrong about the

Okay, I was wrong about the old parser accepting 0[4], but I can find no evidence that a parser ever accepted "subgraph [....]". Attribute lists have only been attached to individual nodes or edges, or preceded by "graph", "node" or "edge" for default settings.

That said, if you simply want to create a bunch of subgraphs with the same style, just set a graph style and create the subgraphs:

graph [style="rounded, filled", color=red, fillcolor=khaki, fontsize=10];
subgraph cluster0 [...}
subgraph cluster1 {...}
graph [style="filled", color=green, fillcolor=khaki, fontsize=10];
subgraph cluster2 {...}

Each subgraph will get the graph attributes defined when the subgraph is created.

I tried with graph instead of

I tried with graph instead of subgraph for the styling, and indeed it now produces the same result as previously with subgraph.

Thank you for the reply and hint about graph style usage.

Recent comments