4
votes

I have a simple directed graph in Graphviz with two kinds of nodes and edges. Each kind has it's own color. My problem is, that I would like to keep how the graph is drawn, but just change the colors. However, when I swap the node names within the two node definitions, the graph changes its layout.

node [shape = circle, width = 0.95, fixedsize = true, style = filled, fillcolor = palegreen] 3 "4-5" 7 "8-9" 10 18 19
node [shape = circle, width = 0.95, fixedsize = true, style = filled, fillcolor = grey]  11 12 "13-14"

Is there a way to force it to one static layout?

1

1 Answers

8
votes

The order in which the nodes are defined does have an impact on the layout.

If you want to keep the layout and change only the colors of the nodes, then you'll need to keep the order of (first) appearance of the nodes and only change their fillcolor attribute.

For example:

digraph g {
  node [shape = circle, width = 0.95, fixedsize = true, style = filled, fillcolor = palegreen];
  3;
  "4-5";
  7;
  "8-9";
  10 [fillcolor = grey];
  18;
  19;
  // new default fillcolor
  node [fillcolor = grey];
  11;
  12 [fillcolor = palegreen];
  "13-14";
}

Resulting in

fillcolor nodes

You can specify the default attributes using the node [fillcolor = grey] instruction, and override the default values on a specific node if needed (12 [fillcolor = palegreen]).