I have a huge graph with atleast 100 nodes tightly connected in graphviz. I am looking for ways that can automate the edge colors coming out of any given node such that the colors are unique. I have close to 30 edges coming out of each node. Thank you !!
I had a similar problem, where I had loads of nodes coming out of 1 node.
I used sfdp (dot couldn't handle the number of nodes) with the -Goverlap=prism option, which spaced things out nicely.
You have here a list of all colors accepted by GraphViz: http://www.graphviz.org/doc/info/colors.html
If you generate a graph from a program of your own, a simple way to have unique colors is to put all those colors in a list, and to pick one from this list when you have a new edge. Something like this pseudo-code:
List colors = {red, blue, green, ...};
for edge in edges:
write(edge.source +
" -> " +
edge.sink +
" [color=\"" +
color.next() +
"\"];\n"
);
A cleaner way to do so would be to define a color from its RGB code. You can do this this way:
digraph G
{
A -> B
[
color="#AABBCC"
]
}
Now all you have to do is to generate for all your edges a hexadecimal number between #000000 and #FFFFFF. Color formats are presented here in the documentation: http://www.graphviz.org/doc/info/attrs.html#k:color
Do you need something that takes a dot file and produces a new colorized dot file? Or do you have some program or script that is generating your dot file? (In what language?)
I am a fan of picking random medium intensity colors for nodes (or clusters), and making the node background a lighter version of that color and making the exiting edges a darker version of that color.
For example, in java I have two utility methods like these.
public static Color hashColor(Object value) {
if (value == null) {
return Color.WHITE.darker();
} else {
int r = 0xff - (Math.abs(1 + value.hashCode()) % 0xce);
int g = 0xff - (Math.abs(1 + value.hashCode()) % 0xdd);
int b = 0xff - (Math.abs(1 + value.hashCode()) % 0xec);
return new Color(r, g, b);
}
}
/**
* @return a hex Color string in the format #rrggbb.
*/
public static String encodeColor(Color color) {
return "#" + String.format("%06x", color.getRGB() & 0xffffff);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With