4

I have been tearing out my hair with this one all afternoon and was hoping someone could help me. Essentially the problem I have is that I'm using a DTLforeach loop to iterate over values in a .csv file and put them into a table. One of the things I want to see in this table is a series of shapes that change colour based on the text that occurs in the .csv file.

However so far every time I've tried to do this it only seems to run the colour test once and so all of the shapes end up being the same colour rather than different colours dependant on the text. So my question comes down to is what I'm trying to do possible and if so how would you go about doing it?

Hope this is all relevant and sorry if this is a duplicate but I searched and couldn't find a question similar to mine. Also sorry if this code is awful, I'm fairly inexperienced with LaTeX so if there's a really easy way to do this I'm open to suggestions.

The data looks like this as a .csv file and is provided by a command added at compile time so that the .csv file can be dynamically generated from a database:

{"jobRefId","CISKeywords","problemLocation","jobProgress"
 "2","Broken, Other","Gate Green  NA Ticket Office","Issue Reported"
 "4","Blocked, Broken, Flooded","Village Purple Purple 4 Toilet (Disabled)","Issue Reported"
 "6","Shower, Blocked, Too Hot","Venue Children/Youth Stepping Stones Shower","Issue Reported"}

Code:

\documentclass{beamer}     
\usepackage{tikz}
\usepackage{xifthen}
\usepackage{longtable}
\usetikzlibrary{shapes}
\usepackage{xcolor}
\usepackage{tabu}

\definecolor{mellowyellow}{RGB}{255,255,199}
\definecolor{darkred}{RGB}{150,0,0}
\definecolor{darkyellow}{RGB}{255,178,0}
\definecolor{darkgreen}{RGB}{0,65,0}
\setbeamercolor{background canvas}{bg=mellowyellow}

\tikzset{

image/.cd,
1/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkred, fill = darkred},
2/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkyellow, fill = darkyellow},
3/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkgreen, fill = darkgreen},
test/.code={
    \ifthenelse{\isin{#1}{Issue Reported}}{\tikzset{image/1}}{
    \ifthenelse{\isin{#1}{Ticket Printed Job In Progress Job Escalated}}{\tikzset{image/2}}{
    \ifthenelse{\isin{#1}{Job Complete}}{\tikzset{image/3}}{
    }}}
},
}

\newcommand{\jobindicator}[5]{
\node (#1) [xshift=#2cm,yshift=#3cm]  [image/test=#4] {\color{mellowyellow}{#5}};
}

\begin{frame}[allowframebreaks, noframenumbering]
\transduration{5}

 \frametitle{\huge{\\[-8pt] Ongoing Jobs Around Site}}
{\tabulinesep=1mm\begin{longtabu}to\linewidth{|X[c,m]|X[c,m]|X[c,m]|}
 \firsthline
 \bfseries{Where?} & \bfseries{What?} & \bfseries{\vspace{4mm} Job Ref \& Status} % 

 \DTLforeach{CIS}{%
 \ciskeywords=CISKeywords, \problemlocation=problemLocation, \jobrefid=jobRefId, \jobprogress=jobProgress}
   {%
  \\ \hline
  \problemlocation & \ciskeywords &  \expandafter{\begin{tikzpicture}\jobindicator{ell1}{0}{0}{\expandafter{\jobprogress}}{\jobrefid} \end{tikzpicture}}
  }
 \\ \lasthline
  \end{longtabu}}

 \end{frame}
 \end{document}
2
  • 1
    Hi Jonathan, welcome to the site! Could you turn your code sample into a complete minimal document, starting from \documentclass and including some sample data?
    – Jake
    Jul 27 '13 at 19:24
  • Have updated it now, hope it now makes more sense, you'll have to pardon my ignorance :) Jul 27 '13 at 19:39
3

Here's a solution:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{xifthen}
\usepackage{longtable}
\usetikzlibrary{shapes}
\usepackage{xcolor}
\usepackage{tabu}
\usepackage{datatool}

\begin{filecontents*}{test.csv}
"jobRefId","CISKeywords","problemLocation","jobProgress"
"2","Broken, Other","Gate Green  NA Ticket Office","Issue Reported"
"4","Blocked, Broken, Flooded","Village Purple Purple 4 Toilet (Disabled)","In Progress"
"6","Shower, Blocked, Too Hot","Venue Children/Youth Stepping Stones Shower","Job Complete"
\end{filecontents*}

\DTLloaddb{CIS}{test.csv}

\definecolor{mellowyellow}{RGB}{255,255,199}
\definecolor{darkred}{RGB}{150,0,0}
\definecolor{darkyellow}{RGB}{255,178,0}
\definecolor{darkgreen}{RGB}{0,65,0}
\setbeamercolor{background canvas}{bg=mellowyellow}

\tikzset{
image/.cd,
1/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkred, fill = darkred},
2/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkyellow, fill = darkyellow},
3/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkgreen, fill = darkgreen},
test/.code={
    \ifthenelse{\expandafter\isin\expandafter{#1}{Issue Reported}}{\tikzset{image/1}}{
    \ifthenelse{\expandafter\isin\expandafter{#1}{Ticket Printed Job In Progress Job Escalated}}{\tikzset{image/2}}{
    \ifthenelse{\expandafter\isin\expandafter{#1}{Job Complete}}{\tikzset{image/3}}{
    }}}
},
}

\newcommand{\jobindicator}[5]{
\node (#1) [xshift=#2cm,yshift=#3cm]  [image/test=#4] {\color{mellowyellow}{#5}};
}

\begin{document}

\begin{frame}[allowframebreaks, noframenumbering]
\transduration{5}

 \frametitle{\huge{\\[-8pt] Ongoing Jobs Around Site}}

{\tabulinesep=1mm\begin{longtabu}to\linewidth{|X[c,m]|X[c,m]|X[c,m]|}
 \firsthline
 \bfseries{Where?} & \bfseries{What?} & \bfseries\vspace{4mm} Job Ref \& Status % 
 \DTLforeach{CIS}{%
 \ciskeywords=CISKeywords, \problemlocation=problemLocation, \jobrefid=jobRefId, \jobprogress=jobProgress}
   {%
     \\ \hline
     \problemlocation & \ciskeywords &  
    \begin{tikzpicture}
     \jobindicator{ell1}{0}{0}{\jobprogress}{\jobrefid}%
    \end{tikzpicture}
  }
  \\\lasthline
\end{longtabu}}

\end{frame}
 \end{document}

This produces:

Image of resulting page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.