# How can I use overlays in beamer when producing graphs with dot?

I usually describe graphs with graphiz and I enjoy dot2tex which produces the corresponding TikZ code.

To explain an algorithm in a presentation, I need to uncover the nodes and edges of a graph step by step (without changing the layout, of course). I can find some documentation on how to do that when one is writing directly tikz code, for instance Beamer vs. TikZ: uncover nodes step-by-step , but in my case the code is generated automatically from the dot specification. Is it possible to include overlay specification in the dot file?

-

I think that in the dot file you could just include overlay specification for labels. Here is an example of dot file (I call it mygraph.dot):

digraph G {
1 [texlbl="{\visible<1->{1}}"];
2 [texlbl="{\visible<2->{2}}"];
3 [texlbl="{\visible<3->{3}}"];
1->2 [label="1/2"];
2->3 [label="1/2"];
3->1 [label="1/2"];
}


Now with the terminal you can create the correspondent TikZ code:

 dot2tex -ftikz mygraph.dot > mygraph.tex


As you know, mygraph.tex is a complete tex document, thus you just have to copy the code of the picture in your presentation. Notice that this applies just for nodes labels, not edge label.

The best way to proceed is:

• export the dot file in a tex document;
• edit the picture inserting \pause.

Coming back after one year more or less...

Actually, using overlay specification with GraphViz is perfectly doable by means of the famous Daniel's style visible on from Mindmap tikzpicture in beamer (reveal step by step). Since it is a style, it can be included in the dot file by means of the key style and it does the job for vertices and edges; for the labels, it's possible to exploit the construct {\visible<overlay specification>{label}} or, again the visible on style inside the key lblstyle.

An example:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz,dot2texi}
\usetikzlibrary{automata,shapes}

\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
state st/.style={draw,circle,top color=orange!2,bottom color=red!50!orange!50}
}

\begin{document}

\begin{frame}[fragile]{My graph}
\begin{tikzpicture}
\begin{dot2tex}[styleonly,codeonly,circo,options=-s -tmath]
digraph G {
1 [style="state st,visible on=<2->"];
2 [style="state st,visible on=<3->"];
3 [style="state st,visible on=<4->"];
1->2 [label="1/2",style="visible on=<3->",lblstyle="visible on=<3->"];
2->3 [label="1/2",style="visible on=<4->",lblstyle="visible on=<4->"];
3->1 [label="1/2",style="visible on=<5->",lblstyle="visible on=<5->"];
}
\end{dot2tex}
\end{tikzpicture}
\end{frame}

\end{document}


The result:

Assuming the file be called anim-graph.tex, it must be compiled as:

pdflatex -shell-escape anim-graph.tex


since the package dot2texi requires to run dot2tex.

-
It seems your solution allows to uncover the text of a node at will and it is already an improvement over what I knew how to do. Still, the nodes remain visible (the circles do not get disappear). Also, do you know how to change the style/color/shape of a node or an edge dynamically? –  Abdallah Apr 8 '12 at 21:56
Sorry for the delay in answering, but I did several trials in my spare time. The conclusion is that, to my best knowledge, is not possible using just dot to change in time styles colors and shapes. As I said in my answer, this can be done editing the tikzpicture after having generated with dot2tex. –  Claudio Fiandrino Apr 13 '12 at 17:04
Ok, thanks for your answer. –  Abdallah Apr 16 '12 at 23:56
@Halladba: I managed to solve the issue.. finally :) –  Claudio Fiandrino Mar 3 '13 at 19:47