I have to do a job with graphviz. I need to visualize the graphic representation of several trees, but in any case I have to compare two tree to see their differences: something like this, I have tree A and tree B. After create their representation and compare them I need to see only the nodes that don't have in common. Someone told me to use EMF Compare but unfortunately I don't know how to make this plugin accept the extension of graphviz.
Any advice or any other possible solution to face this job?
Regards.
Given two .dot
files, a1.dot
:
digraph g1 {
A -> B -> D -> E
A -> C -> E
}
... and a2.dot
:
digraph g2 {
A -> B -> F -> E
A -> C -> F
}
... you can find the nodes that are different between them as follows:
$ dot -Tplain a1.dot | sed -ne 's/^node \([^ ]\+\).*$/\1/p' | sort >a1.nodes
$ dot -Tplain a2.dot | sed -ne 's/^node \([^ ]\+\).*$/\1/p' | sort >a2.nodes
$ diff a1.nodes a2.nodes
4d3
< D
5a5
> F
I'm using sed
to strip the list of node names for each .dot
file out of the plain
output from dot
, sorting the nodes into order and then using diff
to find the differences. This approach doesn't present the differences graphically, but that is a tricky thing to do at the best of times.