2

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.

user2343521
  • 137
  • 1
  • 8
  • I am not familiar with graphviz, so I have no idea whether this can be done... a quick googling didn't turn in anything for an export from graphviz to EMF (the underlying modeling technology used by EMF Compare). EMF Compare will allow you to compare EMF models : you need a way to represent your graphviz graphics into such a model before comparing them. – Kellindil May 21 '13 at 08:48
  • Yes Kellindil, that's another problem. I couldn't find how to create a model from graphviz and use it with EMF models. That's why I decided to write this question, because I don't have any another idea about how to face this. But thanks anyway. – user2343521 May 21 '13 at 18:11

1 Answers1

3

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.

Simon
  • 10,679
  • 1
  • 30
  • 44
  • Man thanks a lot for your trick, actually may be usefull for what I'm doing. – user2343521 Jun 13 '13 at 16:46
  • 1
    Since I answered your question, I've been thinking about how to show the differences graphically and I think it should be possible by displaying a merged graph and shading or otherwise annotating each node differently, depending on whether it is common to both graphs, only in graph 1 or only in graph 2. If you'd be interested in this graphical solution, I could explore it. Roughly, I'd start by taking the approach I took in my answer, create a merged graph, then use the `diff` as input to a script that adds different node attributes for the nodes that differ between the original graphs. – Simon Jun 13 '13 at 23:25
  • 1
    @Simon did you ever build the visual compare mode you talk about here? – Techdragon Aug 23 '14 at 12:30