%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% aagant.sty -- Gant diagram and histogram
%% 
%% Author          : Anders Andersen
%% Created On      : Mon Nov 27 14:17:14 1995
%% Last Modified By: Anders Andersen
%% Last Modified On: Tue Nov 23 12:33:16 1999
%% Status          : Unknown, Use with caution!
%% 
%% (C) Copyright 1995, 1998, 1999, Anders Andersen, all rights reserved.
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --------------------------------------%--------------------------------------
% ---------------------------- Identification part ----------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{rcs}

\RCS$Date: 2002/07/09 23:45:45 $
\RCS$RCSfile: aagant.sty,v $
\RCS$Revision: 1.1 $
\RCS$State: Exp $
\RCS$Author: aa $

\input{aausercs}


% --------------------------------------%--------------------------------------
% ----------------------------- Example of usage ------------------------------
% --------------------------------------%--------------------------------------

% \usepackage{aagant}
% ...
% \begin{gant}[Fritid]{7}{2}                    % `Fritid' is longest task desc
%   \gd{M}\gd{T}\gd{O}\gd{T}\gd{F}\gd{L}\gd{S}  % Labels
%   \task{Jobb}{1}{5}                           % First task
%   \task[red]{Fritid}{6}{7}                    % Second task
% \end{gant}
% ...
% \begin{histogram}[Kirkenes]{10}{2}            % `Kirkenes' is longest
%   \gd[5]{0}\gd[5]{5}\gd[5]{10}                % Labels
%   \histo{Kirkenes}{5}                         % First bar
%   \histo[red]{Kiby}{7}                        % Second bar
% \end{histogram}


% --------------------------------------%--------------------------------------
% ------------------------------ Package loading ------------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{color}
\RequirePackage{calc}
\RequirePackage{ifthen}


% --------------------------------------%--------------------------------------
% --------------------------------- Main code ---------------------------------
% --------------------------------------%--------------------------------------

% The width used for each unit (here 20\unitlength)
\newcounter{gdw}\setcounter{gdw}{20}

% The distance (height) between each task
\newcounter{gdh}\setcounter{gdh}{15}

% The width of the Gant diagram
\newcounter{gwidth}

% The height of the Gant diagram
\newcounter{gheight}

% The total width (including borders and description of task)
\newcounter{gtwidth}

% The total height (including borders and description of unit)
\newcounter{gtheight}
\newcounter{gxxheight}

% The task number (stepped for each new task in the diagram)
\newcounter{gtask}

% The start position (x) of this task
\newcounter{gxpos}

% The start position (y) of this task
\newcounter{gypos}

% The length of this task
\newcounter{glen}

% Space used for description of tasks
\newcounter{ghtextsz}

% Space used for description of units
\newcounter{gvtextsz}\setcounter{gvtextsz}{15}
\newlength{\ghtextw}

% Length of time axis
\newcounter{gveclen}

% The start x position of description text
\newcounter{gdescxpos}

% The start y position of description text
\newcounter{gdescypos}\setcounter{gdescypos}{\value{gdh}/2}

\newcommand{\task}[4][black]{%
  \stepcounter{gtask}
  \setcounter{gypos}{-\value{gtask}*\value{gdh}}
  \setcounter{gxpos}{(#3-1)*\value{gdw}}
  \setcounter{glen}{(#4-#3+1)*\value{gdw}}
  \put(\value{gxpos},\value{gypos}){%
    \textcolor{#1}{\rule{\value{glen}\unitlength}{2\unitlength}}}
  \put(-\value{ghtextsz},\value{gypos}){\makebox(\value{ghtextsz},0)[l]{#2~}}}

\newcommand{\histo}[3][black]{\task[#1]{#2}{1}{#3}}

\newcommand{\gd}[2][1]{%
  \put(\value{gdescxpos},\value{gdescypos}){\makebox(0,0){#2}}
  \addtocounter{gdescxpos}{\value{gdw}*#1}}

\newenvironment{gant}[3][]{%
  \setcounter{gdescxpos}{\value{gdw}/2}
  \settowidth{\ghtextw}{#1~}
  \setcounter{ghtextsz}{\ghtextw/\unitlength}
  \setcounter{gtask}{0}
  \setcounter{gwidth}{#2*\value{gdw}}
  \setcounter{gheight}{#3*\value{gdh}}
  \setcounter{gtwidth}{\value{gwidth}+\value{ghtextsz}+5}
  \setcounter{gtheight}{\value{gheight}+\value{gvtextsz}+5}
  \setcounter{gxxheight}{\value{gtheight}-\value{gvtextsz}}
  \setcounter{gveclen}{\value{gwidth}+5}
  \begin{picture}(\value{gtwidth},\value{gtheight})%
    (-\value{ghtextsz},-\value{gxxheight})
    \put(0,0){\vector(1,0){\value{gveclen}}}
    \multiput(0,-1)(\value{gdw},0){#2}{\line(0,1){2}}}{%
  \end{picture}}

\newenvironment{histogram}[3][]{%
  \begin{gant}[#1]{#2}{#3}\setcounter{gdescxpos}{0}}{\end{gant}}
