Others will probably have more elegant suggestions, but I have three ideas:
- Render Graphviz graphs directly in your posts discusses some options for animation transitions between different graphs that might be of interest to you.
- The Dot input language is designed to be amenable to pre-processing with the C pre-processor, so you could leverage this.
- If you’re open to generating your graph from a scripting language, you could do the colourising there.
To expand on (2), you could have something like the following:
digraph {
A -> B [color=EDGE1];
B -> C [color=EDGE2];
C -> D [color=EDGE3];
}
Then you can generate variations of this with:
$ cpp -DEDGE1=black -DEDGE2=black -DEDGE3=red foo.dot # highlight edge 3
$ cpp -DEDGE1=red -DEDGE2=black -DEDGE3=black # highlight edge 1
To expand on (3), you could instead generate the above graph from Python:
import sys
to_highlight = int(sys.argv[1])
edges = [("A", "B"), ("B", "C"), ("C", "D")]
print("digraph {")
for index, (from_node, to_node) in enumerate(1, edges):
print(f" {from_node} -> {to_node} "
f"[color={'red' if index == to_highlight else 'black'}")
printf("}")
Then to do the equivalent of the two cpp scenarios above would be:
$ python3 my_script.py 3
$ python3 my_script.py 1