9

I want to draw a Gantt diagram using pgfgantt. With the default settings, it draws the bars first and the arrows/links second. Thereby, the bars are crossed by the arrows which I find utterly ugly. Is it possible to change this behaviour, e.g., to define the z-order of drawing ?

enter image description here

Minimal working example:

\documentclass{article}
\usepackage{pgfgantt}

\begin{document}
\begin{tikzpicture}
\begin{ganttchart}[bar/.append style={orange}, link/.append style={thick}]{1}{6}
  \ganttbar{Task 1}{1}{2} \\
  \ganttbar{Task 2}{3}{4} \\
  \ganttbar{Task 3}{5}{6}
  \ganttlink[link type=f-s]{elem0}{elem1}
  \ganttlink{elem0}{elem2}
\end{ganttchart}
\end{tikzpicture}
\end{document}

The example works with pgfgantt.sty version 4.0.

Moriambar
  • 11,466
Erwin411
  • 193
  • 2
  • 5
  • You can with the backgrounds library and the option on background layer or simply with PGF layers (without a library available). Problem is though that the whole chart is filled in white. You will need more than two layer (background and main) or disable that filling somehow. – Qrrbrbirlbel Aug 26 '13 at 13:19
  • Thanks for pointing on PGF layers. My issue appears to be related to this question. – Erwin411 Aug 26 '13 at 13:37
  • If it draws under the tasks the meaning of the link changes (Task1 is involved in Task2 to be able to finish and both lead to Task 3) so it is actually a good thing. – percusse Aug 26 '13 at 13:53

1 Answers1

11

Setting the canvas to fill=none, one can simply use the backgrounds library and the on background layer key to draw the arrow behind “Task 2”. I also set the outer xsep to zero so that the f-s line is perfectly straight.

To avoid ambiguity about that arrow corssing under “Task 2” I would draw the arrow around as in Example Y below. (One could also think of keys that only add to already established link bulge value.)

Code X

\documentclass[tikz,convert=false]{standalone}
\usepackage{pgfgantt}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{ganttchart}[
  /pgf/outer xsep=+0pt,
  bar/.append style={orange},
  canvas/.append style={fill=none},
  link/.append style={thick}]{1}{6}
  \ganttbar{Task 1}{1}{2} \\
  \ganttbar{Task 2}{3}{4} \\
  \ganttbar{Task 3}{5}{6}
  \ganttlink[link type=f-s]{elem0}{elem1}
  \begin{scope}[on background layer]
    \ganttlink{elem0}{elem2}
  \end{scope}
\end{ganttchart}
\end{document}

Output X

enter image description here

Code Y

\documentclass[tikz,convert]{standalone}
\usepackage{pgfgantt}
\newganttlinktype{rdldr*}{%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
      \yUpper) --
    ($(\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
      \yUpper)!%
      \ganttvalueof{link mid}!%
      (\xLeft + \ganttvalueof{link bulge 1} * \ganttvalueof{x unit},
      \yLower)$) --
    ($(\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
      \yUpper)!%
      \ganttvalueof{link mid}!%
      (\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
      \yLower)$) --
    (\xRight - \ganttvalueof{link bulge 2} * \ganttvalueof{x unit},
      \yLower) --
    (\xRight, \yLower);%
}
\ganttset{
  link bulge 1/.link=/pgfgantt/link bulge,
  link bulge 2/.link=/pgfgantt/link bulge}
\begin{document}
\begin{ganttchart}[
  bar/.append style={orange},
  link/.append style={thick},
  link bulge=.5]{1}{6}
  \ganttbar{Task 1}{1}{2} \\
  \ganttbar{Task 2}{3}{4} \\
  \ganttbar{Task 3}{5}{6}
  \ganttlink{elem0}{elem1}
  \ganttlink[link type=rdldr*, link bulge 1=2.5, link mid=.75]{elem0}{elem2}
\end{ganttchart}
\begin{ganttchart}[
  bar/.append style={orange},
  link/.append style={thick},
  link bulge=.5]{1}{6}
  \ganttbar{Task 1}{1}{2} \\
  \ganttbar{Task 2}{3}{4} \\
  \ganttbar{Task 3}{5}{6}
  \ganttlink{elem0}{elem1}
  \ganttlink[link type=rdldr*, link bulge 2=2.5, link mid=.25]{elem0}{elem2}
\end{ganttchart}
\end{document}

Output Y

enter image description hereenter image description here

Moriambar
  • 11,466
Qrrbrbirlbel
  • 119,821