%%
%% This is file `pgfgantt.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pgfgantt.dtx  (with options: `pgfgantt')
%% 
%% Copyright (C) 2012 by Wolfgang Skala
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\ProvidesPackage{pgfgantt}[2012/01/25 v3.0 Draw Gantt diagrams with TikZ]
\NeedsTeXFormat{LaTeX2e}[1999/12/01]


\RequirePackage{tikz}
  \usetikzlibrary{arrows,backgrounds,calc,patterns,positioning}

\newcounter{gtt@width}
\newcounter{gtt@currentline}
\newcounter{gtt@lasttitleline}
\newcounter{gtt@lasttitleslot}
\newcounter{gtt@elementid}
\newcounter{gtt@currgrid}
\def\gtt@lastelement{}
\def\gtt@currentelement{}
\newif\ifgtt@intitle

\def\ganttset#1{\pgfqkeys{/pgfgantt}{#1}}

\def\@gtt@keydef#1#2{%
  \pgfkeyssetvalue{/pgfgantt/#1}{#2}%
}
\def\ganttvalueof#1{%
  \pgfkeysvalueof{/pgfgantt/#1}%
}
\def\@gtt@stylekeydef#1#2{%
  \pgfkeys{/pgfgantt/#1/.style={#2}}%
}
\@gtt@stylekeydef{hgrid style}{dotted}
\newif\ifgtt@hgrid
\ganttset{%
  hgrid/.code={%
    \def\@tempa{#1}%
    \def\@tempb{false}%
    \ifx\@tempa\@tempb%
      \gtt@hgridfalse%
    \else%
      \gtt@hgridtrue%
      \def\@tempb{true}%
      \ifx\@tempa\@tempb%
        \def\gtt@hgridstyle{dotted}%
      \else%
        \def\gtt@hgridstyle{#1}%
      \fi%
    \fi%
  },%
  hgrid/.default=dotted
}

\newif\ifgtt@vgrid
\ganttset{%
  vgrid/.code={%
    \def\@tempa{#1}%
    \def\@tempb{false}%
    \ifx\@tempa\@tempb%
      \gtt@vgridfalse%
    \else%
      \gtt@vgridtrue%
      \def\@tempb{true}%
      \ifx\@tempa\@tempb%
        \def\gtt@vgridstyle{dotted}%
      \else%
        \def\gtt@vgridstyle{#1}%
      \fi%
    \fi%
  },%
  vgrid/.default=dotted
}


\@gtt@keydef{x unit}{.5cm}
\@gtt@keydef{y unit title}{1cm}
\@gtt@keydef{y unit chart}{1cm}

\@gtt@stylekeydef{canvas}{fill=white}
\@gtt@keydef{today}{none}
\@gtt@stylekeydef{today rule}{dashed, line width=1pt}
\@gtt@keydef{today label}{TODAY}

\@gtt@stylekeydef{title}{fill=white}
\@gtt@keydef{title label font}{\small}
\@gtt@stylekeydef{title label anchor}{anchor=mid}
\ganttset{%
  title list options/.code={%
    \def\gtt@titlelistoptions{[#1]}%
  },%
  title list options={var=\x, evaluate=\x}%
}
\@gtt@keydef{title left shift}{0}
\@gtt@keydef{title right shift}{0}
\@gtt@keydef{title top shift}{0}
\@gtt@keydef{title height}{.6}

\newif\ifgtt@includetitle
\ganttset{%
  include title in canvas/.is if=gtt@includetitle,%
  include title in canvas
}

\@gtt@keydef{name}{}
\@gtt@keydef{time slot modifier}{-1}
\newif\ifgtt@inline
\ganttset{%
  inline/.is if=gtt@inline,%
  inline=false%
}

\@gtt@stylekeydef{bar}{fill=white}
\ganttset{%
  bar label text/.code={%
    \def\gtt@barlabeltext##1{#1}%
  },%
  bar label text={\strut#1}%
}
\@gtt@keydef{bar label font}{\normalsize}
\@gtt@stylekeydef{bar label anchor}{anchor=east}
\@gtt@stylekeydef{bar label inline anchor}{anchor=center}
\@gtt@keydef{bar label shape anchor}{center}
\@gtt@keydef{bar left shift}{0}
\@gtt@keydef{bar right shift}{0}
\@gtt@keydef{bar top shift}{.3}
\@gtt@keydef{bar height}{.4}

\@gtt@stylekeydef{group}{fill=black}
\ganttset{%
  group label text/.code={%
    \def\gtt@grouplabeltext##1{#1}%
  },%
  group label text={\strut#1}%
}
\@gtt@keydef{group label font}{\normalsize\bfseries}
\@gtt@stylekeydef{group label anchor}{anchor=east}
\@gtt@stylekeydef{group label inline anchor}{anchor=south}
\@gtt@keydef{group label shape anchor}{center}
\@gtt@keydef{group left shift}{-.1}
\@gtt@keydef{group right shift}{.1}
\@gtt@keydef{group top shift}{.4}
\@gtt@keydef{group height}{.2}
\ganttset{%
  group left peak/.code n args={3}{%
    \def\@tempa{#1}%
    \ifx\@tempa\@empty\else\def\gtt@groupleftpeakmidx{#1}\fi%
    \def\@tempa{#2}%
    \ifx\@tempa\@empty\else\def\gtt@groupleftpeakinnerx{#2}\fi%
    \def\@tempa{#3}%
    \ifx\@tempa\@empty\else\def\gtt@groupleftpeaky{#3}\fi%
  },%
  group right peak/.code n args={3}{%
    \def\@tempa{#1}%
    \def\@tempb{-}%
    \ifx\@tempa\@empty\else%
      \ifx\@tempa\@tempb\else\def\gtt@grouprightpeakmidx{#1}\fi%
    \fi%
    \def\@tempa{#2}%
    \ifx\@tempa\@empty\else%
      \ifx\@tempa\@tempb\else\def\gtt@grouprightpeakinnerx{#2}\fi%
    \fi%
    \def\@tempa{#3}%
    \ifx\@tempa\@empty\else\def\gtt@grouprightpeaky{#3}\fi%
  },%
  group peaks/.code n args={3}{%
    \ganttset{%
      group left peak={#1}{#2}{#3},%
      group right peak={-#1}{-#2}{#3}%
    }%
  },%
  group peaks={.2}{.4}{.1}
}

\ganttset{%
  progress/.code={%
    \def\gtt@progress{#1}%
  },%
  progress=none%
}
\@gtt@stylekeydef{bar incomplete}{}
\@gtt@stylekeydef{group incomplete}{}
\ganttset{%
  incomplete/.style/.code={%
    \ganttset{bar incomplete/.style={#1}, group incomplete/.style={#1}}%
  },%
  incomplete/.style={fill=black!25}
}
\ganttset{%
  progress label text/.code={%
    \def\gtt@progresslabeltext##1{#1}%
  },%
  progress label text={#1\% complete}
}
\@gtt@keydef{progress label font}{\scriptsize}
\@gtt@stylekeydef{progress label anchor}{anchor=west}

\@gtt@stylekeydef{milestone}{fill=black}
\ganttset{%
  milestone label text/.code={%
    \def\gtt@milestonelabeltext##1{#1}%
  },%
  milestone label text={\strut#1}%
}
\@gtt@keydef{milestone label font}{\normalsize\itshape}
\@gtt@stylekeydef{milestone label anchor}{anchor=east}
\@gtt@stylekeydef{milestone label inline anchor}{anchor=south}
\@gtt@keydef{milestone label shape anchor}{center}
\@gtt@keydef{milestone width}{.8}
\@gtt@keydef{milestone height}{.4}
\@gtt@keydef{milestone xshift}{0}
\@gtt@keydef{milestone yshift}{.5}

\@gtt@stylekeydef{link}{-latex, rounded corners=1pt}
\@gtt@keydef{link type}{auto}
\@gtt@keydef{link mid}{.5}
\@gtt@keydef{link bulge}{.4}
\@gtt@keydef{link tolerance}{.6}
\@gtt@keydef{link label}{}
\@gtt@keydef{link label font}{\scriptsize\itshape\normalcolor}
\@gtt@stylekeydef{link label anchor}{anchor=west}

\def\gtt@vgrid@do#1,{%
  \ifx\relax#1\else%
    \ifnum\value{gtt@currgrid}>\value{gtt@width}\else%
      \gtt@vgrid@analyze#1\relax%
      \expandafter\expandafter\expandafter\gtt@vgrid@do%
    \expandafter\fi%
  \fi%
}

\def\gtt@vgrid@analyze{%
  \@ifstar{\gtt@vgrid@draw}{\gtt@vgrid@draw1}%
}

\def\gtt@vgrid@draw#1#2\relax{%
  \foreach \i in {1,...,#1} {%
    \draw [#2]
      (\value{gtt@currgrid} * \ganttvalueof{x unit}, \y@upper pt) --%
      (\value{gtt@currgrid} * \ganttvalueof{x unit}, \y@lower pt);%
    \stepcounter{gtt@currgrid}%
    \ifnum\value{gtt@currgrid}>\value{gtt@width}\breakforeach\fi%
  }%
}

\def\gtt@hgrid@do#1,{%
  \ifx\relax#1\else
    \ifnum\value{gtt@currgrid}<\value{gtt@currentline}\else%
      \gtt@hgrid@analyze#1\relax%
      \expandafter\expandafter\expandafter\gtt@hgrid@do%
    \expandafter\fi%
  \fi%
}

\def\gtt@hgrid@analyze{%
  \@ifstar{\gtt@hgrid@draw}{\gtt@hgrid@draw1}%
}

\def\gtt@hgrid@draw#1#2\relax{%
  \foreach \i in {1,...,#1} {%
    \pgfmathsetmacro\y@upper{%
      \value{gtt@lasttitleline} * \ganttvalueof{y unit title} +%
      (\value{gtt@currgrid} - \value{gtt@lasttitleline})%
      * \ganttvalueof{y unit chart}%
    }%
    \draw [#2]
      (0pt, \y@upper pt) --
      (\value{gtt@width} * \ganttvalueof{x unit}, \y@upper pt);%
    \addtocounter{gtt@currgrid}{-1}%
    \ifnum\value{gtt@currgrid}<\value{gtt@currentline}\breakforeach\fi%
  }%
}

\newif\ifgtt@tikzpicture

\newenvironment{ganttchart}[2][]{%
  \@ifundefined{useasboundingbox}%
    {\gtt@tikzpicturefalse\begin{tikzpicture}}%
    {\gtt@tikzpicturetrue}%
  \ganttset{#1}%
  \setcounter{gtt@width}{#2}%
  \setcounter{gtt@currentline}{0}%
  \setcounter{gtt@lasttitleline}{0}%
  \setcounter{gtt@elementid}{0}%
  \setcounter{gtt@currgrid}{1}%
  \gtt@intitletrue%
  \let\\\ganttnewline%
}{%
  \begin{scope}[on background layer]%
    \ifgtt@includetitle%
      \def\y@upper{0}%
    \else%
      \pgfmathsetmacro\y@upper{%
        \value{gtt@lasttitleline} * \ganttvalueof{y unit title}%
      }%
    \fi%
    \pgfmathsetmacro\y@lower{%
      \value{gtt@lasttitleline} * \ganttvalueof{y unit title}%
      + (\value{gtt@currentline} - \value{gtt@lasttitleline} - 1)%
      * \ganttvalueof{y unit chart}%
    }%
    \draw [/pgfgantt/canvas]
      (0pt, \y@upper pt) rectangle
      (\value{gtt@width} * \ganttvalueof{x unit}, \y@lower pt);%
    \pgfmathsetmacro\y@upper{%
      \value{gtt@lasttitleline} * \ganttvalueof{y unit title}%
    }%
    \ifgtt@vgrid
      \addtocounter{gtt@width}{-1}%
      \foreach \x in {1,...,\value{gtt@width}} {%
        \expandafter\gtt@vgrid@do\gtt@vgridstyle,\relax,%
        \ifnum\value{gtt@currgrid}>\value{gtt@width}\breakforeach\fi%
      }%
      \stepcounter{gtt@width}%
    \fi%
    \ifgtt@hgrid%
      \ifgtt@includetitle%
        \setcounter{gtt@currgrid}{\value{gtt@lasttitleline}}%
      \else%
        \pgfmathsetcounter{gtt@currgrid}{\value{gtt@lasttitleline}-1}%
      \fi%
      \edef\hgrid@upper{\thegtt@currgrid}%
      \foreach \t in {\hgrid@upper,...,\value{gtt@currentline}} {%
        \expandafter\gtt@hgrid@do\gtt@hgridstyle,\relax,%
        \ifnum\value{gtt@currgrid}<\value{gtt@currentline}\breakforeach\fi%
      }%
    \fi%
    \def\@tempa{none}%
    \edef\@tempb{\ganttvalueof{today}}%
    \ifx\@tempa\@tempb\else%
      \draw [/pgfgantt/today rule]
        (\ganttvalueof{today} * \ganttvalueof{x unit}, \y@upper pt) --
        (\ganttvalueof{today} * \ganttvalueof{x unit}, \y@lower pt);%
      \node at (\ganttvalueof{today} * \ganttvalueof{x unit}, \y@lower pt)
        [anchor=north] {\ganttvalueof{today label}};%
    \fi%
  \end{scope}%
  \ifgtt@tikzpicture\else\end{tikzpicture}\fi%
}

\newcommand\ganttnewline[1][]{%
  \def\@tempa{#1}%
  \def\@tempb{grid}%
  \ifx\@tempa\@empty\else
    \ifx\@tempa\@tempb%
      \def\@tempa{/pgfgantt/hgrid style}%
    \fi%
    \pgfmathsetmacro\y@upper{%
      \value{gtt@lasttitleline} * \ganttvalueof{y unit title}%
      + (\value{gtt@currentline} - \value{gtt@lasttitleline} - 1)%
      * \ganttvalueof{y unit chart}%
    }
    \expandafter\draw\expandafter[\@tempa]
      (0pt, \y@upper pt) --
      (\value{gtt@width} * \ganttvalueof{x unit}, \y@upper pt);%
  \fi%
  \addtocounter{gtt@currentline}{-1}%
  \ifgtt@intitle\addtocounter{gtt@lasttitleline}{-1}\fi%
  \setcounter{gtt@lasttitleslot}{0}%
}

\newcommand\gantttitle[3][]{%
  \begingroup%
  \ganttset{#1}%
  \pgfmathsetmacro\x@left{%
    (\value{gtt@lasttitleslot} + \ganttvalueof{title left shift})%
    * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\x@right{%
    (\value{gtt@lasttitleslot} + #3 + \ganttvalueof{title right shift})%
    * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\y@upper{%
    (\value{gtt@currentline} - \ganttvalueof{title top shift})%
    * \ganttvalueof{y unit title}%
  }%
  \pgfmathsetmacro\y@lower{%
    (\value{gtt@currentline} - \ganttvalueof{title top shift}%
    - \ganttvalueof{title height}) * \ganttvalueof{y unit title}%
  }%
  \draw [/pgfgantt/title]
    (\x@left pt, \y@upper pt) rectangle
    (\x@right pt, \y@lower pt);%
  \ganttvalueof{title label font}%
  \node at ($(\x@left pt,\y@upper pt)!.5!(\x@right pt,\y@lower pt)$)
    [/pgfgantt/title label anchor] {#2};%
  \addtocounter{gtt@lasttitleslot}{#3}%
  \endgroup%
}

\newcommand\gantttitlelist[3][]{%
  \begingroup%
  \ganttset{#1}%
  \expandafter\foreach\gtt@titlelistoptions in {#2} {\gantttitle{\x}{#3}}%
  \endgroup%
}

\pgfdeclareshape{chart element}{%
  \savedanchor\lowerleft{%
    \pgfpoint{\x@left pt}{\y@lower pt}%
  }%
  \savedanchor\upperleft{%
    \pgfpoint{\x@left pt}{\y@upper pt}%
  }%
  \savedanchor\lowerright{%
    \pgfpoint{\x@right pt}{\y@lower pt}%
  }%
  \savedanchor\upperright{%
    \pgfpoint{\x@right pt}{\y@upper pt}%
  }%
  \savedanchor\centerpoint{%
    \pgfpoint{\x@right pt / 2 + \x@left pt / 2}%
      {\y@upper pt / 2 + \y@lower pt / 2}%
  }%
  \anchor{on bottom}{%
    \lowerleft%
    \pgf@xa\pgf@x%
    \lowerright%
    \pgf@xb\pgf@x%
    \advance\pgf@xb-\pgf@xa%
    \advance\pgf@xa\@gtt@linkanchorfraction\pgf@xb%
    \pgf@x\pgf@xa%
  }%
  \anchor{on left}{%
    \upperleft%
    \pgf@ya\pgf@y%
    \lowerleft%
    \pgf@yb\pgf@y%
    \advance\pgf@yb-\pgf@ya%
    \advance\pgf@ya\@gtt@linkanchorfraction\pgf@yb%
    \pgf@y\pgf@ya%
  }%
  \anchor{on top}{%
    \upperleft%
    \pgf@xa\pgf@x%
    \upperright%
    \pgf@xb\pgf@x%
    \advance\pgf@xb-\pgf@xa%
    \advance\pgf@xa\@gtt@linkanchorfraction\pgf@xb%
    \pgf@x\pgf@xa%
  }%
  \anchor{on right}{%
    \upperright%
    \pgf@ya\pgf@y%
    \lowerright%
    \pgf@yb\pgf@y%
    \advance\pgf@yb-\pgf@ya%
    \advance\pgf@ya\@gtt@linkanchorfraction\pgf@yb%
    \pgf@y\pgf@ya%
  }%
  \anchor{center}{\centerpoint}%
  \anchor{lower left}{\lowerleft}%
  \anchor{left}{%
    \upperleft%
    \pgf@ya\pgf@y%
    \lowerleft%
    \pgf@yb\pgf@y%
    \advance\pgf@yb-\pgf@ya%
    \advance\pgf@ya.5\pgf@yb%
    \pgf@y\pgf@ya%
  }%
  \anchor{upper left}{\upperleft}%
  \anchor{lower right}{\lowerright}%
  \anchor{right}{%
    \upperright%
    \pgf@ya\pgf@y%
    \lowerright%
    \pgf@yb\pgf@y%
    \advance\pgf@yb-\pgf@ya%
    \advance\pgf@ya.5\pgf@yb%
    \pgf@y\pgf@ya%
  }%
  \anchor{upper right}{\upperright}%
}

\newcommand\ganttbar[4][]{%
  \begingroup%
  \ganttset{#1}%
  \pgfmathsetmacro\x@left{%
    (#3 + \ganttvalueof{time slot modifier}%
      + \ganttvalueof{bar left shift})%
    * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\x@right{%
    (#4 + \ganttvalueof{bar right shift}) * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\y@upper{%
    \value{gtt@lasttitleline} * \ganttvalueof{y unit title}
    + (\value{gtt@currentline} - \value{gtt@lasttitleline}
    - \ganttvalueof{bar top shift}) * \ganttvalueof{y unit chart}%
  }%
  \pgfmathsetmacro\y@lower{%
    \y@upper - \ganttvalueof{bar height} * \ganttvalueof{y unit chart}%
  }%
  \edef\gtt@name{\ganttvalueof{name}}%
  \ifx\gtt@name\@empty\edef\gtt@name{elem\thegtt@elementid}\fi%
  \node [shape=chart element] (\gtt@name)
    at ($(\x@left pt, \y@upper pt)!.5!(\x@right pt, \y@lower pt)$) {};
  \def\@tempa{none}%
  \ifx\gtt@progress\@tempa%
    \def\gtt@progress{100}%
    \let\gtt@pl@draw\relax%
  \else
    \expandafter\ifx\gtt@progresslabeltext\relax\relax%
      \let\gtt@pl@draw\relax%
    \else%
      \def\gtt@pl@draw{%
        \node at ($(\x@right pt, \y@upper pt)!.5!
          (\x@right pt, \y@lower pt)$)
          [/pgfgantt/progress label anchor] {%
            \ganttvalueof{progress label font}{%
              \gtt@progresslabeltext{\gtt@progress}%
            }%
          };%
      }%
    \fi%
  \fi%
  \begin{scope}%
    \clip (\x@left pt, \y@upper pt) rectangle
      ($(\x@left pt, \y@lower pt)!\gtt@progress/100!
        (\x@right pt, \y@lower pt)$);%
    \draw [/pgfgantt/bar, draw=none] (\x@left pt, \y@upper pt)
      rectangle (\x@right pt, \y@lower pt);%
  \end{scope}%
  \begin{scope}%
    \clip ($(\x@left pt, \y@upper pt)!\gtt@progress/100!
      (\x@right pt, \y@upper pt)$)
      rectangle (\x@right pt, \y@lower pt);%
    \draw [/pgfgantt/bar incomplete, draw=none]
      (\x@left pt, \y@upper pt) rectangle (\x@right pt, \y@lower pt);%
  \end{scope}%
  \draw [/pgfgantt/bar, fill=none]
    (\x@left pt, \y@upper pt) rectangle (\x@right pt, \y@lower pt);%
  \gtt@pl@draw%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else%
    \ifgtt@inline%
      \node at (\gtt@name.\ganttvalueof{bar label shape anchor})
        [/pgfgantt/bar label inline anchor]
        {\ganttvalueof{bar label font}{\gtt@barlabeltext{#2}}};%
    \else%
      \node at ($(0pt, \y@upper pt)!.5!(0pt, \y@lower pt)$)
        [/pgfgantt/bar label anchor]
        {\ganttvalueof{bar label font}{\gtt@barlabeltext{#2}}};%
    \fi%
  \fi%
  \xdef\gtt@lastelement{\gtt@currentelement}%
  \xdef\gtt@currentelement{\gtt@name}%
  \stepcounter{gtt@elementid}%
  \global\gtt@intitlefalse%
  \endgroup%
}

\newcommand\ganttlinkedbar[4][]{%
  \begingroup%
  \ganttset{#1}%
  \ganttbar{#2}{#3}{#4}%
  \ganttlink{\gtt@lastelement}{\gtt@currentelement}%
  \endgroup%
}

\newcommand\newganttlinktype[2]{%
  \expandafter\def\csname @gtt@linktype@#1\endcsname{#2}%
}

\newcommand\newganttlinktypealias[2]{%
  \expandafter\def\csname @gtt@linktype@#1\endcsname{%
    \@nameuse{@gtt@linktype@#2}%
  }%
  \expandafter\def\csname @gtt@linktype@#1@label\endcsname{%
    \@nameuse{@gtt@linktype@#2@label}%
  }%
}

\newcommand\setganttlinklabel[2]{%
  \expandafter\def\csname @gtt@linktype@#1@label\endcsname{#2}%
}

\newganttlinktype{r}{%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xRight, \yLower)
    node [pos=.5, /pgfgantt/link label anchor] {\ganttlinklabel};
}
\newganttlinktypealias{default}{r}

\newganttlinktype{rdr}{%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    ($(\xLeft, \yUpper)!\ganttvalueof{link mid}!
      (\xRight, \yUpper)$) --
    ($(\xLeft, \yLower)!\ganttvalueof{link mid}!
      (\xRight, \yLower)$) --
    (\xRight, \yLower);%
}

\newganttlinktype{rdldr}{%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xLeft + \ganttvalueof{link bulge} * \ganttvalueof{x unit},
      \yUpper) --
    ($(\xLeft + \ganttvalueof{link bulge} * \ganttvalueof{x unit},
      \yUpper)!%
      \ganttvalueof{link mid}!%
      (\xLeft + \ganttvalueof{link bulge} * \ganttvalueof{x unit},
      \yLower)$) --
    ($(\xRight - \ganttvalueof{link bulge} * \ganttvalueof{x unit},
      \yUpper)!%
      \ganttvalueof{link mid}!%
      (\xRight - \ganttvalueof{link bulge} * \ganttvalueof{x unit},
      \yLower)$) --
    (\xRight - \ganttvalueof{link bulge} * \ganttvalueof{x unit},
      \yLower) --
    (\xRight, \yLower);%
}

\newganttlinktype{dr}{%
  \ganttsetstartanchor{on bottom=.6}%
  \ganttsetendanchor{on left}%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xLeft, \yLower)
    node [pos=.5, /pgfgantt/link label anchor] {\ganttlinklabel} --
    (\xRight, \yLower);%
}

\newganttlinktype{s-s}{%
  \ganttsetstartanchor{on bottom=0}%
  \ganttsetendanchor{on top=0}%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xRight, \yLower)
    node [pos=.5, /pgfgantt/link label anchor] {\ganttlinklabel};
}
\setganttlinklabel{s-s}{start-to-start}

\newganttlinktype{s-f}{%
  \ganttsetstartanchor{on bottom=0}%
  \ganttsetendanchor{on top=1}%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xRight, \yLower)
    node [pos=.5, /pgfgantt/link label anchor] {\ganttlinklabel};
}
\setganttlinklabel{s-f}{start-to-finish}

\newganttlinktype{f-s}{%
  \ganttsetstartanchor{on bottom=1}%
  \ganttsetendanchor{on top=0}%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xRight, \yLower)
    node [pos=.5, /pgfgantt/link label anchor] {\ganttlinklabel};
}
\setganttlinklabel{f-s}{finish-to-start}

\newganttlinktype{f-f}{%
  \ganttsetstartanchor{on bottom=1}%
  \ganttsetendanchor{on top=1}%
  \draw [/pgfgantt/link]
    (\xLeft, \yUpper) --
    (\xRight, \yLower)
    node [pos=.5, /pgfgantt/link label anchor] {\ganttlinklabel};
}
\setganttlinklabel{f-f}{finish-to-finish}

\newcommand\gtt@drawlink[1]{%
  \@ifundefined{@gtt@linktype@#1}{%
    \PackageWarning{pgfgantt}{Link type `#1' unknown, using `default'.}%
    \def\@gtt@currlinktype{default}%
  }{%
    \def\@gtt@currlinktype{#1}%
  }%
  \edef\@gtt@currlabel{\ganttvalueof{link label}}%
  \ifx\@gtt@currlabel\@empty%
    \def\ganttlinklabel{%
      \ganttvalueof{link label font}{%
        \csname @gtt@linktype@\@gtt@currlinktype @label\endcsname%
      }%
    }%
  \else%
    \def\ganttlinklabel{%
      \ganttvalueof{link label font}{%
        \@gtt@currlabel%
      }%
    }%
  \fi%
  \@nameuse{@gtt@linktype@\@gtt@currlinktype}%
}

\def\@gtt@linkanchordef#1{%
  \ganttset{%
    link anchor/#1/.code={%
      \def\@gtt@linkanchor{#1}%
      \def\@gtt@linkanchorfraction{##1}%
    },%
    link anchor/#1/.default=.5%
  }
}
\@gtt@linkanchordef{on left}
\@gtt@linkanchordef{on right}
\@gtt@linkanchordef{on top}
\@gtt@linkanchordef{on bottom}
\@gtt@linkanchordef{lower left}
\@gtt@linkanchordef{left}
\@gtt@linkanchordef{upper left}
\@gtt@linkanchordef{lower right}
\@gtt@linkanchordef{right}
\@gtt@linkanchordef{upper right}

\newcommand\@gtt@setstartanchor[1]{%
  \pgfqkeys{/pgfgantt/link anchor}{#1}%
  \pgfpointanchor{\@gtt@startelement}{\@gtt@linkanchor}%
  \edef\xLeft{\the\pgf@x}%
  \edef\yUpper{\the\pgf@y}%
}

\newcommand\@gtt@setendanchor[1]{%
  \pgfqkeys{/pgfgantt/link anchor}{#1}%
  \pgfpointanchor{\@gtt@endelement}{\@gtt@linkanchor}%
  \edef\xRight{\the\pgf@x}%
  \edef\yLower{\the\pgf@y}%
}

\newcommand\ganttlink[3][]{%
  \begingroup%
  \ganttset{#1}%
  \def\@gtt@startelement{#2}%
  \def\@gtt@endelement{#3}%
  \let\ganttsetstartanchor\@gtt@setstartanchor%
  \let\ganttsetendanchor\@gtt@setendanchor%
  \ganttsetstartanchor{right}%
  \ganttsetendanchor{left}%
  \def\@tempa{auto}%
  \edef\@tempb{\ganttvalueof{link type}}%
  \ifx\@tempa\@tempb%
    \pgfmathparse{abs(\yUpper - \yLower) <= 1}%
    \ifcase\pgfmathresult%
      \pgfmathparse{
        (\xRight - \xLeft)
        >= \ganttvalueof{link tolerance} * \ganttvalueof{x unit}
      }%
      \ifcase\pgfmathresult%
        \gtt@drawlink{rdldr}%
      \else%
        \gtt@drawlink{rdr}%
      \fi%
    \else%
      \gtt@drawlink{r}%
    \fi%
  \else%
    \gtt@drawlink{\ganttvalueof{link type}}%
  \fi%
  \endgroup%
}

\newcommand\ganttgroup[4][]{%
  \begingroup%
  \ganttset{#1}%
  \pgfmathsetmacro\x@left{%
    (#3 + \ganttvalueof{time slot modifier}%
      + \ganttvalueof{group left shift})%
    * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\x@right{%
    (#4 + \ganttvalueof{group right shift}) * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\y@upper{%
    \value{gtt@lasttitleline} * \ganttvalueof{y unit title}
    + (\value{gtt@currentline} - \value{gtt@lasttitleline}
    - \ganttvalueof{group top shift}) * \ganttvalueof{y unit chart}%
  }%
  \pgfmathsetmacro\y@lower{%
    \y@upper - \ganttvalueof{group height} * \ganttvalueof{y unit chart}%
  }%
  \edef\gtt@name{\ganttvalueof{name}}%
  \ifx\gtt@name\@empty\edef\gtt@name{elem\thegtt@elementid}\fi%
  \node [shape=chart element] (\gtt@name)
    at ($(\x@left pt, \y@upper pt)!.5!(\x@right pt, \y@lower pt)$) {};
  \def\@tempa{none}%
  \ifx\gtt@progress\@tempa%
    \def\gtt@progress{100}%
    \let\gtt@pl@draw\relax%
  \else
    \expandafter\ifx\gtt@progresslabeltext\relax\relax%
      \let\gtt@pl@draw\relax%
    \else%
      \def\gtt@pl@draw{%
        \node at ($(\x@right pt, \y@upper pt)!.5!
          (\x@right pt, \y@lower pt)$)
          [/pgfgantt/progress label anchor] {%
            \ganttvalueof{progress label font}{%
              \gtt@progresslabeltext{\gtt@progress}%
            }%
          };%
      }%
    \fi%
  \fi%
  \pgfmathsetmacro\@maxpeak{%
    \gtt@grouprightpeaky > \gtt@groupleftpeaky ?%
    \gtt@grouprightpeaky * \ganttvalueof{y unit chart} :%
    \gtt@groupleftpeaky * \ganttvalueof{y unit chart}%
  }%
  \begin{scope}%
    \clip (\x@left pt, \y@upper pt) rectangle
      ($(\x@left pt, \y@lower pt - \@maxpeak pt)!%
        \gtt@progress/100!%
        (\x@right pt, \y@lower pt - \@maxpeak pt)$);%
    \path [/pgfgantt/group, draw=none]
      (\x@left pt, \y@upper pt) --
      (\x@right pt, \y@upper pt) --
      (\x@right pt, \y@lower pt) --
      (\x@right pt + \gtt@grouprightpeakmidx * \ganttvalueof{x unit},
        \y@lower pt - \gtt@grouprightpeaky
          * \ganttvalueof{y unit chart}) --
      (\x@right pt + \gtt@grouprightpeakinnerx * \ganttvalueof{x unit},
        \y@lower pt) --
      (\x@left pt + \gtt@groupleftpeakinnerx * \ganttvalueof{x unit},
        \y@lower pt) --
      (\x@left pt + \gtt@groupleftpeakmidx * \ganttvalueof{x unit},
        \y@lower pt - \gtt@groupleftpeaky * \ganttvalueof{y unit chart}) --
      (\x@left pt, \y@lower pt) --
      cycle;%
  \end{scope}%
  \begin{scope}%
    \clip ($(\x@left pt, \y@upper pt)!%
        \gtt@progress/100!%
        (\x@right pt, \y@upper pt)$)
      rectangle (\x@right pt, \y@lower pt - \@maxpeak pt);
    \path [/pgfgantt/group incomplete]
      (\x@left pt, \y@upper pt) --
      (\x@right pt, \y@upper pt) --
      (\x@right pt, \y@lower pt) --
      (\x@right pt + \gtt@grouprightpeakmidx * \ganttvalueof{x unit},
        \y@lower pt - \gtt@grouprightpeaky
          * \ganttvalueof{y unit chart}) --
      (\x@right pt + \gtt@grouprightpeakinnerx * \ganttvalueof{x unit},
        \y@lower pt) --
      (\x@left pt + \gtt@groupleftpeakinnerx * \ganttvalueof{x unit},
        \y@lower pt) --
      (\x@left pt + \gtt@groupleftpeakmidx * \ganttvalueof{x unit},
        \y@lower pt - \gtt@groupleftpeaky * \ganttvalueof{y unit chart}) --
      (\x@left pt, \y@lower pt) --
      cycle;%
  \end{scope}%
  \path [/pgfgantt/group, fill=none]
    (\x@left pt, \y@upper pt) --
    (\x@right pt, \y@upper pt) --
    (\x@right pt, \y@lower pt) --
    (\x@right pt + \gtt@grouprightpeakmidx * \ganttvalueof{x unit},
      \y@lower pt - \gtt@grouprightpeaky * \ganttvalueof{y unit chart}) --
    (\x@right pt + \gtt@grouprightpeakinnerx * \ganttvalueof{x unit},
      \y@lower pt) --
    (\x@left pt + \gtt@groupleftpeakinnerx * \ganttvalueof{x unit},
      \y@lower pt) --
    (\x@left pt + \gtt@groupleftpeakmidx * \ganttvalueof{x unit},
      \y@lower pt - \gtt@groupleftpeaky * \ganttvalueof{y unit chart}) --
    (\x@left pt, \y@lower pt) --
    cycle;%
  \gtt@pl@draw%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else%
    \ifgtt@inline%
      \node at (\gtt@name.\ganttvalueof{group label shape anchor})
        [/pgfgantt/group label inline anchor]
        {\ganttvalueof{group label font}{\gtt@grouplabeltext{#2}}};%
    \else%
      \node at ($(0pt, \y@upper pt)!.5!(0pt, \y@lower pt)$)
        [/pgfgantt/group label anchor]
        {\ganttvalueof{group label font}{\gtt@grouplabeltext{#2}}};%
    \fi%
  \fi%
  \xdef\gtt@lastelement{\gtt@currentelement}%
  \xdef\gtt@currentelement{\gtt@name}%
  \stepcounter{gtt@elementid}%
  \global\gtt@intitlefalse%
  \endgroup%
}

\newcommand\ganttlinkedgroup[4][]{%
  \begingroup%
  \ganttset{#1}%
  \ganttgroup{#2}{#3}{#4}%
  \ganttlink{\gtt@lastelement}{\gtt@currentelement}%
  \endgroup%
}

\newcommand\ganttmilestone[3][]{%
  \begingroup%
  \ganttset{#1}%
  \pgfmathsetmacro\x@mid{%
    (#3 + \ganttvalueof{milestone xshift}) * \ganttvalueof{x unit}%
  }%
  \pgfmathsetmacro\x@left{%
    \x@mid - \ganttvalueof{milestone width} / 2 * \ganttvalueof{x unit}%
  }
  \pgfmathsetmacro\x@right{%
    \x@mid + \ganttvalueof{milestone width} / 2 * \ganttvalueof{x unit}%
  }
  \pgfmathsetmacro\y@mid{%
    \value{gtt@lasttitleline} * \ganttvalueof{y unit title}%
    + (\value{gtt@currentline} - \value{gtt@lasttitleline}%
    - \ganttvalueof{milestone yshift}) * \ganttvalueof{y unit chart}%
  }%
  \pgfmathsetmacro\y@upper{%
    \y@mid + \ganttvalueof{milestone height} / 2
      * \ganttvalueof{y unit chart}%
  }%
  \pgfmathsetmacro\y@lower{%
    \y@mid - \ganttvalueof{milestone height} / 2
      * \ganttvalueof{y unit chart}%
  }%
  \edef\gtt@name{\ganttvalueof{name}}%
  \ifx\gtt@name\@empty\edef\gtt@name{elem\thegtt@elementid}\fi%
  \node [shape=chart element] (\gtt@name)
    at ($(\x@left pt, \y@upper pt)!.5!(\x@right pt, \y@lower pt)$) {};
  \path [/pgfgantt/milestone]
    (\x@left pt, \y@mid pt) --
    (\x@mid pt, \y@lower pt) --
    (\x@right pt, \y@mid pt) --
    (\x@mid pt, \y@upper pt) --
    cycle;%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty\else%
    \ifgtt@inline%
      \node at (\gtt@name.\ganttvalueof{milestone label shape anchor})
        [/pgfgantt/milestone label inline anchor]
        {\ganttvalueof{milestone label font}{%
          \gtt@milestonelabeltext{#2}%
        }};%
    \else%
      \node at (0pt, \y@mid pt)
        [/pgfgantt/milestone label anchor]
        {\ganttvalueof{milestone label font}{%
          \gtt@milestonelabeltext{#2}%
        }};%
    \fi%
  \fi%
  \xdef\gtt@lastelement{\gtt@currentelement}%
  \xdef\gtt@currentelement{\gtt@name}%
  \stepcounter{gtt@elementid}%
  \global\gtt@intitlefalse%
  \endgroup%
}

\newcommand\ganttlinkedmilestone[3][]{%
  \begingroup%
  \ganttset{#1}%
  \ganttmilestone{#2}{#3}%
  \ganttlink{\gtt@lastelement}{\gtt@currentelement}%
  \endgroup%
}
\endinput
%%
%% End of file `pgfgantt.sty'.
