Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same nodes, different colerings in Graphviz

Tags:

graphviz

dot

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?

like image 467
Konrad Reiche Avatar asked Feb 23 '23 03:02

Konrad Reiche


1 Answers

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]).

like image 70
marapet Avatar answered Mar 07 '23 01:03

marapet