| 1 |
% \iffalse |
| 2 |
%% File: histogr.dtx Copyright (C) 1987-1997 Rainer Sch\"opf |
| 3 |
% |
| 4 |
% It may be distributed and/or modified under the |
| 5 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 6 |
% of this license or (at your option) any later version. |
| 7 |
% The latest version of this license is in |
| 8 |
% http://www.latex-project.org/lppl.txt |
| 9 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 10 |
% version 2005/12/01 or later. |
| 11 |
% |
| 12 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 13 |
%<package>\ProvidesPackage{histogr} |
| 14 |
%<package> [1997/02/13 v1.01 Histogram (RmS)] |
| 15 |
% |
| 16 |
%<*driver> |
| 17 |
\documentclass{ltxdoc} |
| 18 |
\usepackage{histogr} |
| 19 |
\GetFileInfo{histogr.sty} |
| 20 |
\begin{document} |
| 21 |
\title{Drawing histogram bars inside the \LaTeX\ |
| 22 |
{\sf picture}--environment\thanks{This file |
| 23 |
has version number \fileversion, last |
| 24 |
revised \filedate.}} |
| 25 |
\author{Rainer Sch\"opf} |
| 26 |
\date{\filedate} |
| 27 |
\maketitle |
| 28 |
\DocInput{histogr.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 |
% |
| 35 |
% \CheckSum{92} |
| 36 |
% |
| 37 |
% \changes{1.01}{1997/02/13}{Version 1.0a converted to \LaTeXe |
| 38 |
% documentation format.} |
| 39 |
% |
| 40 |
% \begin{abstract} |
| 41 |
% This article describes an enhancement of the \LaTeX\ |
| 42 |
% {\sf picture}--environment to draw histogram bars. |
| 43 |
% \end{abstract} |
| 44 |
% |
| 45 |
% \section{User interface} |
| 46 |
% |
| 47 |
% \DescribeMacro{\histogram} |
| 48 |
% This is a macro collection to draw histogram bars inside a |
| 49 |
% {\sf picture}--environment. Use is as follows: |
| 50 |
% |
| 51 |
% \verb+\histogram+($x_0$,$y_0$)($x_1$,$y_1$)...($x_n$,$y_n$) |
| 52 |
% |
| 53 |
% The coordinate pairs specify the upper left corner of |
| 54 |
% the histogram bars, i.e. |
| 55 |
% this will draw a horizontal line from $(x_i,y_i)$ to $(x_{i+1},y_i)$, |
| 56 |
% then a vertical line from $(x_{i+1},y_{i})$ to $(x_{i+1},y_{i+1})$ |
| 57 |
% \DescribeMacro{\noverticallines} |
| 58 |
% \DescribeMacro{\verticallines} |
| 59 |
% if \verb+\noverticallines+ was specified, |
| 60 |
% else from $(x_{i+1},y_{0})$ to $(x_{i+1},\max(y_{i},y_{i+1}))$. |
| 61 |
% |
| 62 |
% Default is \verb+\verticallines+. |
| 63 |
% $y_{0}$ should be less or equal the minimum of all the ${y_i}$ |
| 64 |
% (i.e. other cases have not been tested). |
| 65 |
% |
| 66 |
% Let's start with an example: to get the following picture: |
| 67 |
% |
| 68 |
%\begin{center} |
| 69 |
%\setlength{\unitlength}{1mm} |
| 70 |
%\begin{picture}(100,65)(-10,-15) |
| 71 |
% |
| 72 |
%\thicklines |
| 73 |
%\put(0,-3){\vector(0,1){50}} |
| 74 |
%\put(-3,0){\vector(1,0){90}} |
| 75 |
%\thinlines |
| 76 |
% |
| 77 |
%\put(0,0){\line(0,-1){2}} |
| 78 |
%\put(2,0){\line(0,-1){2}} |
| 79 |
%\put(20,0){\line(0,-1){2}} |
| 80 |
%\put(22,0){\line(0,-1){2}} |
| 81 |
%\put(40,0){\line(0,-1){2}} |
| 82 |
%\put(42,0){\line(0,-1){2}} |
| 83 |
%\put(60,0){\line(0,-1){2}} |
| 84 |
%\put(62,0){\line(0,-1){2}} |
| 85 |
%\put(0,-1){\makebox(2,0)[t]{\small 1}} |
| 86 |
%\put(20,-1){\makebox(2,0)[t]{\small 2}} |
| 87 |
%\put(40,-1){\makebox(2,0)[t]{\small 3}} |
| 88 |
%\put(60,-1){\makebox(2,0)[t]{\small 4}} |
| 89 |
%\put(70,-1){\makebox(0,0)[t]{ml}} |
| 90 |
%\put(0,10){\line(-1,0){2}} |
| 91 |
%\put(0,20){\line(-1,0){2}} |
| 92 |
%\put(-3,8){\makebox(0,4)[r]{5}} |
| 93 |
%\put(-3,18){\makebox(0,4)[r]{10}} |
| 94 |
%\put(-3,30){\makebox(0,4)[r]{n}} |
| 95 |
%\put(15,-10){Behandler 1} |
| 96 |
%\histogram(0,0)(0,4)(2,4)(4,4)(6,0)(8,10)(10,8)(12,6)(14,4) |
| 97 |
% (16,14)(18,8)(20,18)(22,18)(24,8)(26,0)(28,10)(30,2) |
| 98 |
% (32,12)(34,4)(36,6)(38,6)(40,18)(42,10)(44,14)(46,4) |
| 99 |
% (48,8)(50,4)(52,6)(54,4)(56,6)(58,2)(60,2)(62,0) |
| 100 |
%\end{picture} |
| 101 |
%\end{center} |
| 102 |
% I used these \LaTeX\ commands: |
| 103 |
% \begin{verbatim} |
| 104 |
% \setlength{\unitlength}{1mm} |
| 105 |
% \begin {picture}(100,65)(-10,-15) |
| 106 |
% |
| 107 |
% \thicklines |
| 108 |
% \put(0,-3){\vector(0,1){50}} |
| 109 |
% \put(-3,0){\vector(1,0){90}} |
| 110 |
% \thinlines |
| 111 |
% |
| 112 |
% \put(0,0){\line(0,-1){2}} |
| 113 |
% \put(2,0){\line(0,-1){2}} |
| 114 |
% \put(20,0){\line(0,-1){2}} |
| 115 |
% \put(22,0){\line(0,-1){2}} |
| 116 |
% \put(40,0){\line(0,-1){2}} |
| 117 |
% \put(42,0){\line(0,-1){2}} |
| 118 |
% \put(60,0){\line(0,-1){2}} |
| 119 |
% \put(62,0){\line(0,-1){2}} |
| 120 |
% |
| 121 |
% \put(0,-1){\makebox(2,0)[t]{\small 1}} |
| 122 |
% \put(20,-1){\makebox(2,0)[t]{\small 2}} |
| 123 |
% \put(40,-1){\makebox(2,0)[t]{\small 3}} |
| 124 |
% \put(60,-1){\makebox(2,0)[t]{\small 4}} |
| 125 |
% \put(70,-1){\makebox(0,0)[t]{ml}} |
| 126 |
% |
| 127 |
% \put(0,10){\line(-1,0){2}} |
| 128 |
% \put(0,20){\line(-1,0){2}} |
| 129 |
% |
| 130 |
% \put(-3,8){\makebox(0,4)[r]{5}} |
| 131 |
% \put(-3,18){\makebox(0,4)[r]{10}} |
| 132 |
% \put(-3,30){\makebox(0,4)[r]{n}} |
| 133 |
% |
| 134 |
% \put(15,-10){Behandler 1} |
| 135 |
% |
| 136 |
% \histogram(0,0)(0,4)(2,4)(4,4)(6,0)(8,10)(10,8)(12,6)(14,4) |
| 137 |
% (16,14)(18,8)(20,18)(22,18)(24,8)(26,0)(28,10)(30,2) |
| 138 |
% (32,12)(34,4)(36,6)(38,6)(40,18)(42,10)(44,14)(46,4) |
| 139 |
% (48,8)(50,4)(52,6)(54,4)(56,6)(58,2)(60,2)(62,0) |
| 140 |
% \end{picture} |
| 141 |
%\end{verbatim} |
| 142 |
% |
| 143 |
% \StopEventually{} |
| 144 |
% |
| 145 |
% \section{Implementation} |
| 146 |
% |
| 147 |
% \begin{macrocode} |
| 148 |
%<*package> |
| 149 |
% \end{macrocode} |
| 150 |
% |
| 151 |
% \begin{macro}{\hist@x} |
| 152 |
% \begin{macro}{\hist@y} |
| 153 |
% \begin{macro}{\hist@ystart} |
| 154 |
% Here's how it is implemented: first we allocate three counters that |
| 155 |
% are needed later on. \verb+\hist@x+ and \verb+\hist@y+ are the |
| 156 |
% $x$ and $y$ coordinate of the {\em current point}, i.e. the point |
| 157 |
% that serves as a start for the next box of the histogram. |
| 158 |
% \verb+\hist@ystart+ holds the $y$ coordinate of the first point, |
| 159 |
% i.e. $y_{0}$. |
| 160 |
% \begin{macrocode} |
| 161 |
\newcount\hist@x |
| 162 |
\newcount\hist@y |
| 163 |
\newcount\hist@ystart |
| 164 |
% \end{macrocode} |
| 165 |
% \end{macro} |
| 166 |
% \end{macro} |
| 167 |
% \end{macro} |
| 168 |
% \begin{macro}{\noverticallines} |
| 169 |
% \begin{macro}{\verticallines} |
| 170 |
% We need a switch to decide if the vertical lines of the histogram |
| 171 |
% boxes are to be drawn from $y_{i}$ to $y_{i+1}$ or from $y_{0}$ |
| 172 |
% to $\max(y_{i}, y_{i+1})$. Default is the latter. |
| 173 |
% \begin{macrocode} |
| 174 |
\newif\ifhist@vert |
| 175 |
|
| 176 |
\let\verticallines\hist@verttrue |
| 177 |
\let\noverticallines\hist@vertfalse |
| 178 |
|
| 179 |
\hist@verttrue |
| 180 |
% \end{macrocode} |
| 181 |
% \end{macro} |
| 182 |
% \end{macro} |
| 183 |
% \begin{macro}{\histogram} |
| 184 |
% The \verb+\histogram+ command |
| 185 |
% takes the starting point as argument and initializes the counters. |
| 186 |
% \verb+\hist@x+, \verb+\hist@y+ and \verb+\hist@ystart+ are set to |
| 187 |
% $x_{0}$, $y_{0}$ and $y_{0}$, respectively. |
| 188 |
% \begin{macrocode} |
| 189 |
\def\histogram(#1,#2){\hist@x #1 \hist@y #2 \hist@ystart\hist@y |
| 190 |
% \end{macrocode} |
| 191 |
% Then the macro \verb+\hist@next+ is used. |
| 192 |
% \begin{macrocode} |
| 193 |
\hist@next} |
| 194 |
% \end{macrocode} |
| 195 |
% \end{macro} |
| 196 |
% \begin{macro}{\hist@next} |
| 197 |
% \verb+\hist@next+ looks at the next token to see if there is |
| 198 |
% another |
| 199 |
% open parentheses. If this is the case it calls \verb+\hist@box+, |
| 200 |
% otherwise \verb+\hist@end+. |
| 201 |
% \begin{macrocode} |
| 202 |
\def\hist@next{\@ifnextchar ({\hist@box}{\hist@end}} |
| 203 |
% \end{macrocode} |
| 204 |
% \end{macro} |
| 205 |
% \begin{macro}{\hist@box} |
| 206 |
% The macro \verb+\hist@box+ does nearly all the work. |
| 207 |
% The first thing to do is to set the temporary counter |
| 208 |
% \verb+\@tempcnta+ |
| 209 |
% to $x_{i+1} - x_{i}$. Remember that \verb+\hist@x+ is the $x$ |
| 210 |
% coordinate of the last point (i.e. $x_{i}$) whereas the macros |
| 211 |
% first argument is $x_{i+1}$. So we write |
| 212 |
% \begin{macrocode} |
| 213 |
\def\hist@box(#1,#2){\@tempcnta -\hist@x |
| 214 |
\advance\@tempcnta #1 |
| 215 |
% \end{macrocode} |
| 216 |
% The next step is easy: draw the horizontal part of the histogram |
| 217 |
% box. |
| 218 |
% The line starts at $(x_{i},y_{i})$ and has length |
| 219 |
% \verb+\@tempcnta\unitlength+. |
| 220 |
% \begin{macrocode} |
| 221 |
\ifnum \@tempcnta >\z@ |
| 222 |
\put(\hist@x,\hist@y){\line(1,0){\@tempcnta}}\else |
| 223 |
\put(\hist@x,\hist@y){\line(-1,0){-\@tempcnta}}\fi |
| 224 |
% \end{macrocode} |
| 225 |
% Now set \verb+\hist@x+ to $x_{i+1}$: |
| 226 |
% \begin{macrocode} |
| 227 |
\hist@x #1 |
| 228 |
% \end{macrocode} |
| 229 |
% If \verb+\verticallines+ was set we |
| 230 |
% first set \verb+\@tempcnta+ to $\max(y_{i},y_{i+1})$: |
| 231 |
% \begin{macrocode} |
| 232 |
\ifhist@vert |
| 233 |
\ifnum \hist@y >#2 \@tempcnta\hist@y |
| 234 |
\else \@tempcnta #2 \fi |
| 235 |
% \end{macrocode} |
| 236 |
% then we set \verb+\@tempcntb+ to the same value and |
| 237 |
% \verb+\@tempcnta+ to the length of the line to draw. |
| 238 |
% \begin{macrocode} |
| 239 |
\@tempcntb\@tempcnta |
| 240 |
\advance\@tempcnta -\hist@ystart |
| 241 |
% \end{macrocode} |
| 242 |
% We draw the line |
| 243 |
% \begin{macrocode} |
| 244 |
\put(\hist@x,\@tempcntb){\line(0,-1){\@tempcnta}}% |
| 245 |
% \end{macrocode} |
| 246 |
% which finishes this case. |
| 247 |
% \begin{macrocode} |
| 248 |
\else |
| 249 |
% \end{macrocode} |
| 250 |
% In the other case (i.e. if \verb+\noverticallines+ was set) |
| 251 |
% we have to draw a line from $y_{i}$ to $y_{i+1}$. |
| 252 |
% We set \verb+\@tempcnta+ to $y_{i+1} - y_{i}$ |
| 253 |
% \begin{macrocode} |
| 254 |
\@tempcnta -\hist@y |
| 255 |
\advance\@tempcnta #2 |
| 256 |
% \end{macrocode} |
| 257 |
% and draw the line. |
| 258 |
% \begin{macrocode} |
| 259 |
\ifnum \@tempcnta >\z@ |
| 260 |
\put(\hist@x,\hist@y){\line(0,1){\@tempcnta}}\else |
| 261 |
\put(\hist@x,\hist@y){\line(0,-1){-\@tempcnta}}\fi |
| 262 |
% \end{macrocode} |
| 263 |
% Thus endeth the drawing. |
| 264 |
% \begin{macrocode} |
| 265 |
\fi |
| 266 |
% \end{macrocode} |
| 267 |
% Finally we set \verb+\hist@y+ to $y_{i+1}$ and call |
| 268 |
% \verb+\hist@next+ to look for the next coordinate pair. |
| 269 |
% \begin{macrocode} |
| 270 |
\hist@y #2\hist@next} |
| 271 |
% \end{macrocode} |
| 272 |
% \end{macro} |
| 273 |
% \begin{macro}{hist@end} |
| 274 |
% There is only one thing we left out: what if there is no more |
| 275 |
% open parenthesis? That's the easy part: do nothing. |
| 276 |
% \begin{macrocode} |
| 277 |
\def\hist@end{} |
| 278 |
% \end{macrocode} |
| 279 |
% \end{macro} |
| 280 |
% Frank Mittelbach suggested that the $x$--coordinate should |
| 281 |
% specify the midpoint of the histogram bar, not the upper left |
| 282 |
% corner. However, I don't see how this will work if the bars |
| 283 |
% have different widths. What do you think about it? |
| 284 |
% |
| 285 |
% Well, that's all. Use it and enjoy. |
| 286 |
% |
| 287 |
% \Finale |
| 288 |
% |