Into a tikzpicture, I'd like to apply different styles to nodes depending on their values. For example, in a list of integers, I'd like to color the node in red or in blue.
This is only a test for a bigger project, but an answer on this should help anyway.
The following code is working:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarerandomlist{nums}{{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}}
\foreach \x in {1,...,10}
{
\pgfmathrandomitem{\choice}{nums}
\ifthenelse{\choice<5}
{
\node[circle, fill=blue!50] at (\x,0) {\choice};
}
{
\node[circle,fill=red!50] at (\x,0) {\choice};
}
}
\end{tikzpicture}
\end{document}
But, what I'd like to be able to do is creating a node style, depending on the value of the node. This way, I could add more cases and only use the \node line once. I tried the simpliest way to achieve that, but it doesn't work:
\begin{tikzpicture}
\pgfmathdeclarerandomlist{nums}{{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}}
\foreach \x in {1,...,10}
{
\pgfmathrandomitem{\choice}{nums}
\def\clr{\ifthenelse{\choice<5}{blue!50}{red!50}}
\node[circle, fill=\clr] at (\x,0) {\choice};
}
\end{tikzpicture}
In fine, What I'd like to have is a series of ifthenelse into a tikzstyle. This didn't work either. Seems that \ifthenelse does not comply with every TikZ structure...
Thanks in advance if you know a way to help me with this.