3

Within the forum I found this nicely designed milestone / timeline graphic: Milestone graphic in TikZ

Regarding this graphic I would like to make two adaptations:

  1. How can I adjust the code in order to set the vertical position of the circle (rectangle)?

  2. How to adjust the code in order to set the horizontal AND vertical size of the rectangle?

My goal is to have multiple bars above the timeline, somewhat like a gantt chart.

Your help is highly appreciated!


\documentclass{standalone}
\usepackage{datatool}
\usepackage{tikz}
\usetikzlibrary{shadows}
\usetikzlibrary{positioning}
%\usetikzlibrary{calc,intersections}

\usepackage{filecontents}
\begin{filecontents*}{tasks.dat}
phase,taskid,name,position,size
initial,initial,Decision to vote shares,2,8
softblocking,softblocking,Soft Blocking,9,8
afterAGM,afterAGM,No blocking,17,8
\end{filecontents*}

\DTLloaddb[noheader=false]{tasks}{tasks.dat}

\begin{document}
\begin{tikzpicture}[week/.style={font=\bfseries, text=white},
initial/.style={fill=yellow,rectangle,opacity=0.5},
softblocking/.style={fill=red!60,rectangle,opacity=0.5},
afterAGM/.style={fill=green,rectangle,opacity=0.5} ]

% Tasks Headers
\DTLforeach*{tasks}{\phase=phase, \taskid=taskid, \name=name, \position=position,\size=size}{\node(\taskid)[\phase, minimum size=\size em] at (\position, 0) {};
\draw (node cs:name=\taskid, anchor=north) to ++(0,1) node[above, scale=\size/6] {\name};
}

% Timeline Bar
\filldraw[fill=black, draw=white,line width=0.5ex,opacity=0.75] (0,-0.5) rectangle (20,0.5);

% Weeks.
\node[week] at (2,0) {Announcement};
\node[week] at (5,0) {TRD -6};
\node[week] at (9,0) {TRD -4};
\node[week] at (13,0) {TRD, AGM -7};
\node[week] at (17,0) {AGM};
\end{tikzpicture}
\end{document}  
  • Vertical position: yshift. Size: minheight, minwidth. RTFM: Tikz manual. – ajeh Dec 10 '14 at 14:05
  • Dear Ajeh, thank you very much for your quick response. I am quite new to Latex & Tikz. How can I implement your code suggestion from the Tikz manual into the code above?

    Do I have to extend the header of the .dat file, e.g. phase,taskid,name,position,minheight,minwidt? Where can I include yshift?

    – ScoobyDoo84 Dec 10 '14 at 14:23
  • @ajeh Also it is not minheight it's minimum height and width similarly. RTFM yourself :) – percusse Dec 10 '14 at 15:04
  • You want something like a Gantt char, do you know pgfgantt? – Ignasi Dec 11 '14 at 07:59
  • Thanks for the recommendation @Ignasi. However, the pgfgantt is somewhat too much. I need the graphic for a beamer presentation and prefer somewhat more colourful, less technical. But thats just a matter of preference :) – ScoobyDoo84 Dec 11 '14 at 09:12

1 Answers1

1

I'm not entirely certain what you want this to look like. Probably not like this, but this is what I get from your description! (Or something more like this? But note that I drew that so it is a bit on the odd side.)

By the way, you should consider using Claudio Fiandrino's timeline library.

variable milestones

\documentclass[tikz,border=5pt]{standalone}
\usepackage{datatool}
\usetikzlibrary{shadows,positioning}

\usepackage{filecontents}
\begin{filecontents*}{tasks.dat}
phase,taskid,name,xposition,yposition,width,height
initial,initial,Decision to vote shares,2,5,8,10
softblocking,softblocking,Soft Blocking,9,0,8,24
afterAGM,afterAGM,No blocking,17,-6,8,2
\end{filecontents*}

\DTLloaddb[noheader=false]{tasks}{tasks.dat}

\begin{document}
\begin{tikzpicture}[week/.style={font=\bfseries, text=white},
initial/.style={fill=yellow,rectangle,opacity=0.5},
softblocking/.style={fill=red!60,rectangle,opacity=0.5},
afterAGM/.style={fill=green,rectangle,opacity=0.5} ]

% Tasks Headers
\DTLforeach*{tasks}{\phase=phase, \taskid=taskid, \name=name, \xposition=xposition, \yposition=yposition, \mywidth=width, \myheight=height}{\node(\taskid)[\phase, minimum width=\mywidth em, minimum height=\myheight mm] at (\xposition, \yposition) {};
\draw (node cs:name=\taskid, anchor=north) to ++(0,1) node[above, scale=\mywidth/6] {\name};
}

% Timeline Bar
\filldraw[fill=black, draw=white,line width=0.5ex,opacity=0.75] (0,-0.5) rectangle (20,0.5);

% Weeks.
\node[week] at (2,0) {Announcement};
\node[week] at (5,0) {TRD -6};
\node[week] at (9,0) {TRD -4};
\node[week] at (13,0) {TRD, AGM -7};
\node[week] at (17,0) {AGM};
\end{tikzpicture}
\end{document}
cfr
  • 198,882
  • Dear cfr, that is exactly what I am looking for. Thank you very much! Using your code I additionally added options for the anchor and text position options in \draw (node cs:name=\taskid, anchor=north) to ++(0,1). Then the timeline can also appear in the middle of the chart. – ScoobyDoo84 Dec 11 '14 at 09:08
  • @ScoobyDoo84 You're welcome. Don't forget to consider accepting the answer if it solves your problem. (Click on the checkmark at top left of the answer.) – cfr Dec 11 '14 at 13:35