[Tex/LaTex] How to make Beamer overlays with TikZ node attributes

animationsbeameroverlaystikz-pgftikz-styles

As a follow-up question to Tikz animated figure in Beamer, how can I animate a particular attribute of a node?

MWE

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{graphs}

\tikzset{
  node distance = 3 cm,
  graph vertex/.style={
    circle,
    draw,
    minimum size=7.5mm,
  },
  marked/.style={
    color=white,
    fill=black,
  },
}

\begin{document}
\begin{frame}
  \centering
    \begin{tikzpicture}
      \node[graph vertex, marked] (1) at (0 , 3) {$v_1$};
      \node[graph vertex,       ] (2) at (0 , 6) {$v_2$};
      \node[graph vertex,       ] (3) at (3 , 3) {$v_3$};
      \node[graph vertex, marked] (4) at (3 , 6) {$v_4$};
      \node[graph vertex,       ] (5) at (5 , 8) {$v_5$};

      \graph {
        (1) -- (3) -- (4) -- (2) --[bend left] (5),
        (1) -- (2),
        (1) -- (4),
        (3) --[bend right] (5)
      };
  \end{tikzpicture}
\end{frame}

\begin{frame}
  \centering
  \begin{tikzpicture}
      \node[graph vertex, marked] (1) at (0 , 3) {$v_1$};
      \node[graph vertex,       ] (2) at (0 , 6) {$v_2$};
      \node[graph vertex,       ] (3) at (3 , 3) {$v_3$};
      \node[graph vertex, marked] (4) at (3 , 6) {$v_4$};
      \node[graph vertex, marked] (5) at (5 , 8) {$v_5$};

      \graph {
        (1) -- (3) -- (4) -- (2) --[bend left] (5),
        (1) -- (2),
        (1) -- (4),
        (3) --[bend right] (5)
      };
  \end{tikzpicture}
\end{frame}

\begin{frame}
  \centering
  \begin{tikzpicture}
      \node[graph vertex, marked] (1) at (0 , 3) {$v_1$};
      \node[graph vertex,       ] (2) at (0 , 6) {$v_2$};
      \node[graph vertex,       ] (3) at (3 , 3) {$v_3$};
      \node[graph vertex,       ] (4) at (3 , 6) {$v_4$};
      \node[graph vertex, marked] (5) at (5 , 8) {$v_5$};

      \graph {
        (1) -- (3) -- (4) -- (2) --[bend left] (5),
        (1) -- (2),
        (1) -- (4),
        (3) --[bend right] (5)
      };
  \end{tikzpicture}
\end{frame}
\end{document}

I'd like to get this syntax to something like

\begin{frame}
  \centering
    \begin{tikzpicture}
      \node[graph vertex, marked      ] (1) at (0 , 3) {$v_1$};
      \node[graph vertex,             ] (2) at (0 , 6) {$v_2$};
      \node[graph vertex,             ] (3) at (3 , 3) {$v_3$};
      \node[graph vertex, marked=<1-2>] (4) at (3 , 6) {$v_4$};
      \node[graph vertex, marked=<2-3>] (5) at (5 , 8) {$v_5$};

      \graph {
        (1) -- (3) -- (4) -- (2) --[bend left] (5),
        (1) -- (2),
        (1) -- (4),
        (3) --[bend right] (5)
      };
  \end{tikzpicture}
\end{frame}

I'm open to other syntax options as well, as long as it 'more or less' adheres to the above (i.e. doesn't duplicate code, is readable).

Attempt with overlay-beamer-styles

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{overlay-beamer-styles}

\tikzset{
  node distance = 3 cm,
  graph vertex/.style={
    circle,
    draw,
    minimum size=7.5mm,
  },
  marked/.style={
    color=white,
    fill=black,
  },
  marked on/.style={alt=#1{}{marked}},
}

\begin{document}
\begin{frame}
  \centering
    \begin{tikzpicture}
      \node[graph vertex, marked         ] (1) at (0 , 3) {$v_1$};
      \node[graph vertex,                ] (2) at (0 , 6) {$v_2$};
      \node[graph vertex,                ] (3) at (3 , 3) {$v_3$};
      \node[graph vertex, marked on=<1-2>] (4) at (3 , 6) {$v_4$};
      \node[graph vertex, marked on=<2-3>] (5) at (5 , 8) {$v_5$};

      \graph {
        (1) -- (3) -- (4) -- (2) --[bend left] (5),
        (1) -- (2),
        (1) -- (4),
        (3) --[bend right] (5)
      };
  \end{tikzpicture}
\end{frame}
\end{document}

Best Answer

Your code using overlay-beamer-styles will work if you change the code line

  marked on/.style={alt=#1{}{marked}},

to

  marked on/.style={alt=#1{marked}{}},

The code:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{overlay-beamer-styles}

\tikzset{
  node distance = 3 cm,
  graph vertex/.style={
    circle,
    draw,
    minimum size=7.5mm,
  },
  marked/.style={
    color=white,
    fill=black,
  },
  marked on/.style={alt=#1{marked}{}},
}

\makeatletter
\def\c@slideinframe{\beamer@slideinframe}
\makeatother

\begin{document}
\begin{frame}
\frametitle{Test slide \arabic{slideinframe}}
  \centering
    \begin{tikzpicture}
      \node[graph vertex, marked         ] (1) at (0 , 3) {$v_1$};
      \node[graph vertex,                ] (2) at (0 , 6) {$v_2$};
      \node[graph vertex,                ] (3) at (3 , 3) {$v_3$};
      \node[graph vertex, marked on=<1-2>] (4) at (3 , 6) {$v_4$};
      \node[graph vertex, marked on=<2-3>] (5) at (5 , 8) {$v_5$};

      \graph {
        (1) -- (3) -- (4) -- (2) --[bend left] (5),
        (1) -- (2),
        (1) -- (4),
        (3) --[bend right] (5)
      };
  \end{tikzpicture}
\end{frame}
\end{document}

enter image description here