User Tools

Site Tools


latex:lottime:tikz

lottime diagrams in tikz

For PDF output, or at a Windows system, using tikz may be better.

Since tikz is a higher level language for describing pictures, the amount of code needed to create a diagram is reduced. Unlike the pstricks version which has a lottime.sty file, here a bunch of definitions in the main file are created.

The common code:

\def\numtime{75}% Number of time units
\def\numlots{15}% Number of lots (+ 1)
\def\tlength{1.2em}% Unit length of time
\def\llength{1.2em}% Unit length of lot
\def\tlen{\tlength / 2}
\def\llen{\llength / 2}
% 'lot' and 'batch', used both horizontally and vertically.
\def\lot(#1)(#2,#3)#4{\lots(#1,#1)(#2,#3)(red!15,{#4})}
\def\batch(#1,#2)(#3,#4)#5{\lots(#1,#2)(#3,#4)(green!10,{#5})}

The numtime value defines the number of units at the time axis, while the numlots value defines the number of lots in the diagram. The tlength length defines the length of one time unit in the diagram, while llength defines the size of a single lot. Note that the latter contains names (and a lot number at the front), so it should be high enough for text.

The other definitions are sort of fixed, the lot and batch macros corresponds with the same macros defined in the pstricks version, except that they define a colour as well (the red!15 and green!10 names). Use white as colour to get the same output as the pstricks version.

Horizontal diagrams

For horizontal diagrams, use the following lots macro:

% #1 first lot number of batch
% #2 last lot number of batch
% #3 start time
% #4 end time
% #5 fill color
% #6 text
% Horizontal 'lots'
\def\lots(#1,#2)(#3,#4)(#5,#6)%
{%
    \fill[#5] (\tlength * #3, -\llength * #1) rectangle (\tlength * #4, -\llength - \llength * #2);
    \draw   (\tlength * #3, -\llength * #1) rectangle (\tlength * #4, -\llength - \llength * #2);
    \draw   (\tlen * #3 + \tlen * #4, -\llen - \llen * #1 - \llen * #2) node[anchor=mid] {#6};
}

This macro is the generic definition of lots and batches. Note that text cannot be rotated here (the pstricks version does have macros for that), since it is considered to be bad for readability by tikz.

The lot and batch macros defined above use this macro for the actual rendering of lots in the diagram.

The diagram itself is just a few additional lines:

% Horizontal picture
\begin{tikzpicture}
\draw (0, -\llength * \numlots) grid[xstep=5 *\tlength, ystep=\llength, ultra thin] (\tlength * \numtime, 0);
\draw[thick] (0, -\llength - \llength * \numlots) -- (0, 0) -- (\tlength * \numtime, 0);
% time labeling
\foreach \x in {0,5,..., \numtime} \draw (\tlength * \x, 0) node[above] {\x};
% lot numbers
\foreach \x in {0,2, ..., \numlots} \draw (0, \llen - \llength * \x) node[left] {\x};
\lots(0,0)(0,3.5)(red!20,Lot 0)
\lots(1,2)(1,5)(blue!20,Lot 1)
%\input{simdata}
\end{tikzpicture}

After opening a tikz picture, first a grid is drawn (you may want to change the xstep and/or ystep settings). The second line draws the axes.

The two \foreach lines draw the values of the time and lot axes, with an additional \draw you can add labels to the figure. The next step is to draw all the lots being shown in the diagram. You can do this manually by using the \lots macro, or you can \input{} entries generated by the lottime.py program from a simulation.

Vertical diagrams

The vertical diagrams work very much like the horizontal diagrams, except the axes are swapped, so the initial grid, axes, and labels are drawn in a different way, all text is rotated, and the \lots macro changes.

% #1 first lot number of batch
% #2 last lot number of batch
% #3 start time
% #4 end time
% #5 fill color
% #6 text
% Vertical 'lots'
\def\lots(#1,#2)(#3,#4)(#5,#6)%
{%
    \fill[#5] (\llength * #1, \tlength * #3) rectangle (\llength + \llength * #2, \tlength * #4);
    \draw     (\llength * #1, \tlength * #3) rectangle (\llength + \llength * #2, \tlength * #4);
    \draw   (\llen * #1 + \llen * #2 + \llen, \tlen * #3 + \tlen * #4) node[anchor=mid, rotate=90] {#6};
}

The \lots macros for vertical diagrams.

And the diagram is created as follows:

\begin{tikzpicture}
\draw (0, 0) grid[xstep=\llength, ystep=5 * \tlength, ultra thin] (\llength * \numlots, \tlength * \numtime);
\draw[thick] (\llength * \numlots, 0) -- (0, 0) -- (0, \tlength * \numtime);
% time labeling
\foreach \x in {0,5,..., \numtime} \draw (-1em, \tlength * \x) node[rotate=90] {\x};
% lot numbers
\foreach \x in {0,2, ..., \numlots} \draw (\llen + \llength * \x, -1em) node[rotate=90] {\x};
% From here, nothing changes compared to the horizontal diagram.
\lots(0,0)(0,3.5)(red!20,Lot 0)
\lots(1,2)(1,5)(blue!20,Lot 1)
%\input{simdata}
\end{tikzpicture}

Note that only the \lots macro, and drawing of the grid, labels, and axes changes.

latex/lottime/tikz.txt · Last modified: Wednesday, 24 November 2010 : 10:33:01 by hat