% All macros commented
\newcommand{\paperpdf}{}              %  1
\newcommand{\papertex}{}              %  2
\newcommand{\projecttex}{}            %  3
\newcommand{\verifytex}{}             %  4
\newcommand{\demoplottex}{}           %  5
\newcommand{\toolsperyear}{}          %  6
\newcommand{\tablethree}{}            %  7
\newcommand{\menkexlsx}{}             %  8
\newcommand{\inputsconf}{}            %  9
\newcommand{\downloadtex}{}           % 10
\newcommand{\formattex}{}             % 11
\newcommand{\demoyearconf}{}          % 12
\newcommand{\initializetex}{}         % 13
\newcommand{\expandingproject}{}      % 14



\begin{tikzpicture}

  %% These white lines are only relevant when we want to add boxes in
  %% multiple figures (for example to build slides). They are used to fix
  %% the vertical position of the boxs in the figure so it doesn't change
  %% as we add more boxes.
  \draw [white] (-9cm,0) -- (9cm,0);
  \draw [white] (0,-5cm) -- (0,4cm);

  %% Right-side Y axis (red, logarithmic histogram). This should be created
  %% under the line, because the line doesn't interfere with interpretting
  %% the histogram, but the inverse is not true.
  \begin{axis}[
      ymode=log,
      width=5cm,
      height=5cm,
      axis on top,
      axis x line=none,
      axis y line*=right,
      at={(-7.4cm,-1.8cm)},
      enlarge x limits = false,
      ylabel={Num. papers (red, log-scale)},
      max space between ticks=20,
    ]
    \addplot+ [ybar, mark=none, fill=red!40!white, red!40!white]
    table [x index=0, y index=2] {tex/build/to-publish/tools-per-year.txt};
  \end{axis}

  %% Left-side Y axis (green, linear/percent line).
  \begin{axis}[
      ymin=0,
      ymax=100,
      width=5cm,
      height=5cm,
      xlabel={Year},
      axis y line*=left,
      at={(-7.4cm,-1.8cm)},
      enlarge x limits = false,
      ylabel={Frac. papers with tools (green)},
      yticklabel=\pgfmathprintnumber{\tick}\,\%,
      x tick label style={/pgf/number format/1000 sep=},
    ]

    %% Linear plot, showing the number of papers mentioning tools.
    \addplot+ [mark=none, ultra thick, green!60!black]
    table {tex/build/to-publish/tools-per-year.txt};
  \end{axis}

  %% Use small fonts for the rest.
  \scriptsize

  %% top-make.mk
  \node [rectangle,
         very thick,
         text centered,
         font=\ttfamily,
         text width=2.8cm,
         anchor=north west,
         at={(-2.6cm,3.5cm)},
         minimum width=11.6cm,
         minimum height=7.25cm,
         draw=green!50!black!50,
         fill=black!10!green!2!white,
         label={[shift={(0,-5mm)}]\texttt{top-make.mk}}] {};

  %% verify.mk
  \node [at={(-0.7cm,-2.9cm)},
         thick,
         rectangle,
         text centered,
         font=\ttfamily,
         text width=2.45cm,
         minimum width=3.5cm,
         minimum height=1.3cm,
         draw=green!50!black!50,
         fill=black!10!green!12!white,
         label={[shift={(1cm,-5mm)}]\texttt{verify.mk}}] {};

  %% Paper.mk
  \node [at={(5.35cm,-2.9cm)},
         thick,
         rectangle,
         text centered,
         text width=2.8cm,
         minimum width=7cm,
         minimum height=1.3cm,
         draw=green!50!black!50,
         fill=black!10!green!12!white,
         font=\ttfamily,
         label={[shift={(0,-5mm)}]\texttt{paper.mk}}] {};

  %% Work-horse Makefiles, the X axis value of the files is the same. The Y
  %% axis values range like this:
  %%      2.1cm
  %%      1.3cm
  %%      0.5cm
  %%     -0.4cm
  %%     -1.3cm
  \node [node-makefile, at={(-1.4cm,3cm)},
        label={[shift={(0,-5mm)}]\texttt{initialize.mk}}] {};
  \node [node-makefile, at={(0.9cm,3cm)},
        label={[shift={(0,-5mm)}]\texttt{download.mk}}] {};
  \node [node-makefile, at={(3.2cm,3cm)},
        label={[shift={(0,-5mm)}]\texttt{format.mk}}] {};
  \node [node-makefile, at={(5.5cm,3cm)},
        label={[shift={(0,-5mm)}]\texttt{demo-plot.mk}}] {};

  %% paper.pdf
  \ifdefined\paperpdf
  \node (paperpdf) [node-terminal, at={(7.8cm,-3cm)}] {paper.pdf};
  \fi

  %% paper.tex and references.tex
  \ifdefined\papertex
  \node (reftex) [node-nonterminal, at={(5.5cm,-3.9cm)}] {references.tex};
  \node (papertex) [node-nonterminal, at={(7.8cm,-3.9cm)}] {paper.tex};
  \node (papertex-north) [node-point, at={(7.8cm,-3.65cm)}] {};
  \draw [rounded corners, black!50, line width=1.5pt] (reftex) |- (papertex-north);
  \draw [->, black!50, line width=1.5pt] (papertex) -- (paperpdf);
  \fi

  %% project.tex
  \ifdefined\projecttex
  \node (projecttex) [node-terminal, at={(3.2cm,-3cm)}] {project.tex};
  \draw [->, black!50, line width=1.5pt] (projecttex) -- (paperpdf);
  \fi

  %% verify.tex
  \ifdefined\verifytex
  \node (verifytex) [node-terminal, at={(-1.4cm,-3cm)}] {verify.tex};
  \draw [->, black!50, line width=1.5pt] (verifytex) -- (projecttex);
  \fi

  %% demo-plot.tex
  \ifdefined\demoplottex
  \node (initialize-south) [node-point, at={(-1.4cm,-2cm)}] {};
  \node (verifytop) [node-point, at={(-1.4cm,-2.75cm)}] {};
  \node (dptex) [node-terminal, at={(5.5cm,-1.3cm)}] {demo-plot.tex};
  \draw [rounded corners, ->, black!50, line width=1.5pt]
        (dptex) |- (initialize-south) |- (verifytop);
  \fi

  %% tools-per-year.txt
  \ifdefined\toolsperyear
  \node (tpyear) [node-terminal, at={(5.5cm,-0.4cm)}] {tools-per-\\year.txt};
  \draw [->, black!50, line width=1.5pt] (tpyear) -- (dptex);
  \fi

  %% table-3.txt
  \ifdefined\tablethree
  \node (tabthree) [node-terminal, at={(3.2cm,0.5cm)}] {table-3.txt};
  \draw [rounded corners, ->, black!50, line width=1.5pt] (tabthree) |- (tpyear);
  \fi

  %% menkexlsx
  \ifdefined\menkexlsx
  \node (xlsx) [node-terminal, at={(0.9cm,1.3cm)}] {menke20.xlsx};
  \draw [->, rounded corners, black!50, line width=1.5pt] (xlsx) |- (tabthree);
  \fi

  %% INPUTS.conf
  \ifdefined\inputsconf
  \node (INPUTS) [node-nonterminal, at={(0.9cm,4cm)}] {INPUTS.conf};
  \node (xlsx-west) [node-point, at={(-0.25cm,1.37cm)}] {};
  \draw [->,rounded corners, black!50, line width=1.5pt]
        (INPUTS.west) -| (xlsx-west) |- (xlsx);
  \fi

  %% download.tex
  \ifdefined\downloadtex
  \node (downloadtex) [node-terminal, at={(0.9cm,-1.3cm)}] {download.tex};
  \node (downloadtex-west) [node-point, at={(-0.25cm,-1.25cm)}] {};
  \draw [->,rounded corners, black!50, line width=1.5pt]
        (INPUTS.west) -| (downloadtex-west) |- (downloadtex);
  \draw [rounded corners, -, black!50, line width=1.5pt]
        (downloadtex) |- (initialize-south);
  \fi

  %% format.tex
  \ifdefined\formattex
  \node (fmttex) [node-terminal, at={(3.2cm,-1.3cm)}] {format.tex};
  \draw [->, black!50, line width=1.5pt] (tabthree) -- (fmttex);
  \draw [rounded corners, -, black!50, line width=1.5pt]
        (fmttex) |- (initialize-south);
  \fi

  %% demo-year.conf
  \ifdefined\demoyearconf
  \node (dyearconf) [node-nonterminal, at={(5.5cm,4cm)}] {demo-year.conf};
  \node (dptex-west) [node-point, at={(4.35cm,-1.25cm)}] {};
  \draw [->,rounded corners, black!50, line width=1.5pt]
        (dyearconf.west) -| (dptex-west) |- (dptex);
  \fi

  %% Initialize.tex
  \ifdefined\initializetex
  \node (initializetex) [node-terminal, at={(-1.4cm,-1.3cm)}] {initialize.tex};
  \draw [->, black!50, line width=1.5pt] (initializetex) -- (verifytex);
  \node [anchor=west, at={(-2.4cm,1.5cm)}] {Basic project info};
  \node [anchor=west, at={(-2.4cm,1.2cm)}] {(e.g., Git commit).};
  \node [anchor=west, at={(-2.4cm,0.5cm)}] {Also defines};
  \node [anchor=west, at={(-2.4cm,0.2cm)}] {project structure};
  \node [anchor=west, at={(-2.4cm,-0.1cm)}] {(for \texttt{*.mk} files).};
  \fi

  %% Expanding project
  \ifdefined\expandingproject

    %% The Makefile.
    \node [node-makefile, dotted, at={(7.8cm,3cm)},
          label={[shift={(0,-5mm)}]\texttt{next-step.mk}}] {};

    %% next-step.tex
    \node [dotted] (a3tex) [node-terminal, at={(7.8cm,-1.3cm)}] {next-step.tex};
    \draw [dotted, rounded corners, -, black!50, line width=1.4pt]
          (a3tex) |- (initialize-south);

    % out-3a.dat and out-3b.dat
    \node [dotted] (out3a) [node-terminal, at={(7.8cm,2.1cm)}] {out-a.dat};
    \node [dotted] (out3b) [node-terminal, at={(7.8cm,0.5cm)}] {out-b.dat};
    \node (a3tex-east) [node-point, at={(8.93cm,-0.8cm)}] {};
    \draw [dotted, ->, rounded corners, black!50, line width=1.5pt]
          (out3a.east) -| (a3tex-east) |- (a3tex);
    \draw [dotted, ->, black!50, line width=1.5pt] (out3b) -- (a3tex);

    %% demo-out.dat
    \node [dotted] (dout) [node-terminal, at={(5.5cm,1.3cm)}] {demo-out.dat};
    \draw [dotted, rounded corners, ->, black!50, line width=1.5pt] (dout.south) |- (out3b);

    %% links
    \node (dout-west) [node-point, at={(5cm,1.3cm)}] {};
    \draw [dotted, ->, black!50, line width=1.5pt] (xlsx) -- (dout);
    \node [opacity=0.7] (out3a-west) [node-point, at={(6.65cm,2.1cm)}] {};
    \draw [dotted, ->, rounded corners, black!50, line width=1.5pt] (xlsx) |- (out3a);
    \node [dotted] (a3conf1) [node-nonterminal, at={(7.8cm,4cm)}]  {param.conf};
    \draw [dotted, rounded corners, black!50, line width=1.5pt]
          (a3conf1.west) -| (out3a-west) |- (out3a);
  \fi

\end{tikzpicture}
