% Copyright (C) 2018-2019 Mohammad Akhlaghi <mohammad@akhlaghi.org>
%
% This LaTeX source is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This LaTeX source is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this LaTeX source.  If not, see <https://www.gnu.org/licenses/>.

%% Environment variables.
\newcommand{\allopacity}{1}
\newcommand{\sver}{}
\newcommand{\srep}{}
\newcommand{\dver}{}
\newcommand{\ddver}{}
\newcommand{\confopt}{}
\newcommand{\confenv}{}
\newcommand{\containers}{}
\newcommand{\db}{}
\newcommand{\calib}{}
\newcommand{\corr}{}
\newcommand{\runord}{}
\newcommand{\runopt}{}
\newcommand{\humanerr}{}
\newcommand{\confirmbias}{}
\newcommand{\depupdate}{}
\newcommand{\coauth}{}
\newcommand{\varsinpaper}{}
\newcommand{\recordinfo}{}
\newcommand{\softcite}{}
\newcommand{\prevchange}{}

\begin{tikzpicture}[>=stealth, thick, black!50, text=black,
    every new ->/.style={shorten >=1pt},
    hv path/.style={to path={-| (\tikztotarget)}},
    graphs/every graph/.style={edges=rounded corners}]

    \footnotesize

  %% This white line is only added to fix the vertical position of the
  %% figure so it doesn't change as we add more boxes.
  \draw [white] (0,-4.3) -- (0,3.8);
  \draw [white] (-0.5,0) -- (12,0);

  %% Box showing containers.
  \ifdefined\containers
    \filldraw[orange!20!white, rounded corners=2mm] (-0.1,0.3) rectangle (5.6,3.8);
    \draw (-0.1,3.65) node [anchor=west] {\scriptsize Existing solutions:};
    \draw (0,3.35) node [anchor=west] {\scriptsize Virtual machines};
    \draw (0,3.05) node [anchor=west] {\scriptsize Containers};
    \draw (0,2.75) node [anchor=west] {\scriptsize Package managers};
  \fi

  \graph[grow right sep, simple] {
    { [nodes={yshift=7mm}]
      soft/Software [gbox] -> build/Build [bbox],
      hard/Hardware/data [gbox, yshift=-0.5cm] --
      p1 [coordinate, xshift=2cm, yshift=-0.5cm]
    } -- [hv path]
    p2 [coordinate] ->
    srun/Run software on data [bbox] ->
    paper/Paper [bbox]
  };

  \ifdefined\paperfinal
    \node (happy) [inner sep=0pt, below=of paper, yshift=+8mm]
          {\includegraphics[width=2cm]{img/happy-question.jpg}};
    \node (happyurl) [below=of happy, xshift=-9.5mm, yshift=+1cm]
          {\tiny \url{https://heywhatwhatdidyousay.wordpress.com}};
    \node (qurl) [below=of happyurl, xshift=10.5mm, yshift=+1.2cm]
          {\tiny \url{http://pngimages.net}};
  \else
    \ifdefined\paperinit
      \node (happy) [inner sep=0pt, below=of paper, yshift=+8mm]
            {\includegraphics[width=2cm]{img/happy.jpg}};
      \node (happyurl) [below=of happy, xshift=-9.5mm, yshift=+1cm]
            {\tiny \url{https://heywhatwhatdidyousay.wordpress.com}};
    \fi
  \fi

  %% Software...
  \let\ppopacity\undefined
  \ifdefined\allopacity \newcommand{\ppopacity}{1}
  \else \ifdefined\focusonpackages
      \newcommand{\ppopacity}{1}
    \else
      \newcommand{\ppopacity}{0.3}
    \fi
  \fi

  \ifdefined\sver
  \node (sver)
        [rbox, above=of soft, yshift=-8mm, opacity=\ppopacity]
        {What version?};
  \fi
  \ifdefined\srep
  \node (srep)
        [rbox, above=of sver, yshift=-8mm, opacity=\ppopacity]
        {Repository?};
  \fi

  %% Build
  \ifdefined\dver
  \node (dver)
        [rbox, above=of build, yshift=-8mm, opacity=\ppopacity]
        {Dependencies?};
  \fi
  \ifdefined\ddver
  \node (ddver)
        [rbox, above=of dver, yshift=-8mm, opacity=\ppopacity]
        {Dep. versions?};
  \fi
  \ifdefined\confopt
  \node (confopt)
        [rbox, above=of ddver, yshift=-8mm, opacity=\ppopacity]
        {Config options?};
  \fi
  \ifdefined\confenv
  \node (confenv)
        [rbox, above=of confopt, yshift=-8mm, opacity=\ppopacity]
        {Config environment?};
  \fi

  %% Hardware/data
  \let\ppopacity\undefined
  \ifdefined\allopacity \newcommand{\ppopacity}{1}
  \else \ifdefined\focusonhardware
      \newcommand{\ppopacity}{1}
    \else
      \newcommand{\ppopacity}{0.3}
    \fi
  \fi
  \ifdefined\db
  \node (db)
        [rbox, below=of hard, yshift=+8mm, opacity=\ppopacity]
        {Data base, or PID?};
  \fi
  \ifdefined\calib
  \node (calib)
        [rbox, below=of db, yshift=+8mm, opacity=\ppopacity]
        {Calibration/version?};
  \fi
  \ifdefined\corr
  \node (corr)
        [rbox, below=of calib, yshift=+8mm, opacity=\ppopacity]
        {Integrity?};
  \fi

  %% Run software ...
  \let\ppopacity\undefined
  \ifdefined\allopacity \newcommand{\ppopacity}{1}
  \else \ifdefined\focusonrun
      \newcommand{\ppopacity}{1}
    \else
      \newcommand{\ppopacity}{0.3}
    \fi
  \fi
  \ifdefined\runord
  \node (runord)
        [rbox, above=of srun, yshift=-8mm, opacity=\ppopacity]
        {What order?};
  \fi
  \ifdefined\runopt
  \node (runopt)
        [rbox, above=of runord, yshift=-8mm, opacity=\ppopacity]
        {Runtime options?};
  \fi
  \ifdefined\humanerr
  \node (humanerr)
        [rbox, above=of runopt, yshift=-8mm, opacity=\ppopacity]
        {Human error?};
  \fi
  \ifdefined\confirmbias
  \node (confirmbias)
        [rbox, above=of humanerr, yshift=-8mm, opacity=\ppopacity]
        {Confirmation bias?};
  \fi
  \ifdefined\depupdate
  \node (depupdate)
        [rbox, below=of srun, yshift=+8mm, opacity=\ppopacity]
        {Environment update?};
  \fi
  \ifdefined\coauth
  \node (coaut)
        [rbox, below=of depupdate, yshift=+8mm, opacity=\ppopacity]
        {In sync with coauthors?};
  \fi

  %% Paper ...
  \let\ppopacity\undefined
  \ifdefined\allopacity \newcommand{\ppopacity}{1}
  \else \ifdefined\focusonpaper
      \newcommand{\ppopacity}{1}
    \else
      \newcommand{\ppopacity}{0.3}
    \fi
  \fi
  \ifdefined\varsinpaper
  \node (varsinpaper)
        [rbox, above=of paper, xshift=-1mm, yshift=-8mm, opacity=\ppopacity]
        {Sync with analysis?};
  \fi
  \ifdefined\recordinfo
  \node (recordinfo)
        [rbox, above=of varsinpaper, yshift=-8mm, opacity=\ppopacity]
        {Report this info?};
  \fi
  \ifdefined\softcite
  \node (softcite)
        [rbox, above=of recordinfo, yshift=-8mm, opacity=\ppopacity]
        {Cited software?};
  \fi
  \ifdefined\prevchange
  \node (prevchange)
        [rbox, above=of softcite, yshift=-8mm, opacity=\ppopacity]
        {History recorded?};
  \fi

  \ifdefined\gitlogo
  \node [inner sep=0pt, opacity=0.5] at (5.5,0)
        {\includegraphics[width=10cm]{img/git.png}};
  \fi
\end{tikzpicture}
