diff options
Diffstat (limited to 'graphics/pstricks/contrib/pst-bar')
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/Makefile | 68 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/README | 17 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar-doc.bib | 66 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar-doc.pdf | bin | 0 -> 114763 bytes | |||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar-doc.tex | 738 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar-docDE.pdf | bin | 0 -> 121106 bytes | |||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar-docDE.tex | 736 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar.orig | 420 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar.pro | 30 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar.sty | 10 | ||||
-rw-r--r-- | graphics/pstricks/contrib/pst-bar/pst-bar.tex | 409 |
11 files changed, 2494 insertions, 0 deletions
diff --git a/graphics/pstricks/contrib/pst-bar/Makefile b/graphics/pstricks/contrib/pst-bar/Makefile new file mode 100644 index 0000000000..7c55f49a68 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/Makefile @@ -0,0 +1,68 @@ +# `Makefile' for `pst-bar.pdf', hv, 2008/11/26 + +.SUFFIXES : .tex .ltx .dvi .ps .pdf .eps + +PACKAGE = pst-bar + +MAIN = $(PACKAGE)-doc + +TDS = ~/PSTricks/PSTricks-TDS + +LATEX = latex + +ARCHNAME = $(MAIN)-$(shell date +%y%m%d) + +ARCHFILES = $(PACKAGE).sty $(PACKAGE).tex $(PACKAGE).pro $(MAIN).tex README Changes Makefile + +all : doc clean +doc: $(MAIN).pdf + +$(MAIN).pdf : $(MAIN).ps + GS_OPTIONS=-dAutoRotatePages=/None ps2pdf $< + +$(MAIN).ps : $(MAIN).dvi + dvips $< + +$(MAIN).dvi : $(MAIN).tex + $(LATEX) $< + $(LATEX) $< + if ! test -f $(basename $<).glo ; then touch $(basename $<).glo; fi + if ! test -f $(basename $<).idx ; then touch $(basename $<).idx; fi + makeindex -s gglo.ist -t $(basename $<).glg -o $(basename $<).gls \ + $(basename $<).glo + makeindex -t $(basename $<).ilg -s pst-doc.ist -o $(basename $<).ind \ + $(basename $<).idx + bibtex $(MAIN) + $(LATEX) $< + $(LATEX) $< + +clean : + $(RM) $(addprefix $(MAIN), .log .aux .glg .glo .gls .ilg .idx .ind .tmp .toc .out ) + $(RM) $(addprefix $(MAIN), .dvi .ps .bbl .blg) + $(RM) *.csv +veryclean : clean + $(RM) $(addprefix $(MAIN), .pdf) + +arch : + zip $(ARCHNAME).zip $(ARCHFILES) + +tds: + cp -u Changes $(TDS)/doc/generic/$(PACKAGE)/ + cp -u README $(TDS)/doc/generic/$(PACKAGE)/ + cp -u $(MAIN).pdf $(TDS)/doc/generic/$(PACKAGE)/ +# + cp -u Changes $(TDS)/tex/latex/$(PACKAGE)/ + cp -u $(PACKAGE).sty $(TDS)/tex/latex/$(PACKAGE)/ +# + cp -u Changes $(TDS)/tex/generic/$(PACKAGE)/ + cp -u $(PACKAGE).tex $(TDS)/tex/generic/$(PACKAGE)/ +# + cp -u Changes $(TDS)/dvips/$(PACKAGE)/ + cp -u $(PACKAGE).pro $(TDS)/dvips/$(PACKAGE)/ +# + cp -u Changes $(TDS)/source/$(PACKAGE)/ + cp -u $(MAIN).tex $(TDS)/source/$(PACKAGE)/ + cp -u $(MAIN).bib $(TDS)/source/$(PACKAGE)/ + cp -u Makefile $(TDS)/source/$(PACKAGE)/ + +# EOF diff --git a/graphics/pstricks/contrib/pst-bar/README b/graphics/pstricks/contrib/pst-bar/README new file mode 100644 index 0000000000..cab7a017cb --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/README @@ -0,0 +1,17 @@ +With pst-bar, one may use pstricks to produce bar charts directly from a data +file. This package is still in the beta stage --- the usual caveats pertaining +to beta software apply. Additional features and improved (in both content and +layout) documentation will be provided as the code stabilizes. + +INSTALLATION: + +pst-bar consists of three files: pst-bar.sty, pst-bar.tex, and pst-bar.pro. +Place the first two anywhere your installation can find them (typically +$LOCALTEXMF/tex/latex/pst-bar for pst-bar.sty and +$LOCALTEXMF/tex/generic/pst-bar for pst-bar.tex). Place pst-bar.pro where dvips +can find it, typically in the pstricks subdirectory of your dvips directory +(i.e., $LOCALTEXMF/dvips/pstricks). + +DOCUMENTATION: + +See pst-bar-doc.ps or pst-bar-doc.pdf for details on using pst-bar. diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar-doc.bib b/graphics/pstricks/contrib/pst-bar/pst-bar-doc.bib new file mode 100644 index 0000000000..7997765a24 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar-doc.bib @@ -0,0 +1,66 @@ +@STRING{dtk = {{D}ie {\TeX}nische {K}om{\"o}die} } + +@Book{PostScript, + Author = {Kollock, Nikolai G.}, + Title = {PostScript richtig eingesetzt: vom Konzept zum + praktischen Einsatz}, + Publisher = {IWT}, + Address = {Vaterstetten}, + year = 1989, +} + +@Manual{pstricks, + Title = {PSTricks - {\PS} macros for Generic TeX}, + Author = {Timothy Van Zandt}, + Organization = {}, + Address = {\url{http://www.tug.org/application/PSTricks}}, + Note = {}, + year = 1993, +} + + +@Manual{pdftricks, + Title = {PSTricks Support for pdf}, + Author = {Herbert Voss}, + Organization = {}, + Address = {\url{http://PSTricks.de/pdf/pdfoutput.phtml}}, + Note = {}, + year = 2002, +} + +@Manual{miwi, + Title = {References for \TeX{} and Friends}, + Author = {Michael Wiedmann and Peter Karp}, + Organization = {}, + Address = {\url{http://www.miwie.org/tex-refs/}}, + Note = {}, + year = 2003, +} + + +@Book{companion, + author = {Michel Goosens and Frank Mittelbach and Sebastian Rahtz and Denis Roegel and Herbert Vo{\ss}}, + title = {The {\LaTeX} {G}raphics {C}ompanion}, + publisher = {{Addison-Wesley Publishing Company}}, + edition = second, + year = {2007}, + address = {Reading, Mass.} +} + +@Book{PSTricks2, + author = {Herbert Vo\ss}, + title = {\texttt{PSTricks} -- {G}rafik f\"ur \TeX{} und \LaTeX}, + edition = {5.}, + publisher = {DANTE -- Lehmanns}, + year = {2008}, + address = {Heidelberg/Hamburg} +} + +@Book{LaTeXRef, + author = {Herbert Vo\ss}, + title = {\LaTeX\ Referenz}, + edition = {1.}, + publisher = {DANTE -- Lehmanns}, + year = {2007}, + address = {Heidelberg/Hamburg} +} diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar-doc.pdf b/graphics/pstricks/contrib/pst-bar/pst-bar-doc.pdf Binary files differnew file mode 100644 index 0000000000..e1c445c0cd --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar-doc.pdf diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar-doc.tex b/graphics/pstricks/contrib/pst-bar/pst-bar-doc.tex new file mode 100644 index 0000000000..74fb070238 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar-doc.tex @@ -0,0 +1,738 @@ +%% $Id: pst-bar-doc.tex 63 2008-11-26 18:00:46Z herbert $ +\documentclass[11pt,english,BCOR10mm,DIV12,bibliography=totoc,parskip=false,smallheadings + headexclude,footexclude,oneside]{pst-doc} +\listfiles +\usepackage{pst-bar}% +\let\pstBarVersion\fileversion +\usepackage{booktabs}% +\usepackage{filecontents}% +\usepackage{verbatim}% +\makeatletter +\def\kernhack#1#2{% + \begingroup + \setbox\z@\hbox{#1#2}% + \dimen@\wd\z@ + \setbox\z@\hbox{#1{}#2}\advance\dimen@-\wd\z@ + \ifdim\dimen@=\z@\else\kern\dimen@\fi + \endgroup +} +\def\switch#1#2{% + \begingroup + \def\@switch##1#1##2\@nil#1##3\@stop{% + \def\reserved@a{##3}% + \ifx\reserved@a\@empty#2\else + \setbox\z@\hbox{##1#1}% + \setbox\tw@\hbox{\kernhack{#1}{##2}\switch{#1}{##2}}% + \dimen@\wd\tw@\advance\dimen@\wd\z@% + \wd\z@\dimen@% + \rlap{\hb@xt@\dimen@{\hfil\unhbox\tw@}}% + \box\z@ + \fi + }% + \@switch#2\@nil#1\@nil#1\@stop + \endgroup +} +% Given an e-mail address of the form abc@def.ghi.jkl, reverses it to be jkl +% ghi. def. abc@ +\def\switchemail#1{\expandafter\@switchemail#1\@stop} +% Helper function for \switchemail. Note the \copy, because \kernhack will +% destroy the box otherwise. Need to do some funky stuff because of catcodes. +\begingroup +\makeatother +\def\tmp#1#2#3{% + \gdef#1##1@##2#2{% + \begingroup + \setbox#3\hbox{\switch{.}{##2}}% + \switch{@}{##1@\copy#3}% + \endgroup + }% +} +\makeatletter +\tmp\@switchemail\@stop\@tempboxa +\endgroup +\makeatother + +\usepackage[T1]{fontenc}% + +\begin{filecontents*}{example1.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 1, 2, 3 +\end{filecontents*} + +\begin{filecontents*}{example2.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 0.5, 1.5, 1 +\end{filecontents*} + +\begin{filecontents*}{example3.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 0.5, 1.5, 1 + 0.75, 1.6, 0.9 + 0.9, 2.2, 2.5 +\end{filecontents*} + +\begin{filecontents*}{example4.csv} + Set 1, Set 2, Set 3 + 1, 0, 3 +\end{filecontents*} + +\begin{filecontents*}{example5.csv} + 0, 2, 0 +\end{filecontents*} + +\begin{filecontents*}{example6.csv} + Set 1, Set 2, Set 3 + 1.3, 2.5, 0.9 +\end{filecontents*} + +\begin{filecontents*}{example7.csv} + 0.7, 1.9, 0.4 + 1.2, 2.7, 1.4 +\end{filecontents*} + +\begin{document} +\title{\texttt{pst-bar}\\ Bar charts for \texttt{pstricks}\\ + {\small v.\pstBarVersion}} +\author{Alan Ristow} +\docauthor{Alan Ristow\\Herbert Vo\ss} +\date{\today} +\maketitle + + \begin{abstract} + With \LPack{pst-bar}, one may use \LPack{pstricks} to produce bar charts + directly from a data file. This package is still in the beta stage --- the + usual caveats pertaining to beta software apply. Additional features and + improved (in both content and layout) documentation will be provided as the + code stabilizes. + \end{abstract} + +\section{Introduction} + \LPack{pst-bar} uses the power and flexibility of + \LPack{pstricks}~\cite{vanzandt:93} to draw bar charts from data stored in a + comma-delimited file. Several solutions exist for drawing bar charts for + \TeX\ and \LaTeX\ documents. The obvious solution is to use an external + program, such as \Index{gnuplot} or \Index{Matlab}, that can save bar charts in a format + that may be read directly into \TeX\ or \LaTeX. This approach has the + disadvantage that extra effort is required to produce charts with a uniform + appearance that blend well with the other graphics in a document. In many + cases the text in the chart can be typeset by \LaTeX\ with the aid of the + \LPack{psfrag} or \verb|psfragx| packages (for diagrams created with Matlab, + this process can be accelerated by \Index{LaPrint}, a Matlab program written + specifically for this purpose~\cite{linneman:04}). However, some programs + write the text elements in Encapsulated Postscript files in such a way that + the \LPack{psfrag}-based options cannot work. + + Bar charts may also be drawn using the built-in drawing tools provided by + \TeX\ and \LaTeX. This is the approach used by the \LPack{histogr} + package~\cite{schopf:97}, which is intended to draw histograms, but can be + used to draw very simple bar charts. It also appears to be the approach + used by the \LPack{bar} package~\cite{bleser:94} for \LaTeX\ 2.09, which + defines an environment for drawing bar charts. However, the built-in + drawing tools are quite limited and work on the \LPack{bar} package appears + to have ceased after 1994. + + More sophisticated drawing tools have been developed for use with \TeX\ and + \LaTeX, notably \verb|eepic|, \verb|texdraw| and \verb|latexdraw|, + \verb|LaTeXPiX|, MetaPost, \LPack{mfpic}, and \LPack{pstricks}. Any of these + tools might be used to create bar charts; however, none of them has + built-in support for doing so, and bar charts must be drawn using the + ``brute force'' method --- manually drawing boxes to represent the bars in + the chart. Depending on the tool, the axes of the chart might also need to + be drawn manually. The \LPack{pst-bar} package is intended to automate the + process of drawing bar charts using \LPack{pstricks}. + + There are currently two existing solutions for producing bar charts using + \verb|pstricks|. One is the aforementioned brute force method in which a + series of \Lcs{psframe}s are drawn with suitable heights, widths, and + colors to produce the desired chart~\cite{voss:barcharts}. While this + method works admirably and provides maximum flexibility, it is tedious and + labor-intensive. The other option is the \LPack{bardiag} package, which + essentially automates this approach~\cite{stepanyan:03}. While effective, + \LPack{bardiag} requires a number of external packages to function, uses + \LaTeX\ to perform its mathematical operations, and is not compatible with + plain \TeX. + + These issues are all avoided by \LPack{pst-bar}. It calls only on packages + that are part of the \verb|pstricks| family, provides extensive + customization features, relies on Postscript for nearly all mathematical + operations, and should be compatible with plain \TeX\ (untested). + \verb|pst-bar| provides commands for reading data from a comma-delimited + file to produce and label a bar chart. Multiple series of data may be + plotted in either clustered or stacked form, and bars may be plotted either + horizontally or vertically. An additional option allows block charts that + display the differences between subsequent rows of data in the data file + (see Section~\ref{sec:block}). + + At this stage, \verb|pst-bar| should be regarded as beta software. + Revisions to the code between this release and the first stable release are + not guaranteed to be backward compatible. + + \section{Drawing a Bar Chart} + Drawing a bar chart with \verb|pst-bar| is a three-step process: (i) read + the data file, (ii) draw the bars, and (iii) draw the axes. The first two + step are accomplished directly with \verb|pst-bar|; the third requires the + \LPack{pst-plot} package, a standard part of \verb|pstricks|. + + The following sections address the data file format, how to load data from + the file, and how to use the data to produce a bar chart. + + \subsection{Data File Format} + The data file must be comma-delimited with each row containing the same + number of entries. A header row is permitted, but no header entry may + contain commas or \Lcs{par} commands (including \verb|\\|). One of the + data files used for the examples in this manual looks like + \verbatiminput{example1.csv}% + In this case, \verb|Set 1|, \verb|Set 2|, and \verb|Set 3| are the + headers. The subsequent rows, hereafter referred to as \emph{data rows}, + contain the data associated with these headers. The file is arranged in a + pseudo-columnar fashion, so that the data associated with \verb|Set 1| + are \verb|1| and \verb|1|, those with \verb|Set 2| are \verb|2| and + \verb|2|, and so on. After these data are plotted, the bars will be + labeled with the text from the header row. + + \emph{Warning!} There are two very important conditions on the data + within the file: + \begin{itemize} + \item All data outside of the header must be numeric. If there is no + header row, all data in the file must be numeric. + \item Each row must contain the same number of entries. + \end{itemize} + Failure to meet these conditions may result in Postscript errors or (less + frequently) incorrectly labeled or drawn bar charts. + + How these data are plotted depends on the type of plot desired. See + Sections~\ref{sec:cluster}--\ref{sec:block} and the examples in + Section~\ref{sec:examples} for more on this. + + \subsection{Reading the Data File} + Use the command \verb|\readpsbardata| to read from a data file: + \begin{verbatim} + \readpsbardata[<options>]{<data>}{<filename>}\end{verbatim} + For the data, simply specify a macro name not currently in use. + + The available options are: + \begin{center} + \begin{tabular}{ll} + \toprule + Parameter & Definition\\ + \midrule + \Lkeyword{header} & \verb|true| if first line of data file is header + row\\ + & \verb|false| otherwise\\ + & Default: \verb|true|\\ + \bottomrule + \end{tabular} + \end{center} + If \verb|header| is set to \verb|false|, \verb|pst-bar| will assume that + no header is present and treat the first line of the file as data. + + \subsection{Drawing the Bars} + \label{sec:drawing_bars}% + The command \verb|\psbarchart| draws the bars for the bar chart. + \begin{verbatim} + \psbarchart[<options>]{<data>}\end{verbatim} + For \verb|<data>|, use the macro name supplied to \Lcs{readpsbardata}. + Bars are grouped in columns that are one \Lcs{psxunit} wide, and the + number of bars appearing in a single column is equal to the number of + data rows in the data file. It labels the bottom of each column with the + headers from the data file if \Lkeyword{header} was set to to \verb|true| + during \Lcs{readpsbardata}. It only creates the bars and the column + labels --- axes and frames must be provided separately. + + The available options are: + \begin{center} + \begin{tabular}{ll} + \toprule + Parameter & Definition\\ + \midrule + \Lkeyword{chartstyle} & \Lkeyval{cluster} produces a cluster of bars\\ + & \Lkeyval{stack} stacks the cluster into a single + column\\ + & \Lkeyval{block} prints a ``floating'' bar with a + nonzero minimum\\ + & Default: \Lkeyval{cluster}\\ + \Lkeyword{barstyle} & Name(s) of bar style(s) to use for each bar\\ + & Default: \verb|{black,darkgray,gray,lightgray,white,red,green,blue}|\\ + \Lkeyword{barcolsep} & Factor determining whitespace between + columns\\ + & Default: \verb|0.4|\\ + \Lkeyword{barsep} & Factor determining whitespace between bars\\ + & (\Lkeyval{cluster} and \Lkeyval{block} charts)\\ + & Default: \verb|0.0|\\ + \Lkeyword{barlabelrot} & Angle of rotation of the column labels\\ + & Default: \verb|0|\\ + \Lkeyword{orientation} & \Lkeyval{vertical} for vertically drawn bars\\ + & \Lkeyval{horizontal} for horizontally drawn + bars\\ + & Default: \Lkeyval{vertical}\\ + \bottomrule% + \end{tabular} + \end{center} + + The number of \verb|barstyle|s specified must equal or exceed the number + of bar segments in each column; otherwise, a Postscript error will + result. For the \Lkeyval{cluster} and \Lkeyval{stack} \verb|chartstyle|s, this + is equal to the number of data rows in the data file; for the + \Lkeyval{block} \verb|chartstyle|, it is equal to half the number of data + rows. Furthermore, when specifying the list of \verb|barstyle|s, the + styles must be listed between curly braces, e.g., +\begin{BDef} +\Lcs{psbarchart}\OptArgs\Largb{\ldots} +\end{BDef} + + The \Lkeyword{barstyle}s available by default are \Lkeyval{red}, \Lkeyval{green}, + \Lkeyval{blue}, \Lkeyval{black}, \Lkeyval{white}, \Lkeyval{gray}, \Lkeyval{lightgray}, + and \Lkeyval{darkgray}. Each of these plots a bar of the named color with + square corners and a black outline. New \Lkeyword{barstyle}s may be defined + using the \Lcs{newpsbarstyle} command described in + Section~\ref{sec:customizing}. + + Figure~\ref{fig:bar_layout} shows how the \Lcs{psbarchart} lays out the + bars for the default \Lkeyword{chartstyle}, \Lkeyval{cluster}. For the + \Lkeyval{stack} \Lkeyword{chartstyle}, the \Lkeyword{barsep} option is ignored. + + \begin{figure}[t] + \centering% + \begin{pspicture}(0,0)(4in,2in)% + \psframe[linestyle=dashed](0,0)(4in,2in)% + \psframe[linestyle=none,fillstyle=hlines,hatchangle=45,% + hatchcolor=lightgray,hatchwidth=0.4pt,hatchsep=8pt](0,0)(1in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](0.2in,0in)(0.45in,0.8in)% + \psframe[fillcolor=lightgray,fillstyle=solid](0.55in,0in)(0.8in,1.1in)% + \psline[linestyle=dotted](1in,0in)(1in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](1.2in,0in)(1.45in,0.6in)% + \psframe[fillcolor=lightgray,fillstyle=solid](1.55in,0in)(1.8in,0.4in)% + \psline[linestyle=dotted](2in,0in)(2in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](2.2in,0in)(2.45in,0.4in)% + \psframe[fillcolor=lightgray,fillstyle=solid](2.55in,0in)(2.8in,0.3in)% + \psline[linestyle=dotted](3in,0in)(3in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](3.2in,0in)(3.45in,1.1in)% + \psframe[fillcolor=lightgray,fillstyle=solid](3.55in,0in)(3.8in,0.9in)% + \rput[b](0.5in,1.8in){\small$\mathtt{\backslash psxunit}$}% + \psline{->}(0.2in,1.87in)(0in,1.87in)% + \psline{->}(0.8in,1.87in)(1in,1.87in)% + \psline(0.45in,0.85in)(0.45in,1.3in)% + \psline(0.55in,1.15in)(0.55in,1.3in)% + \rput[l](0.8in,1.25in){\small$\mathtt{barsep} \times + \mathtt{\backslash psxunit}$}% + \psline{->}(0.75in,1.25in)(0.55in,1.25in)% + \psline{->}(0.25in,1.25in)(0.45in,1.25in)% + \psline{->}(0.6in,0.9in)(0.8in,0.9in)% + \psline{->}(1.2in,0.9in)(1in,0.9in)% + \rput[l](1.25in,0.9in){\small$0.5 \times \mathtt{barcolsep} \times + \mathtt{\backslash psxunit}$}% + \end{pspicture} + \caption{\label{fig:bar_layout}% + Schematic diagram for the layout of the bar chart. The hatched area + marks the region in which data from the first column of the data file + will be plotted. Bar width is equal to $[(1 - \mathtt{barsep} - 0.5 + \times \mathtt{barcolsep}) \times \mathtt{\backslash psxunit}] / N$, + where $N$ is the number of bars in the column. + }% + \end{figure} + +\subsection{Customizing the Chart}\label{sec:customizing}% + To add a custom bar style, use the command \Lcs{newpsbarstyle}, +\begin{BDef} +\Lcs{newpsbarstyle}\Largb{<name>}\Largb{<definition>} +\end{BDef} + The name is a text string not currently used by any other + \Lkeyword{barstyle}, and the definition may consist of any \LPack{pstricks} + key or group of keys applicable to \Lcs{psframe}. For example, the + \Lkeyval{red} \Lkeyword{barstyle} is defined as +\begin{BDef} +\Lcs{newpsbarstyle}\Largb{red}\Largb{\Lkeyset{fillcolor=red},\Lkeyset{fillstyle=solid},\Lkeyword{framearc}=0} +\end{BDef} + + To customize the type used to set the column labels, redefine + \Lcs{psbarlabel}. For example, to have the label set in small italics, + use +\begin{BDef} +\LcsStar{renewcommand}\Lcs{psbarlabel}\Largb{\small\itshape} +\end{BDef} + By default, \Lcs{psbarlabel} sets the column label in the current text + font. + + To adjust the spacing between the bars and the column labels, redefine + \Lcs{psbarlabelsep}. Note that it is defined as a command, not a + length, and should be redefined using \Lcs{renewcommand*}. By default + it is \verb|0pt|. + + Finally, the data from the file may be scaled and manipulated using the + command \Lcs{psbarscale}, +\begin{BDef} +\Lcs{psbarscale}\Largr{<scale>}\Largb{<Postscript code>} +\end{BDef} + inspired by Herbert Vo\ss' \verb|\pstScale| from + \LPack{pstricks-add}~\cite{voss:04}. The data are scaled by the value in + parentheses and may be further manipulated with Postscript code. For + example, to plot the logarithm of the input data one would use + \Lcs{psbarscale}\Largr{1}\Largb{log}. The Postscript code is applied to the data + prior to scaling. + + \section{The Chart Styles} + As described in Section~\ref{sec:drawing_bars}, there are three different + \Lkeyword{chartstyle} options. The default, \Lkeyval{cluster} is the common bar + chart with bars clustered into groups of related data. The second option, + \Lkeyval{stack}, draws a series of bars stacked atop one another instead of + sitting side-by-side in a cluster. The third, \Lkeyval{block}, draws clustered + bars between two data points, thus displaying a range of values instead of + a single value. + + The following sections describe each \Lkeyword{chartstyle} in detail, including + how it uses the input data. Examples of use are provided in each case. Full + examples, including axes, appear in Section~\ref{sec:examples}. + + \subsection{\texttt{cluster}} + \label{sec:cluster}% + For a \Lkeyval{cluster} chart, each comma-delimited variable within a given + row represents a bar in a different column. Each row represents a new set + of bars. Thus the file + \verbatiminput{example1.csv}% + produces the bars + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,3)% + \readpsbardata{\data}{example1.csv}% + \psbarchart[barstyle={red,blue}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][1.75in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,3)% + \readpsbardata{\data}{example1.csv}% + \psbarchart[barstyle={red,blue}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage}% + \hfill% + + \subsection{\texttt{stack}} + For a \Lkeyval{stack} chart, each column of the chart has only one bar. This + bar consists of as many segments as the data file has data rows, with the + data from each row stacked onto the previous row. Thus, the file + \verbatiminput{example2.csv}% + produces the bars + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},chartstyle=stack]{\data}% + \end{pspicture} + \end{minipage} + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=stack]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + \hfill% + + Notice that these bars are wider than those produced by + \Lkeyset{chartstyle=cluster} because the bars are stacked vertically + instead of being clustered along the bottom axis. A bar width similar to + that of the \Lkeyval{cluster} chart in the previous section could be + obtained by setting \Lkeyword{xunit}\verb|=0.25in|. + + \subsection{\texttt{block}} + \label{sec:block}% + For a \verb|block| chart, each bar represents a range of values. As such, + each bar requires two data lines from the data file, one denoting the + upper limit and the other the lower limit. If there are multiple pairs of + data lines, they are plotted in a clustered fashion. If there are an odd + number of data lines, the last line of the data file is ignored. Thus, + the file + \verbatiminput{example3.csv}% + produces the bars + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,3.5)% + \readpsbardata{\data}{example3.csv}% + \psbarchart[barstyle={red,blue},chartstyle=block]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][1.5in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,3.5)% + \readpsbardata{\data}{example3.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=block]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + \section{Examples} + \label{sec:examples}% + Basic examples of each type including axes and gridlines: + + \begin{verbatim} +\begin{filecontents*}{example2.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 0.5, 1.5, 1 +\end{filecontents*}\end{verbatim} + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},chartstyle=stack]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=stack]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},chartstyle=block]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=block]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + Using \verb|\newpsbarstyle|: + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \newpsbarstyle{yellowhatch}{framearc=0.5,fillstyle=hlines*,rot=45,fillcolor=yellow}% + \newpsbarstyle{redoutline}{framearc=0.5,fillcolor=black,linecolor=red,linewidth=1.5pt}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,redoutline}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.75in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\newpsbarstyle{yellowhatch}{framearc=0.5,% + fillstyle=hlines*,rot=45,fillcolor=yellow}% +\newpsbarstyle{redoutline}{framearc=0.5,% + fillcolor=black,linecolor=red,% + linewidth=1.5pt}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,% + redoutline}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + Using \verb|[orientation=horizontal]|: + + \hfill% + \begin{minipage}[b]{2in}% + \psset{unit=0.5in}% + \newpsbarstyle{yellowhatch}{framearc=0.5,fillstyle=hlines*,rot=45,fillcolor=yellow}% + \newpsbarstyle{redoutline}{framearc=0.5,fillcolor=black,linecolor=red,linewidth=1.5pt}% + \begin{pspicture}(0,-0.5)(4,3.5)% + \psgrid[yunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(3,1)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=x,ticks=x](0,0)(3,3)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,redoutline},orientation=horizontal]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.75in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\newpsbarstyle{yellowhatch}{framearc=0.5,% + fillstyle=hlines*,rot=45,fillcolor=yellow}% +\newpsbarstyle{redoutline}{framearc=0.5,% + fillcolor=black,linecolor=red,% + linewidth=1.5pt}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,% + redoutline}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + Sophisticated effects are possible using multiple calls to + \Lcs{psbarchart} in a single chart. For example, a particular important + bar may be highlighted in green by splitting the data into two files, one + containing a zero for the data value to be highlighted, and the other + containing zeros for all of the data \emph{except} the value to be + highlighted. + + \vspace*{2ex}% + + File 1 (\verb|example4.csv|): + \verbatiminput{example4.csv}% + + File 2 (\verb|example5.csv|): + \verbatiminput{example5.csv}% + Notice that the second file has no header row in order to prevent the bar + labels from being printed twice. + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example4.csv}% + \psbarchart[barstyle={blue}]{\data}% + \readpsbardata[header=false]{\data}{example5.csv}% + \psbarchart[barstyle={green}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example4.csv}% + \psbarchart[barstyle={blue}]{\data}% + \readpsbardata[header=false]{\data}% + {example5.csv}% + \psbarchart[barstyle={green}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + Different chart styles may also be combined in a single bar chart. + + \vspace*{2ex}% + + File 1 (\verb|example6.csv|): \verbatiminput{example6.csv}% + + File 2 (\verb|example7.csv|): \verbatiminput{example7.csv}% + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example6.csv}% + \psbarchart[barstyle={black}]{\data}% + \readpsbardata[header=false]{\data}{example7.csv}% + \psbarchart[barstyle={red},chartstyle=block,barcolsep=0.8]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example6.csv}% + \psbarchart[barstyle={black}]{\data}% + \readpsbardata[header=false]{\data}% + {example7.csv}% + \psbarchart[barstyle={red},chartstyle=block,% + barcolsep=0.8]{\data}% +\end{pspicture} +\end{pspicture}\end{verbatim} + \end{minipage} + + \section{To Do} + \begin{itemize} + \item Provide commands to facilitate legend creation and placement. + \item Allow the automatic labeling of bars with values from the data + file. + \item Allow the automatic labeling of bars with labels of the user's + choice. + \item Improve header parsing to allow commas within header entries. + \item Add error-checking to ensure that each row of the data file + contains the same number of entries, throwing an error in \TeX\ or + \LaTeX\ if not. + \item Improve documentation. + \end{itemize} + +\nocite* +\bibliographystyle{plain}% +\bibliography{pst-bar-doc}% + +\printindex + + +\end{document} diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar-docDE.pdf b/graphics/pstricks/contrib/pst-bar/pst-bar-docDE.pdf Binary files differnew file mode 100644 index 0000000000..80afdd67fc --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar-docDE.pdf diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar-docDE.tex b/graphics/pstricks/contrib/pst-bar/pst-bar-docDE.tex new file mode 100644 index 0000000000..d053993e86 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar-docDE.tex @@ -0,0 +1,736 @@ +%% $Id: pst-bar-doc.tex 63 2008-11-26 18:00:46Z herbert $ +%% geaendert am 7.2.09 ch. roemer +\documentclass[11pt,ngerman,BCOR10mm,DIV12,bibliography=totoc,parskip=false,smallheadings + headexclude,footexclude,oneside]{pst-doc} +\listfiles + +\usepackage[T1]{fontenc} +\usepackage[ansinew]{inputenc} +\usepackage{babel} + +\usepackage{pst-bar}% +\let\pstBarVersion\fileversion +\usepackage{booktabs}% +\usepackage{filecontents}% +\usepackage{verbatim}% +\makeatletter +\def\kernhack#1#2{% + \begingroup + \setbox\z@\hbox{#1#2}% + \dimen@\wd\z@ + \setbox\z@\hbox{#1{}#2}\advance\dimen@-\wd\z@ + \ifdim\dimen@=\z@\else\kern\dimen@\fi + \endgroup +} +\def\switch#1#2{% + \begingroup + \def\@switch##1#1##2\@nil#1##3\@stop{% + \def\reserved@a{##3}% + \ifx\reserved@a\@empty#2\else + \setbox\z@\hbox{##1#1}% + \setbox\tw@\hbox{\kernhack{#1}{##2}\switch{#1}{##2}}% + \dimen@\wd\tw@\advance\dimen@\wd\z@% + \wd\z@\dimen@% + \rlap{\hb@xt@\dimen@{\hfil\unhbox\tw@}}% + \box\z@ + \fi + }% + \@switch#2\@nil#1\@nil#1\@stop + \endgroup +} +% Given an e-mail address of the form abc@def.ghi.jkl, reverses it to be jkl +% ghi. def. abc@ +\def\switchemail#1{\expandafter\@switchemail#1\@stop} +% Helper function for \switchemail. Note the \copy, because \kernhack will +% destroy the box otherwise. Need to do some funky stuff because of catcodes. +\begingroup +\makeatother +\def\tmp#1#2#3{% + \gdef#1##1@##2#2{% + \begingroup + \setbox#3\hbox{\switch{.}{##2}}% + \switch{@}{##1@\copy#3}% + \endgroup + }% +} +\makeatletter +\tmp\@switchemail\@stop\@tempboxa +\endgroup +\makeatother + +\usepackage[T1]{fontenc}% + +\begin{filecontents*}{example1.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 1, 2, 3 +\end{filecontents*} + +\begin{filecontents*}{example2.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 0.5, 1.5, 1 +\end{filecontents*} + +\begin{filecontents*}{example3.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 0.5, 1.5, 1 + 0.75, 1.6, 0.9 + 0.9, 2.2, 2.5 +\end{filecontents*} + +\begin{filecontents*}{example4.csv} + Set 1, Set 2, Set 3 + 1, 0, 3 +\end{filecontents*} + +\begin{filecontents*}{example5.csv} + 0, 2, 0 +\end{filecontents*} + +\begin{filecontents*}{example6.csv} + Set 1, Set 2, Set 3 + 1.3, 2.5, 0.9 +\end{filecontents*} + +\begin{filecontents*}{example7.csv} + 0.7, 1.9, 0.4 + 1.2, 2.7, 1.4 +\end{filecontents*} + +\begin{document} +\title{\texttt{pst-bar}\\ Balken- und Säulendiagramme mit \texttt{pstricks}\\ + {\small v.\pstBarVersion}} +\author{Alan Ristow} +\docauthor{Alan Ristow\\Herbert Vo\ss\\Juliane Horn (\"Ubersetzung)} +\date{\today} +\maketitle + + \begin{abstract} + Mithilfe von \LPack{pst-bar} kann man \LPack{pstricks} verwenden, um Balkendiagramme + direkt aus einer Daten-Datei zu erzeugen. Dieses Paket befindet sich allerdings noch im + Beta-Stadium -- die üblichen Warnungen bezüglich Beta-Software treffen + daher zu. Es wird zusätzliche Merkmale und verbesserte Dokumentationen (den Inhalt + sowie die Ausstattung betreffend) geben, wenn sich der Code stabilisiert. + \end{abstract} + +\section{Einführung} + Aufgrund der Leistung und Flexibilität von \LPack{pstricks} [1] ist es möglich, mit + \LPack{pst-bar} Balkendiagramme zu erstellen, deren Einzelheiten in einer + mit Komma abgetrennten Datei gespeichert sind. + Es gibt mehrere Lösungen, um Säulendiagramme in \TeX\ und \LaTeX\ - + Dokumenten zu "`zeichnen"'. + Die offensichtliche Lösung ist, ein externes Programm wie \Index{gnuplot} + oder \Index{Matlab} zu verwenden, das Balkendiagramme in einem Format speichert, welches + direkt von \TeX\ oder \LaTeX\ gelesen werden kann. Diese Methode hat den Nachteil, dass + zusätzlicher Aufwand nötig ist, um den Diagrammen ein einheitliches Erscheinungsbild zu + geben, welches zu anderen Grafiken im Dokument passt. In vielen Fällen kann der Diagrammtext + von \LaTeX\ mithilfe der Pakete \LPack{psfrag} oder \verb|psfragx| eingefügt werden + (das Matlab-Programm \Index{LaPrint} kann diesen Prozess bei Matlab-Diagrammen + beschleunigen, da es speziell für diesen Zweck entwickelt wurde [2]). Jedoch schreiben + einige Programme die Textelemente in EPS (Encapsulated Postscript)-Dateien, sodass die + Optionen von \LPack{psfrag} nicht funktionieren. + +Balkendiagramme können aber auch mit den eingebauten Zeichenwerkzeugen in +\TeX\ und \LaTeX\ gezeichnet werden. Dafür wird das \LPack{histogr} Paket [3] verwendet, +welches neben Histogrammen auch sehr einfache Balkendiagramme erstellen kann. Es scheint eine +Annäherung an das \LPack{bar} Paket [4] für \LaTeX\ 2.09 zu sein, da es eine neue Umgebung +für das Zeichnen von Säulendiagrammen definiert. Allerdings sind die eingebauten +Zeichenwerkzeuge begrenzt und die Arbeit am \LPack{bar} Paket wurde wohl nach 1994 beendet. + +Es wurden technisch verfeinerte Zeichenwerkzeuge für \TeX\ und +\LaTeX\ entwickelt; die bekanntesten sind \verb|eepic|, \verb|texdraw| und \verb|latexdraw|, +\verb|LaTeXPiX|, MetaPost, \LPack{mfpic}, und \LPack{pstricks}. Mit jedem dieser Mittel +können Balkendiagramme gesetzt werden; jedoch besitzt keines eine eingebaute Unterstützung +für diese, sodass die Diagramme mit der "`Brachialgewalt"'--Methode angefertigt werden +müssen, das +bedeutet ein manuelles Einzeichnen von Kästen, welche die Balken im Diagramm +darstellen. Je nach Werkzeug kann es sein, dass auch die Achsen manuell eingezeichnet +werden müssen. Das \LPack{pst-bar} Paket soll den Prozess des Zeichnens von Balken- und +Säulendiagrammen unter Verwendung von \LPack{pstricks} automatisieren. + +Derzeit gibt es zwei Möglichkeiten für die Erstellung von Balkendiagrammen mit +\verb|pstricks|. Die Erste ist die oben genannte Brachialgewalt-Methode, bei der eine Reihe +von +\Lcs{psframe}s mit passenden Höhen, Breiten und Farben gezeichnet werden, um zum gewünschten +Ergebnis zu gelangen [5]. Zwar ist diese Möglichkeit vortrefflich und bietet den größten +Spielraum, allerdings ist sie mühsam und arbeitsintensiv. Die zweite Option ist das +\LPack{bardiag} Paket; es automatisiert im Wesentlichen [6] die Vorgehensweise mit brachialer +Gewalt im. +Dieser Ansatz ist wirkungsvoll, jedoch benötigt \LPack{bardiag} zahlreiche externe Pakete. +Weiterhin verwendet es \LaTeX\ , um mathematische Befehle durchzuführen und es ist nicht +kompatibel mit dem normalen \TeX. + +Durch \LPack{pst-bar} werden diese Probleme vermieden. Es beruft sich ausschließlich auf +Pakete der \verb|pstricks|-Familie, stellt umfassende Anpassungsfunktionen zur Verfügung, +baut auf Postscript für fast alle mathematischen Operationen und sollte mit dem einfachen +\TeX\ kompatibel sein (bisher ungetestet). Damit Balkendiagramme angefertigt und beschriftet +werden können, benutzt \verb|pst-bar| Befehle, um die Angaben der durch Komma +abgegrenzten Datei zu lesen. Vielfache Datenreihen können dabei entweder gesammelt oder +gestapelt grafisch dargestellt werden; die Balken können horizontal oder vertikal +eingezeichnet werden. Eine zusätzliche Option ermöglicht es, Blockdiagramme zu erzeugen, +welche die Unterschiede zwischen den nachfolgenden Reihen von Daten in der Datendatei zeigen +(siehe auch Kapitel ~\ref{sec:block}). + +Zu diesem Zeitpunkt sollte \verb|pst-bar| noch als Beta-Software betrachtet werden. Es wird +nicht garantiert, dass die Änderungen am Code, welche zwischen dieser Ausgabe und der ersten +dauerhaften Ausgabe auftreten, auch rückwärts kompatibel sind. + +\section{Erstellen von Balken- und Säulendiagrammen} +Das Zeichnen von Balkendiagrammen mit \verb|pst-bar| erfolgt in drei Schritten: +(i) Lesen der Datendatei, (ii) Zeichnen der Balken und (iii) Einzeichnen der Achsen. Die +ersten beiden Schritte erfolgen direkt durch \verb|pst-bar|. Für den dritten ist das +\LPack{pst-plot} Paket notwendig, das fester Bestandteil von \verb|pstricks| ist. + +Die folgenden Abschnitte befassen sich mit dem Format der Datendatei, mit dem Laden von Daten +aus der Datei und mit dem Erstellen eines Balkendiagramms mithilfe dieser Daten. + +\subsection{Format der Datendatei} +Die Datei mit den Daten muss durch Komma begrenzt sein und jede Reihe muss die gleiche Anzahl +an Einträgen enthalten. Eine Kopfzeile ist erlaubt, aber kein Eintrag in dieser Zeile darf +Kommas oder \Lcs{par} Befehle beinhalten (gilt ebenso für \verb|\\|). Eine der Dateien, +welche für diese Dokumentation benutzt werden, sieht so aus: \verbatiminput{example1.csv}% +In diesem Fall sind \verb|Set 1|, \verb|Set 2|, und \verb|Set 3| die Kopfzeilen. Die +nachfolgenden Reihen, später als \emph{data rows} gekennzeichnet, umfassen die Daten, die mit +den Überschriften verknüpft werden. Die Datei wird in einem säulenähnlichen Stil angeordnet, +sodass man mit \verb|Set 1| die Daten \verb|1| und \verb|1| verbindet, mit \verb|Set 2| die +Daten \verb|2| und \verb|2| und so weiter. Zuerst werden die Daten grafisch dargestellt und +anschließend mit dem Text der Kopfzeile beschriftet. + +\emph{Achtung!} Es gibt zwei sehr wichtige Bedingungen für die Daten innerhalb der Datei: +\begin{itemize} + \item Alle Daten außerhalb der Kopfzeile müssen numerisch sein. Falls keine Kopfzeile + vorhanden ist, müssen alle Daten der Datei numerisch sein. + \item Jede Zeile muss dieselbe Anzahl von Einträgen haben. +\end{itemize} +Werden diese Bedingungen nicht eingehalten, können Postscript-Fehler oder (seltener) falsch +beschriftete oder gezeichnete Balkendiagramme die Folge sein. + +Wie diese Dateien grafisch dargestellt werden, hängt von der Art des gewünschten Diagramms +ab. Siehe dazu Kapitel ~\ref{sec:cluster} -- \ref{sec:block} und die Beispiele in +Kapitel~\ref{sec:examples}. + +\subsection{Lesen der Datendatei} +Der Befehl \verb|\readpsbardata| liest die Datei: +\begin{verbatim} + \readpsbardata[<options>]{<data>}{<filename>} +\end{verbatim} +Geben Sie für die Daten einen Makro-Namen an, den Sie noch nicht benutzen. + +Die verfügbaren Optionen sind: +\begin{center} +\begin{tabular}{ll} +\toprule +Parameter & Definition\\ +\midrule +\Lkeyword{header} & \verb|true|, wenn die erste Zeile der Datei eine Kopfzeile ist\\ + & \verb|false|, wenn \verb|true| nicht zutrifft\\ + & Standard: \verb|true|\\ +\bottomrule +\end{tabular} +\end{center} + +Setzt man \verb|header| auf \verb|false|, so geht \verb|pst-bar| davon aus, dass kein +header (Kopfzeile) existiert und die erste Zeile wird als Daten-Zeile angesehen. + +\subsection{Einzeichnen der Balken} +\label{sec:drawing_bars}% +Der Befehl \verb|\psbarchart| zeichnet die Balken für das Diagramm. +\begin{verbatim} + \psbarchart[<options>]{<data>} +\end{verbatim} +Für \verb|<data>| verwenden Sie bitte den Makro-Namen, den Sie bei \Lcs{readpsbardata} +ausgewählt hatten. +Die Säulen werden in Spalten eingeteilt, die eine \Lcs{psxunit} breit sind. Die Anzahl der +Säulen in einer Spalte entspricht dabei der Zahl der Datenreihen in einer Datei. Die +Unterseite jeder Spalte wird mit den Überschriften (header) der Datei beschriftet, wenn man +bei \Lcs{readpsbardata} für \Lkeyword{header} \verb|true| angegeben hat. Allerdings +wird nur die Balken- und Säulenbeschriftung erstellt -- der Rahmen und die Achsen müssen extra +bestimmt werden. + +Die verfügbaren Optionen sind: +\begin{center} +\begin{tabular}{ll} +\toprule +Parameter & Definition\\ +\midrule +\Lkeyword{chartstyle} & \Lkeyval{cluster} erzeugt eine Gruppe von Balken\\ + & \Lkeyval{stack} sammelt die Gruppen in einer Einzelspalte\\ + & \Lkeyval{block} erstellt einen schwebenden Balken (Minimum ist nicht 0)\\ + & Standard: \Lkeyval{cluster}\\ + \Lkeyword{barstyle} & Name(n) des Balken-Stils für jeden Balken\\ + & Standard: \verb|{black,darkgray,gray,lightgray,white,red,green,blue}|\\ + \Lkeyword{barcolsep} & beeinflusst den Zwischenraum zwischen den Spalten\\ + & Standard: \verb|0.4|\\ + \Lkeyword{barsep} & beeinflusst den Zwischenraum zwischen den Balken \\ + & (\Lkeyval{cluster} und \Lkeyval{block} Diagramme)\\ + & Standard: \verb|0.0|\\ + \Lkeyword{barlabelrot} & Drehwinkel der Spaltenbeschriftung\\ + & Standard: \verb|0|\\ + \Lkeyword{orientation} & \Lkeyval{vertical} für vertikal gezeichnete Balken\\ + & \Lkeyval{horizontal} für horizontal gezeichnete Balken\\ + & Standard: \Lkeyval{vertical}\\ +\bottomrule% +\end{tabular} +\end{center} + +Die Anzahl der angegebenen \verb|barstyle|s muss der Anzahl von Balken in jeder Spalte +entsprechen oder größer als diese sein. Andernfalls entsteht ein Postcript-Fehler. Bei den +\Lkeyval{cluster} und \Lkeyval{stack} \verb|chartstyle|s entspricht dies den Datenreihen in +der Datei; beim \Lkeyval{block} \verb|chartstyle| entspricht es der halben Anzahl +der Datenreihen. Außerdem ist bei der Angabe der \verb|barstyle|s darauf zu achten, dass die +Stile in geschweiften Klammern angegeben werden, wie z.\,B.: +\begin{BDef} +\Lcs{psbarchart}\OptArgs\Largb{\ldots} +\end{BDef} + +Die verfügbaren \Lkeyword{barstyle}s sind standardmäßig \Lkeyval{red}, \Lkeyval{green}, +\Lkeyval{blue}, \Lkeyval{black}, \Lkeyval{white}, \Lkeyval{gray}, \Lkeyval{lightgray}, +und \Lkeyval{darkgray}. Jeder davon erzeugt einen Balken in der angegebenen Farbe mit +rechtwinkligen Ecken und schwarzem Umriss. Mit dem Befehl \Lcs{newpsbarstyle} können +zusätzlich neue \Lkeyword{barstyle}s definiert werden, siehe dazu +Kapitel ~\ref{sec:customizing}. + +Abbildung ~\ref{fig:bar_layout} zeigt, wie \Lcs{psbarchart} die Balken im +Standard-\Lkeyword{chartstyle}, \Lkeyval{cluster}, anlegt. Beim \Lkeyval{stack} +\Lkeyword{chartstyle} wird die \Lkeyword{barsep} Option nicht berücksichtigt. + +\begin{figure}[t] + \centering% + \begin{pspicture}(0,0)(4in,2in)% + \psframe[linestyle=dashed](0,0)(4in,2in)% + \psframe[linestyle=none,fillstyle=hlines,hatchangle=45,% + hatchcolor=lightgray,hatchwidth=0.4pt,hatchsep=8pt](0,0)(1in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](0.2in,0in)(0.45in,0.8in)% + \psframe[fillcolor=lightgray,fillstyle=solid](0.55in,0in)(0.8in,1.1in)% + \psline[linestyle=dotted](1in,0in)(1in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](1.2in,0in)(1.45in,0.6in)% + \psframe[fillcolor=lightgray,fillstyle=solid](1.55in,0in)(1.8in,0.4in)% + \psline[linestyle=dotted](2in,0in)(2in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](2.2in,0in)(2.45in,0.4in)% + \psframe[fillcolor=lightgray,fillstyle=solid](2.55in,0in)(2.8in,0.3in)% + \psline[linestyle=dotted](3in,0in)(3in,2in)% + \psframe[fillcolor=darkgray,fillstyle=solid](3.2in,0in)(3.45in,1.1in)% + \psframe[fillcolor=lightgray,fillstyle=solid](3.55in,0in)(3.8in,0.9in)% + \rput[b](0.5in,1.8in){\small$\mathtt{\backslash psxunit}$}% + \psline{->}(0.2in,1.87in)(0in,1.87in)% + \psline{->}(0.8in,1.87in)(1in,1.87in)% + \psline(0.45in,0.85in)(0.45in,1.3in)% + \psline(0.55in,1.15in)(0.55in,1.3in)% + \rput[l](0.8in,1.25in){\small$\mathtt{barsep} \times + \mathtt{\backslash psxunit}$}% + \psline{->}(0.75in,1.25in)(0.55in,1.25in)% + \psline{->}(0.25in,1.25in)(0.45in,1.25in)% + \psline{->}(0.6in,0.9in)(0.8in,0.9in)% + \psline{->}(1.2in,0.9in)(1in,0.9in)% + \rput[l](1.25in,0.9in){\small$0.5 \times \mathtt{barcolsep} \times + \mathtt{\backslash psxunit}$}% + \end{pspicture} + \caption{\label{fig:bar_layout}% +Schematische Darstellung für das Layout des Balkendiagramms. Die schraffierte Fläche markiert +den Bereich, in dem die Daten der ersten Spalte der Datei dargestellt sind. Die Breite der +Balken entspricht $[(1 - \mathtt{barsep} - 0.5 \times \mathtt{barcolsep}) \times +\mathtt{\backslash psxunit}] / N$, wobei $N$ für die Anzahl der Balken in einer Spalte +steht.}% +\end{figure} + +\subsection{Anpassung des Diagramms}\label{sec:customizing}% +Um einen angefertigten Balkentyp hinzuzufügen, ist der Befehl \Lcs{newpsbarstyle} zu +verwenden: +\begin{BDef} +\Lcs{newpsbarstyle}\Largb{<name>}\Largb{<definition>} +\end{BDef} +Diese Bezeichnung ist eine Textfolge, die derzeitig von keinem anderen \Lkeyword{barstyle} +verwendet wird. Die Definition kann sich aus jedem \LPack{pstricks} Schlüssel bzw. aus jeder +Gruppe von Schlüsseln ergeben, die mit \Lcs{psframe} anwendbar sind. Zum Beispiel wird +\Lkeyval{red} \Lkeyword{barstyle} wie folgt definiert: +\begin{BDef} +\Lcs{newpsbarstyle}\Largb{red}\Largb{\Lkeyset{fillcolor=red},\Lkeyset{fillstyle=solid}, +\Lkeyword{framearc}=0} +\end{BDef} + +Um den Typ, mit dem die Spaltenbezeichnungen festgelegt werden, anzupassen, wird +\Lcs{psbarlabel} neu definiert. Wenn die Beschriftung aus kleinen Kursivbuchstaben bestehen +soll, sieht diese so aus: +\begin{BDef} +\LcsStar{renewcommand}\Lcs{psbarlabel}\Largb{\small\itshape} +\end{BDef} +Üblicherweise erstellt \Lcs{psbarlabel} die Spaltenbeschriftung in der aktuellen Schriftart. + +Um den Abstand zwischen den Säulen und der Spaltenbeschriftung zu regulieren, wird +\Lcs{psbarlabelsep} neu definiert. Dabei ist es als Befehl, nicht als Umfang, definiert und +muss daher mit \Lcs{renewcommand*} wiederdefiniert werden. Als Standard benutzt man \verb|0pt|. + +Am Ende ist es möglich, die Daten der Datei mit \Lcs{psbarscale} anzupassen und zu +manipulieren, wie z.\,B. +\begin{BDef} +\Lcs{psbarscale}\Largr{<scale>}\Largb{<Postscript code>} +\end{BDef} +welches von Herbert Vo\ss' \verb|\pstScale| aus \LPack{pstricks-add} beeinflusst wurde [7]. +Die Daten werden durch den Wert in Klammern eingestuft und können im Weiteren mit dem +Postscript Code gesteuert werden. Für den Fall, dass man den Logarithmus der eingegebenen +Daten grafisch darstellen will, würde man \Lcs{psbarscale}\Largr{1}\Largb{log} benutzen. +Der Postscript Code bezieht sich auf die Daten vor der Skalierung. + +\section{Die Arten von Diagrammen} +Wie bereits in ~\ref{sec:drawing_bars} beschrieben, gibt es drei verschiedene Möglichkeiten +für den Parameter \Lkeyword{chartstyle}. Der Standard-Typ \Lkeyval{cluster} ist ein +allgemeines Balkendiagramm, bei dem die Balken aufgrund ähnlicher Daten gruppiert werden. Die +zweite Option, \Lkeyval{stack}, zeichnet eine Reihe von Säulen aufeinander gestapelt, statt +sie nebeneinander in einer Gruppe anzuordnen. Benutzt man \Lkeyval{block}, die dritte +Alternative, so werden angehäufte Balken zwischen zwei Datenpunkten eingezeichnet und somit +eine Spanne von Werten anstelle eines einzelnen Wertes veranschaulicht. + +Die folgenden Abschnitte beschreiben jeden \Lkeyword{chartstyle} im Detail und erklären, wie +die Eingabedaten verwendet werden. Zusätzlich werden für jeden Fall Muster +gezeigt. Im Kapitel ~\ref{sec:examples} sind vollständige Beispiele einschließlich der Achsen +aufgezeigt. + +\subsection{\texttt{cluster}}\label{sec:cluster}% +In einem \Lkeyval{cluster} Diagramm wird jede Variable in einer Reihe, die durch Kommas +getrennt ist, als ein Balken in einer einzelnen Spalte dargestellt. Jede Reihe steht daher +für eine neue Balkeneinheit. Die Datei +\verbatiminput{example1.csv}% +erzeugt nachstehendes Diagramm: + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,3)% + \readpsbardata{\data}{example1.csv}% + \psbarchart[barstyle={red,blue}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][1.75in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,3)% + \readpsbardata{\data}{example1.csv}% + \psbarchart[barstyle={red,blue}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage}% + \hfill% + +\subsection{\texttt{stack}} +Bei einem \Lkeyval{stack} Diagramm befindet sich in jeder Spalte lediglich ein Balken. Dieser +eine Balken besteht aus so vielen Abschnitten, wie die Datendatei Reihen hat. Jede Reihe wird +auf die Oberkante der Vorigen "`gestapelt"'. Die Datei +\verbatiminput{example2.csv}% +erzeugt folgendes Diagramm:\\ +\vspace*{.5cm}\\ + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},chartstyle=stack]{\data}% + \end{pspicture} + \end{minipage} + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=stack]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + \hfill% + +Beachten Sie, dass diese Säulen hier breiter sind als bei +\Lkeyset{chartstyle=cluster}, da sie bei \Lkeyval{stack} vertikal aufeinander gestapelt +werden, bei \Lkeyval{cluster} allerdings horizontal nebeneinander auf der x-Achse angeordnet +sind. Um eine ähnliche Balkenbreite wie im \Lkeyval{cluster} - Diagramm zu erhalten, stellt +man \Lkeyword{xunit}\verb|=0.25in| ein. + +\subsection{\texttt{block}}\label{sec:block}% +In einem \verb|block| Diagramm kann an jedem Balken eine Reihe von Werten abgelesen werden. +Daher benötigt jede Säule zwei Datenlinien aus der Datei, eine für die Markierung der oberen +und eine für die Markierung der unteren Grenze. Gibt es mehrere Paare von Datenlinien, werden +sie gesammelt dargestellt. Existiert eine ungerade Anzahl von Datenreihen, so wird die letzte +nicht beachtet. +\vspace*{.5cm} + +Aus: \verbatiminput{example3.csv}% +entsteht dieses Diagramm: + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,3.5)% + \readpsbardata{\data}{example3.csv}% + \psbarchart[barstyle={red,blue},chartstyle=block]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][1.5in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,3.5)% + \readpsbardata{\data}{example3.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=block]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + +\section{Beispiele}\label{sec:examples}% +Grundlegende Beispiele für jeden Typ einschließlich Achsen und Gitternetzlinien: + + \begin{verbatim} +\begin{filecontents*}{example2.csv} + Set 1, Set 2, Set 3 + 1, 2, 3 + 0.5, 1.5, 1 +\end{filecontents*}\end{verbatim} + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},chartstyle=stack]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=stack]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},chartstyle=block]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={red,blue},% + chartstyle=block]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + +Verwendung von \verb|\newpsbarstyle|: + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \newpsbarstyle{yellowhatch}{framearc=0.5,fillstyle=hlines*,rot=45,fillcolor=yellow}% + \newpsbarstyle{redoutline}{framearc=0.5,fillcolor=black,linecolor=red,linewidth=1.5pt}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,redoutline}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.75in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\newpsbarstyle{yellowhatch}{framearc=0.5,% + fillstyle=hlines*,rot=45,fillcolor=yellow}% +\newpsbarstyle{redoutline}{framearc=0.5,% + fillcolor=black,linecolor=red,% + linewidth=1.5pt}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,% + redoutline}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + +\vspace*{2cm} + +Verwendung von \verb|[orientation=horizontal]|:\\ + + \hfill% + \begin{minipage}[b]{2in}% + \psset{unit=0.5in}% + \newpsbarstyle{yellowhatch}{framearc=0.5,fillstyle=hlines*,rot=45,fillcolor=yellow}% + \newpsbarstyle{redoutline}{framearc=0.5,fillcolor=black,linecolor=red,linewidth=1.5pt}% + \begin{pspicture}(0,-0.5)(4,3.5)% + \psgrid[yunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(3,1)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=x,ticks=x](0,0)(3,3)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,redoutline},orientation=horizontal]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.75in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\newpsbarstyle{yellowhatch}{framearc=0.5,% + fillstyle=hlines*,rot=45,fillcolor=yellow}% +\newpsbarstyle{redoutline}{framearc=0.5,% + fillcolor=black,linecolor=red,% + linewidth=1.5pt}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example2.csv}% + \psbarchart[barstyle={yellowhatch,% + redoutline}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage}\\ + +Komplexe Effekte sind unter mehrfacher Benennung von \Lcs{psbarchart} in einem einzelnen +Diagramm möglich. Zum Beispiel kann ein besonders wichtiger Balken in grün hervorgehoben +werden, indem man die Daten in zwei Dateien aufgespaltet. Eine enthält eine Null für den +Datenwert, der hervorgehoben werden soll und die andere enthält Nullen für alle anderen +Daten \emph{außer} der Hervorzuhebenden. + +\vspace*{2ex}% + +Datei 1 (\verb|example4.csv|): \verbatiminput{example4.csv}% + +Datei 2 (\verb|example5.csv|): \verbatiminput{example5.csv}% +Beachten Sie, dass die zweite Datei keine Kopfzeile hat, damit die Balkenbeschriftung nicht +doppelt erfolgt. + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example4.csv}% + \psbarchart[barstyle={blue}]{\data}% + \readpsbardata[header=false]{\data}{example5.csv}% + \psbarchart[barstyle={green}]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example4.csv}% + \psbarchart[barstyle={blue}]{\data}% + \readpsbardata[header=false]{\data}% + {example5.csv}% + \psbarchart[barstyle={green}]{\data}% +\end{pspicture}\end{verbatim} + \end{minipage} + +Verschiedene Diagrammarten können auch in einem Balkendiagramm kombiniert werden. + +\vspace*{.5cm}% + +Datei 1 (\verb|example6.csv|): \verbatiminput{example6.csv}% + +Datei 2 (\verb|example7.csv|): \verbatiminput{example7.csv}% + + \hfill% + \begin{minipage}[b]{1.5in}% + \psset{unit=0.5in}% + \begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example6.csv}% + \psbarchart[barstyle={black}]{\data}% + \readpsbardata[header=false]{\data}{example7.csv}% + \psbarchart[barstyle={red},chartstyle=block,barcolsep=0.8]{\data}% + \end{pspicture} + \end{minipage}% + \hfill% + \begin{minipage}[b][2.25in][c]{3.5in}% + \begin{verbatim} +\psset{unit=0.5in}% +\begin{pspicture}(0,-0.5)(3,4.5)% + \psgrid[xunit=1.5in,gridlabels=0,% + subgriddiv=0,griddots=30](0,0)(1,4)% + \psaxes[axesstyle=frame,Ox=0,Dx=1,labels=y,% + ticks=y](0,0)(3,4)% + \readpsbardata{\data}{example6.csv}% + \psbarchart[barstyle={black}]{\data}% + \readpsbardata[header=false]{\data}% + {example7.csv}% + \psbarchart[barstyle={red},chartstyle=block,% + barcolsep=0.8]{\data}% +\end{pspicture} +\end{pspicture}\end{verbatim} + \end{minipage} + +\section{Tipps} +\begin{itemize} + \item Informieren Sie sich über Befehle, um die Erstellung und Platzierung der + Beschriftung zu erleichtern. + \item Erlauben Sie die automatische Beschriftung der Balken mit den Werten der Datendatei. + \item Erlauben Sie die automatische Beschriftung der Balken nach Ihrer Wahl. + \item Verbessern Sie die Syntaxanalyse der Überschrift, um Kommas zwischen den Einträgen + der Kopfzeile zu erlauben. + \item Fügen Sie eine Fehler-Überprüfung hinzu, um sicherzustellen, dass jede Reihe der + Datei dieselbe Anzahl an Einträgen enthält; falls nicht, wird der Fehler in \TeX\ + oder \LaTeX\ übertragen. + \item Verbessern Sie die Dokumentation. +\end{itemize} + +\nocite* +\bibliographystyle{plain}% +\bibliography{pst-bar-doc}% + +\printindex + + +\end{document} diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar.orig b/graphics/pstricks/contrib/pst-bar/pst-bar.orig new file mode 100644 index 0000000000..407c75d749 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar.orig @@ -0,0 +1,420 @@ +\csname PSTBarLoaded\endcsname% +\let\PSTBarLoaded\endinput% +\ifx\PSTplotLoaded\endinput\else\input pst-plot.tex\fi% +\pstheader{pst-bar.pro}% +\input pst-key.tex% + +\def\fileversion{0.7a} +\def\filedate{2004/09/24} +\message{`pst-bar' v\fileversion, \filedate\space (Alan Ristow)}% + +\define@key{psset}{barsep}{\edef\psk@barsep{#1}}% +\define@key{psset}{barcolsep}{\edef\psk@barcolsep{#1}}% +\define@key{psset}{barstyle}{\edef\psk@barstyle{#1}}% +\define@key{psset}{barlabelrot}{\edef\psk@barlabelrot{#1}}% +\setkeys{psset}{barsep=0.0,barcolsep=0.4,barstyle=\@empty,barlabelrot=0}% +% +% chartstyle=cluster|stack|block (0,1,2) +\def\psset@chartstyle#1{\pst@expandafter\psset@@chartstyle{#1}\@nil\psk@chartstyle} +\def\psset@@chartstyle#1#2\@nil#3{% + \ifx#1c\let#3\z@\else + \ifx#1s\let#3\@ne\else + \ifx#1b\let#3\tw@\else + \@pstrickserr{Bad argument: `#1#2'}\@ehpa + \fi + \fi + \fi +}% +\psset@chartstyle{cluster}% +% +% orientation=vertical|horizontal (0,1) +\def\psset@orientation#1{\pst@expandafter\psset@@orientation{#1}\@nil\psk@orientation} +\def\psset@@orientation#1#2\@nil#3{% + \ifx#1h\let#3\p@\else + \ifx#1v\let#3\z@\else + \@pstrickserr{Bad argument: `#1#2'}\@ehpa + \fi + \fi +}% +\psset@orientation{vertical}% + +\def\psset@header#1{% + \pst@expandafter\psset@@header{#1}\@nil\psk@header +}% +\def\psset@@header#1#2\@nil#3{% + \ifx#1t\let#3\z@\else + \ifx#1f\let#3\@ne\else + \@pstrickserr{Bad argument: `#1#2'}\@ehpa + \fi + \fi +}% +\psset@header{true}% + +\def\psbarchart{\def\pst@par{}\pst@object{psbarchart}}% +\def\pstbar@header{\@empty}% +\def\psbarlabel#1{#1}% +\def\psbarlabelsep{0pt}% +\def\psbarscale(#1)#2{% + \def\psbar@mul{#1\space}% + \def\psbar@psop{#2\space}% +} +\def\psbar@mul{1\space}% +\def\psbar@psop{\@empty}% + +\newread\pstbar@file% + +% Define bar chart styles + +\def\psset@barstyle#1{\def\@barstylelist{#1}}% +\def\newpsbarstyle#1#2{\@namedef{psbarcs@#1}{\psset{#2}}}% + +\def\begin@barstyle{\def\pst@tempd{/barstyles [ }}% +\def\add@barstyle{% + \def\pst@code{}% + \ifpsshadow% + \pst@closedshadow% + \fi% + \ifdim\psk@border\p@>\z@% + \pst@addborder% + \fi% + \psk@fillstyle% + \pst@stroke% + \ifpsdoubleline% + \pst@doublestroke% + \fi% + \def\pst@tempa{\strip@pt\psk@orientation}% + \edef\pst@tempd{ \pst@tempd (% + \pst@tempc \psk@cornersize% + xbar1 ybar1 xbar2 ybar2 4 -\pst@tempa\space roll + \psk@dimen% + \tx@Frame% + \pst@code )% + }% +} +\def\end@barstyle{\edef\pst@tempd{ \pst@tempd ] def }}% + +\def\setbarstyle{% + \begin@barstyle% + \expandafter\@setbarstyle\@barstylelist,\@nil\ignorespaces% + \end@barstyle% +}% +\def\@setbarstyle#1,{% + \@@setbarstyle{#1}% + \@ifnextchar\@nil{\@gobble}{\@setbarstyle}% +}% +\def\@@setbarstyle#1{% + \@ifundefined{psbarcs@#1}% + {\@pstrickserr{Custom bar chart style `#1' undefined}\@ehpa}% + {\@nameuse{psbarcs@#1}\add@barstyle}% +}% + +% Default bar chart styles + +\newpsbarstyle{red}{fillcolor=red,fillstyle=solid,framearc=0}% +\newpsbarstyle{green}{fillcolor=green,fillstyle=solid,framearc=0}% +\newpsbarstyle{blue}{fillcolor=blue,fillstyle=solid,framearc=0}% +\newpsbarstyle{black}{fillcolor=black,fillstyle=solid,framearc=0}% +\newpsbarstyle{white}{fillcolor=white,fillstyle=solid,framearc=0}% +\newpsbarstyle{gray}{fillcolor=gray,fillstyle=solid,framearc=0}% +\newpsbarstyle{lightgray}{fillcolor=lightgray,fillstyle=solid,framearc=0}% +\newpsbarstyle{darkgray}{fillcolor=darkgray,fillstyle=solid,framearc=0}% + +\psset@barstyle{black,darkgray,gray,lightgray,white,red,green,blue}% + +\def\readpsbardata{\@ifnextchar[{\readpsbardata@i}{\readpsbardata@i[]}} + +\def\readpsbardata@i[#1]#2#3{% + \def\pst@tempa{#1}% + \ifx\pst@tempa\@empty\else\psset{#1}\fi + \openin\pstbar@file=#3\relax% + \ifeof\pstbar@file% + \@pstrickserr{Data file `#3' not found.}\@ehpa + \else + \def\pst@tempb{\@empty}% + \ifx\psk@header\z@% + \@readpsbarheader% + \fi + \readpsbardata@ii% + \edef\pst@tempb{[\pst@tempb]}% + \let#2\pst@tempb% + \fi + \closein\pstbar@file% +}% + +\def\readpsbardata@ii{% + \read\pstbar@file to \pst@tempa + \ifeof\pstbar@file + \relax + \else + \edef\pst@tempb{\pst@tempb [}% + \expandafter\readpsbardata@iii\pst@tempa,\@nil\ignorespaces% + \edef\pst@tempb{\pst@tempb ]}% + \readpsbardata@ii% + \fi +}% + +\def\readpsbardata@iii#1,{% + \edef\pst@tempb{\pst@tempb #1\space}% + \@ifnextchar\@nil{\@gobble}{\readpsbardata@iii}% +}% + +\def\@readpsbarheader{% + \read\pstbar@file to \pst@tempa + \ifeof\pstbar@file + \relax + \else + \let\pstbar@header\pst@tempa + \fi +}% + +% Apply labels from file header to bar chart columns. +% TODO: Deal with column headings that contain commas. + +% The trimspaces command is (c) Michael Downes 1994 +% (http://www.tug.org/tex-archive/info/aro-bend/answer.015). +\catcode`\Q=3 +\def\psbar@trimspaces#1{% + \begingroup + \aftergroup\toks\aftergroup0\aftergroup{% + \expandafter\trimb\expandafter\noexpand#1Q Q}% + \edef#1{\the\toks0}% +} +\def\trimb#1 Q{\trimc#1Q} +\def\trimc#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1} +\catcode`\Q=11 + +\def\pstbar@xlabels{% + \pst@dima=-0.5pt\relax% + \expandafter\pstbar@xlabels@i\pstbar@header,\@nil\ignorespaces% +}% + +\def\pstbar@xlabels@i#1,{% + \def\pst@tempa{#1}% + \psbar@trimspaces\pst@tempa% + \advance\pst@dima by 1pt% + \def\pst@tempb{\strip@pt\pst@dima}% + \uput[-90]{\psk@barlabelrot}(\pst@tempb,-\psbarlabelsep){\psbarlabel{\pst@tempa}}% + \@ifnextchar\@nil{\@gobble}{\pstbar@xlabels@i}% +}% + +\def\pstbar@labelcount#1{% + \pst@dima=0pt\relax% + \expandafter\pstbar@labelcount@i\pstbar@header,\@nil\ignorespaces% + \let#1\pst@dima% +}% + +\def\pstbar@labelcount@i#1,{% + \advance\pst@dima by 1pt% + \@ifnextchar\@nil{\@gobble}{\pstbar@labelcount@i}% +}% + +\def\pstbar@ylabels{% + \pstbar@labelcount{\pst@dima}% + \advance\pst@dima by 0.5pt% + \expandafter\pstbar@ylabels@i\pstbar@header,\@nil\ignorespaces% +}% + +\def\pstbar@ylabels@i#1,{% + \def\pst@tempa{#1}% + \psbar@trimspaces\pst@tempa% + \advance\pst@dima by -1pt% + \def\pst@tempb{\strip@pt\pst@dima}% + \uput[180]{\psk@barlabelrot}(-\psbarlabelsep,\pst@tempb){\psbarlabel{\pst@tempa}}% + \@ifnextchar\@nil{\@gobble}{\pstbar@ylabels@i}% +}% + +\def\psbarchart@i#1{% + \pst@killglue% + \begingroup% + \use@par% + \psbarchart@ii{#1}% + \endgroup% + \ignorespaces% +}% + +\def\psbarchart@ii#1{% + \begin@SpecialObj% + + % Save contents of \pst@code and load start-of-path code + % into \pst@tempc + + \let\pst@tempb\pst@code% + \def\pst@code{}% + \solid@star% + \let\pst@tempc\pst@code% + + % Load end-of-path code into \pst@tempd and restore original + % contents of \pst@code + + \begin@barstyle% + \expandafter\@setbarstyle\@barstylelist,\@nil\ignorespaces% + \end@barstyle% + \let\pst@code\pst@tempb% + + % Draw bar chart + + \pst@checknum\psk@barcolsep\pst@tempa% + \pst@checknum\psk@barsep\pst@tempb% + \ifx\psk@orientation\z@ % vertical + \pst@dima=\psxunit% + \pst@dimb=\psyunit% + \def\pst@tempc{true}% + \else\ifx\psk@orientation\p@ % horizontal + \pst@dima=\psyunit% + \pst@dimb=\psxunit% + \def\pst@tempc{false}% + \else + \@pstrickserr{Bad orientation specification}\@ehpa + \fi\fi + \ifcase\psk@chartstyle% chartstyle=cluster + \addto@pscode{% + \pst@tempd% + /BARDATA #1 def + /nbars BARDATA length def + /ncols BARDATA 0 get length def + /colwidth \pst@number\pst@dima def + /barcolsep \pst@tempa \pst@number\pst@dima mul def + /barsep \pst@tempb \pst@number\pst@dima mul def + /barwidth colwidth barcolsep sub nbars 1 sub barsep mul sub nbars div def + /bXoffset 0.5 barcolsep mul def + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount 0 def + /ybar1 0 def + BARDATA { + /DATAVECTOR exch def + DATAVECTOR { + /ybar2 exch \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul def + /xoffset barwidth barsep add barcount mul bXoffset add def + /xbar1 colcount colwidth mul xoffset add def + /xbar2 xbar1 barwidth add def + ybar1 ybar2 ne { % if ybar1 == ybar2, don't stroke a path + newpath + barstyles barcount get cvx exec + } if + /colcount \pst@tempc\space {colcount 1 add}{colcount 1 sub} ifelse def + } forall + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount barcount 1 add def + } forall + }% + \or% chartstyle=stack + \addto@pscode{% + \pst@tempd% + tx@BarDict begin + /BARDATA #1 transpose def + /ncols BARDATA length def + /colwidth \pst@number\pst@dima def + /barcolsep \pst@tempa \pst@number\pst@dima mul def + /barwidth colwidth barcolsep sub def + /bXoffset 0.5 barcolsep mul def + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount 0 def + /ybar1 0 def + BARDATA { + /DATAVECTOR exch def + /xbar1 colcount colwidth mul bXoffset add def + /xbar2 xbar1 barwidth add def + DATAVECTOR { + /ybar2 exch \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul ybar1 add def + ybar1 ybar2 ne { % if ybar1 == ybar2, don't stroke a path + newpath + barstyles barcount get cvx exec + closepath + } if + /ybar1 ybar2 def + /barcount barcount 1 add def + } forall + /barcount 0 def + /ybar1 0 def + /colcount \pst@tempc\space {colcount 1 add}{colcount 1 sub} ifelse def + } forall + end + }% + \or% chartstyle=block + \addto@pscode{% + \pst@tempd% + tx@BarDict begin + /BARDATA #1 transpose def + /ncols BARDATA length def + /nbars BARDATA 0 get length 2 idiv def + /colwidth \pst@number\pst@dima def + /barcolsep \pst@tempa \pst@number\pst@dima mul def + /barsep \pst@tempb \pst@number\pst@dima mul def + /barwidth colwidth barcolsep sub nbars 1 sub barsep mul sub nbars div def + /bXoffset 0.5 barcolsep mul def + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount 0 def + /ybar1 0 def + BARDATA { + /DATAVECTOR exch def + 0 1 nbars 1 sub { + dup + /ybar1 exch 2 mul DATAVECTOR exch get \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul def + /ybar2 exch 2 mul 1 add DATAVECTOR exch get \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul def + /xoffset barwidth barsep add barcount mul bXoffset add def + /xbar1 colcount colwidth mul xoffset add def + /xbar2 xbar1 barwidth add def + ybar1 ybar2 ne { % if ybar1 == ybar2, don't stroke a path + newpath + barstyles barcount get cvx exec + } if + /barcount barcount 1 add def + } for + /barcount 0 def + /colcount \pst@tempc\space {colcount 1 add}{colcount 1 sub} ifelse def + } forall + end + }% + \else% + \@pstrickserr{Unknown chart style.}\@ehpa% + \fi% + \ifx\psk@orientation\z@% + \pstbar@xlabels% + \else + \pstbar@ylabels% + \fi + \end@SpecialObj% +}% + +\endinput + +\iffalse +%% CHANGE-LOG + v 0.7a 2004/09/24 + Removed some debugging code that was accidentally left in the last release. + The removed code was harmless, but caused confusion for some users. + + v 0.7 2004/09/15 + Made a minor change to \psbarscale so its functionality would be more + closely analogous to the \pstScale command from the pstricks-add pacakge. + Improved documentation. Set default barstyle to list of all available + barstyles. First release to CTAN. + + v 0.6 2004/09/09 + Added orientation parameter and horizontal bar-drawing capability. Removed + erroneous correction factor for linewidth from stacked bar chart. + + v 0.5 2004/09/02 + Added header parameter for \readpsbardata. Improved handling of headers in + the data file -- spaces may now be included in a header item, though commas + still may not. + + v 0.4 2004/08/29 + Added "block" chartstyle. Updated \readpsbardata to use .csv for both + header and data. Introduced \psbarscale command. First release to pstricks + mailing list, 2004/09/01. + + v 0.3 2004/08/26 + Added command \readpsbardata to read data for bar chart directly from a + .csv file with the first row containing the column labels. + + v 0.2a 2004/08/23 + Changed colsep parameter name to barcolsep to avoid clash with psmatrix. + + v 0.2 2004/08/22 + Added stacked bar chart, chartstyle parameter, and introduced pst-bar.pro + prologue with transpose command. + + v 0.1 2004/08/21 + Clustered bar chart. +\fi diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar.pro b/graphics/pstricks/contrib/pst-bar/pst-bar.pro new file mode 100644 index 0000000000..608a8c4261 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar.pro @@ -0,0 +1,30 @@ +%! +% PostScript prologue for pst-bar.tex. +% Version 0.2, 2004/08/22 +% For distribution, see pstricks.tex. +% +/tx@BarDict 5 dict def tx@BarDict begin +% +% transpose -- Matrix transpose +% +/transpose { + /X exch def + /row X length def + /col X 0 get length def + [ + /i 0 def + col { + [ + /j 0 def + row { + X j get i get + /j j 1 add def + } repeat + /i i 1 add def + ] + } repeat + ] +} def +% +end +% END pst-bar.pro diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar.sty b/graphics/pstricks/contrib/pst-bar/pst-bar.sty new file mode 100644 index 0000000000..b12795ce04 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar.sty @@ -0,0 +1,10 @@ +\RequirePackage{pstricks}% +\ProvidesPackage{pst-bar}[2004/08/22 package wrapper for pst-bar.tex (ahr)] +\input{pst-bar.tex} +\IfFileExists{pst-bar.pro}{% + \ProvidesFile{pst-bar.pro} + [2004/08/22 v. 0.2, PostScript prologue file (ahr)] + \@addtofilelist{pst-bar.pro}}{}% +\ProvidesFile{pst-bar.tex} + [\filedate\space v\fileversion\space `pst-bar' (ahr)] +\endinput diff --git a/graphics/pstricks/contrib/pst-bar/pst-bar.tex b/graphics/pstricks/contrib/pst-bar/pst-bar.tex new file mode 100644 index 0000000000..2d6b18fbc8 --- /dev/null +++ b/graphics/pstricks/contrib/pst-bar/pst-bar.tex @@ -0,0 +1,409 @@ +%% $Id: pst-bar.tex 63 2008-11-26 18:00:46Z herbert $ +%% +%% +%% This is file `pst-bar.tex', +%% +%% IMPORTANT NOTICE: +%% +%% Package `pst-bar.tex' +%% +%% Alan Ristow +%% Herbert Voss <Herbert.Voss _at_ pstricks.de> +%% +%% This program can be redistributed and/or modified under the terms +%% of the LaTeX Project Public License Distributed from CTAN archives +%% in directory macros/latex/base/lppl.txt. +%% +%% DESCRIPTION: +%% `pst-bar' is a PSTricks package for additionals to the standard +%% pstricks package +%% +\csname PSTBarLoaded\endcsname% +\let\PSTBarLoaded\endinput% +\ifx\PSTricksLoaded\endinput\else\input pstricks \fi +\ifx\PSTplotLoaded\endinput\else\input pst-plot \fi +\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey \fi + + +\def\fileversion{0.92} +\def\filedate{2008/11/26} +\message{`pst-bar' v\fileversion, \filedate\space (Alan Ristow)}% + +\pstheader{pst-bar.pro}% +\pst@addfams{pst-bar} + +\newlength\psk@labelwidth% +\define@key[psset]{pst-bar}{barsep}{\edef\psk@barsep{#1}}% +\define@key[psset]{pst-bar}{barcolsep}{\edef\psk@barcolsep{#1}}% +\define@key[psset]{pst-bar}{barstyle}{\def\@barstylelist{#1}}% +\define@key[psset]{pst-bar}{barlabelrot}{\edef\psk@barlabelrot{#1}}% +\define@key[psset]{pst-bar}{labelalign}{\def\psk@labelalign{#1}}% +\define@key[psset]{pst-bar}{labelwidth}{\setlength\psk@labelwidth{#1}}% +\def\psk@labelalign{\centering}% +\setlength\psk@labelwidth{0.5in}% +% +% chartstyle=cluster|stack|block (0,1,2) +\define@key[psset]{pst-bar}{chartstyle}{\pst@expandafter\psset@@chartstyle{#1}\@nil\psk@chartstyle}% +\def\psset@@chartstyle#1#2\@nil#3{% + \ifx#1c\let#3\z@\else + \ifx#1s\let#3\@ne\else + \ifx#1b\let#3\tw@\else + \@pstrickserr{Bad argument: `#1#2'}\@ehpa + \fi + \fi + \fi +}% +% orientation=vertical|horizontal (0,1) +\define@key[psset]{pst-bar}{orientation}{\pst@expandafter\psset@@orientation{#1}\@nil\psk@orientation}% +\def\psset@@orientation#1#2\@nil#3{% + \ifx#1h\let#3\p@\else + \ifx#1v\let#3\z@\else + \@pstrickserr{Bad argument: `#1#2'}\@ehpa + \fi + \fi +}% +\define@key[psset]{pst-bar}{header}{\pst@expandafter\psset@@header{#1}\@nil\psk@header}% +\def\psset@@header#1#2\@nil#3{% + \ifx#1t\let#3\z@\else + \ifx#1f\let#3\@ne\else + \@pstrickserr{Bad argument: `#1#2'}\@ehpa + \fi + \fi +}% +\psset[pst-bar]{barsep=0.0,barcolsep=0.4,barstyle=\@empty,barlabelrot=0,% + chartstyle=cluster,orientation=vertical,header=true}% + +\def\psbarchart{\def\pst@par{}\pst@object{psbarchart}}% +\def\pstbar@header{\@empty}% +\def\psbarlabel#1{#1}% +\def\psbarlabelsep{0pt}% +\def\psbarscale(#1)#2{% + \def\psbar@mul{#1\space}% + \def\psbar@psop{#2\space}% +} +\def\psbar@mul{1\space}% +\def\psbar@psop{\@empty}% + +\newread\pstbar@file% + +% Define bar chart styles + +\def\newpsbarstyle#1#2{\@namedef{psbarcs@#1}{\psset{#2}}}% + +\def\begin@barstyle{\def\pst@tempd{/barstyles [ }}% +\def\add@barstyle{% + \def\pst@code{}% + \ifpsshadow% + \pst@closedshadow% + \fi% + \ifdim\psk@border\p@>\z@% + \pst@addborder% + \fi% + \psk@fillstyle% + \pst@stroke% + \ifpsdoubleline% + \pst@doublestroke% + \fi% + \def\pst@tempa{\strip@pt\psk@orientation}% + \edef\pst@tempd{ \pst@tempd (% + \pst@tempc \psk@cornersize% + xbar1 ybar1 xbar2 ybar2 4 -\pst@tempa\space roll + \psk@dimen% + \tx@Frame% + \pst@code )% + }% +} +\def\end@barstyle{\edef\pst@tempd{ \pst@tempd ] def }}% + +\def\setbarstyle{% + \begin@barstyle% + \expandafter\@setbarstyle\@barstylelist,\@nil\ignorespaces% + \end@barstyle% +}% +\def\@setbarstyle#1,{% + \@@setbarstyle{#1}% + \@ifnextchar\@nil{\@gobble}{\@setbarstyle}% +}% +\def\@@setbarstyle#1{% + \@ifundefined{psbarcs@#1}% + {\@pstrickserr{Custom bar chart style `#1' undefined}\@ehpa}% + {\@nameuse{psbarcs@#1}\add@barstyle}% +}% + +% Default bar chart styles + +\newpsbarstyle{red}{fillcolor=red,fillstyle=solid,framearc=0}% +\newpsbarstyle{green}{fillcolor=green,fillstyle=solid,framearc=0}% +\newpsbarstyle{blue}{fillcolor=blue,fillstyle=solid,framearc=0}% +\newpsbarstyle{black}{fillcolor=black,fillstyle=solid,framearc=0}% +\newpsbarstyle{white}{fillcolor=white,fillstyle=solid,framearc=0}% +\newpsbarstyle{gray}{fillcolor=gray,fillstyle=solid,framearc=0}% +\newpsbarstyle{lightgray}{fillcolor=lightgray,fillstyle=solid,framearc=0}% +\newpsbarstyle{darkgray}{fillcolor=darkgray,fillstyle=solid,framearc=0}% + +%\psset@barstyle{black,darkgray,gray,lightgray,white,red,green,blue}% +\psset[pst-bar]{barstyle={black,darkgray,gray,lightgray,white,red,green,blue}}% + +\def\readpsbardata{\@ifnextchar[{\readpsbardata@i}{\readpsbardata@i[]}} + +\def\readpsbardata@i[#1]#2#3{% + \def\pst@tempa{#1}% + \ifx\pst@tempa\@empty\else\psset{#1}\fi + \openin\pstbar@file=#3\relax% + \ifeof\pstbar@file% + \@pstrickserr{Data file `#3' not found.}\@ehpa + \else + \def\pst@tempb{\@empty}% + \ifx\psk@header\z@% + \@readpsbarheader% + \fi + \readpsbardata@ii% + \edef\pst@tempb{[\pst@tempb]}% + \let#2\pst@tempb% + \fi + \closein\pstbar@file% +}% + +\def\readpsbardata@ii{% + \read\pstbar@file to \pst@tempa + \ifeof\pstbar@file + \relax + \else + \edef\pst@tempb{\pst@tempb [}% + \expandafter\readpsbardata@iii\pst@tempa,\@nil\ignorespaces% + \edef\pst@tempb{\pst@tempb ]}% + \readpsbardata@ii% + \fi +}% + +\def\readpsbardata@iii#1,{% + \edef\pst@tempb{\pst@tempb #1\space}% + \@ifnextchar\@nil{\@gobble}{\readpsbardata@iii}% +}% + +\def\@readpsbarheader{% + \read\pstbar@file to \pst@tempa + \ifeof\pstbar@file + \relax + \else + \let\pstbar@header\pst@tempa + \fi +}% + +% Apply labels from file header to bar chart columns. +% TODO: Deal with column headings that contain commas. + +% The trimspaces command is (c) Michael Downes 1994 +% (http://www.tug.org/tex-archive/info/aro-bend/answer.015). +\catcode`\Q=3 +\def\psbar@trimspaces#1{% + \begingroup + \aftergroup\toks\aftergroup0\aftergroup{% + \expandafter\trimb\expandafter\noexpand#1Q Q}% + \edef#1{\the\toks0}% +} +\def\trimb#1 Q{\trimc#1Q} +\def\trimc#1Q#2{\afterassignment\endgroup \vfuzz\the\vfuzz#1} +\catcode`\Q=11 + +\def\pstbar@xlabels{% + \pst@dima=-0.5pt\relax% + \expandafter\pstbar@xlabels@i\pstbar@header,\@nil\ignorespaces% +}% + +\def\pstbar@xlabels@i#1,{% + \def\pst@tempa{#1}% + \psbar@trimspaces\pst@tempa% + \advance\pst@dima by 1pt% + \def\pst@tempb{\strip@pt\pst@dima}% + \uput[-90]{\psk@barlabelrot}(\pst@tempb,-\psbarlabelsep){\psbarlabel{\parbox{\psk@labelwidth}{\psk@labelalign\pst@tempa}}}% + \@ifnextchar\@nil{\@gobble}{\pstbar@xlabels@i}% +}% + +\def\pstbar@labelcount#1{% + \pst@dima=0pt\relax% + \expandafter\pstbar@labelcount@i\pstbar@header,\@nil\ignorespaces% + \let#1\pst@dima% +}% + +\def\pstbar@labelcount@i#1,{% + \advance\pst@dima by 1pt% + \@ifnextchar\@nil{\@gobble}{\pstbar@labelcount@i}% +}% + +\def\pstbar@ylabels{% + \pstbar@labelcount{\pst@dima}% + \advance\pst@dima by 0.5pt% + \expandafter\pstbar@ylabels@i\pstbar@header,\@nil\ignorespaces% +}% + +\def\pstbar@ylabels@i#1,{% + \def\pst@tempa{#1}% + \psbar@trimspaces\pst@tempa% + \advance\pst@dima by -1pt% + \def\pst@tempb{\strip@pt\pst@dima}% + \uput[180]{\psk@barlabelrot}(-\psbarlabelsep,\pst@tempb){\psbarlabel{\parbox{\psk@labelwidth}{\psk@labelalign\pst@tempa}}}% + \@ifnextchar\@nil{\@gobble}{\pstbar@ylabels@i}% +}% + +\def\psbarchart@i#1{% + \pst@killglue% + \begingroup% + \use@par% + \psbarchart@ii{#1}% + \endgroup% + \ignorespaces% +}% + +\def\psbarchart@ii#1{% + \begin@SpecialObj% + + % Save contents of \pst@code and load start-of-path code + % into \pst@tempc + + \let\pst@tempb\pst@code% + \def\pst@code{}% + \solid@star% + \let\pst@tempc\pst@code% + + % Load end-of-path code into \pst@tempd and restore original + % contents of \pst@code + + \begin@barstyle% + \expandafter\@setbarstyle\@barstylelist,\@nil\ignorespaces% + \end@barstyle% + \let\pst@code\pst@tempb% + + % Draw bar chart + + \pst@checknum\psk@barcolsep\pst@tempa% + \pst@checknum\psk@barsep\pst@tempb% + \ifx\psk@orientation\z@ % vertical + \pst@dima=\psxunit% + \pst@dimb=\psyunit% + \def\pst@tempc{true}% + \else\ifx\psk@orientation\p@ % horizontal + \pst@dima=\psyunit% + \pst@dimb=\psxunit% + \def\pst@tempc{false}% + \else + \@pstrickserr{Bad orientation specification}\@ehpa + \fi\fi + \ifcase\psk@chartstyle% chartstyle=cluster + \addto@pscode{% + \pst@tempd% + /BARDATA #1 def + /nbars BARDATA length def + /ncols BARDATA 0 get length def + /colwidth \pst@number\pst@dima def + /barcolsep \pst@tempa \pst@number\pst@dima mul def + /barsep \pst@tempb \pst@number\pst@dima mul def + /barwidth colwidth barcolsep sub nbars 1 sub barsep mul sub nbars div def + /bXoffset 0.5 barcolsep mul def + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount 0 def + /ybar1 0 def + BARDATA { + /DATAVECTOR exch def + DATAVECTOR { + /ybar2 exch \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul def + /xoffset barwidth barsep add barcount mul bXoffset add def + /xbar1 colcount colwidth mul xoffset add def + /xbar2 xbar1 barwidth add def + ybar1 ybar2 ne { % if ybar1 == ybar2, don't stroke a path + newpath + barstyles barcount get cvx exec + } if + /colcount \pst@tempc\space {colcount 1 add}{colcount 1 sub} ifelse def + } forall + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount barcount 1 add def + } forall + }% + \or% chartstyle=stack + \addto@pscode{% + \pst@tempd% + tx@BarDict begin + /BARDATA #1 transpose def + /ncols BARDATA length def + /colwidth \pst@number\pst@dima def + /barcolsep \pst@tempa \pst@number\pst@dima mul def + /barwidth colwidth barcolsep sub def + /bXoffset 0.5 barcolsep mul def + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount 0 def + /ybar1 0 def + BARDATA { + /DATAVECTOR exch def + /xbar1 colcount colwidth mul bXoffset add def + /xbar2 xbar1 barwidth add def + /count 0 def + DATAVECTOR { + count 0 eq { + /ybar2 exch \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul ybar1 add def + }{ + /ybar2 exch \psbar@mul mul \pst@number\pst@dimb mul ybar1 add def + } ifelse + ybar1 ybar2 ne { % if ybar1 == ybar2, don't stroke a path + newpath + barstyles barcount get cvx exec + closepath + } if + /ybar1 ybar2 def + /barcount barcount 1 add def + /count count 1 add def + } forall + /barcount 0 def + /ybar1 0 def + /colcount \pst@tempc\space {colcount 1 add}{colcount 1 sub} ifelse def + } forall + end + }% + \or% chartstyle=block + \addto@pscode{% + \pst@tempd% + tx@BarDict begin + /BARDATA #1 transpose def + /ncols BARDATA length def + /nbars BARDATA 0 get length 2 idiv def + /colwidth \pst@number\pst@dima def + /barcolsep \pst@tempa \pst@number\pst@dima mul def + /barsep \pst@tempb \pst@number\pst@dima mul def + /barwidth colwidth barcolsep sub nbars 1 sub barsep mul sub nbars div def + /bXoffset 0.5 barcolsep mul def + /colcount \pst@tempc\space {0}{ncols 1 sub} ifelse def + /barcount 0 def + /ybar1 0 def + BARDATA { + /DATAVECTOR exch def + 0 1 nbars 1 sub { + dup + /ybar1 exch 2 mul DATAVECTOR exch get \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul def + /ybar2 exch 2 mul 1 add DATAVECTOR exch get \psbar@psop \psbar@mul mul \pst@number\pst@dimb mul def + /xoffset barwidth barsep add barcount mul bXoffset add def + /xbar1 colcount colwidth mul xoffset add def + /xbar2 xbar1 barwidth add def + ybar1 ybar2 ne { % if ybar1 == ybar2, don't stroke a path + newpath + barstyles barcount get cvx exec + } if + /barcount barcount 1 add def + } for + /barcount 0 def + /colcount \pst@tempc\space {colcount 1 add}{colcount 1 sub} ifelse def + } forall + end + }% + \else% + \@pstrickserr{Unknown chart style.}\@ehpa% + \fi% + \ifx\psk@orientation\z@% + \pstbar@xlabels% + \else + \pstbar@ylabels% + \fi + \end@SpecialObj% +}% + +\endinput + |