73 lines
2.5 KiB
TeX
73 lines
2.5 KiB
TeX
%-----------------------------------------------------------------------------------------------------------------------------------------------%
|
|
% The MIT License (MIT)
|
|
%
|
|
% Copyright (c) 2016 Jan Küster
|
|
%
|
|
% Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
% of this software and associated documentation files (the "Software"), to deal
|
|
% in the Software without restriction, including without limitation the rights
|
|
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
% copies of the Software, and to permit persons to whom the Software is
|
|
% furnished to do so, subject to the following conditions:
|
|
%
|
|
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
% THE SOFTWARE.
|
|
%
|
|
%-----------------------------------------------------------------------------------------------------------------------------------------------%
|
|
\newcounter{barcount}
|
|
|
|
|
|
% draw a bar chart
|
|
% param 1: width
|
|
% param 2: height
|
|
% param 3: border color
|
|
% param 4: label text color
|
|
% param 5: label bg color
|
|
% param 6: cat 1 color
|
|
\newenvironment{barchart}[8]{
|
|
|
|
\newcommand{\barwidth}{0.35}
|
|
\newcommand{\barsep}{0.2}
|
|
|
|
% param 1: overall percent
|
|
% param 2: label
|
|
% param 3: cat 1 percent
|
|
% param 4: cat 2 percent
|
|
% param 5: cat 3 percent
|
|
\newcommand{\baritem}[5]{
|
|
|
|
\pgfmathparse{##3+##4+##5}
|
|
\let\perc\pgfmathresult
|
|
|
|
\pgfmathparse{#2}
|
|
\let\barsize\pgfmathresult
|
|
|
|
\pgfmathparse{\barsize*##3/100}
|
|
\let\barone\pgfmathresult
|
|
|
|
\pgfmathparse{\barsize*##4/100}
|
|
\let\bartwo\pgfmathresult
|
|
|
|
\pgfmathparse{\barsize*##5/100}
|
|
\let\barthree\pgfmathresult
|
|
|
|
\pgfmathparse{(\barwidth*\thebarcount)+(\barsep*\thebarcount)}
|
|
\let\barx\pgfmathresult
|
|
|
|
\filldraw[fill=#6, draw=none] (0,-\barx) rectangle (\barone,-\barx-\barwidth);
|
|
\filldraw[fill=#7, draw=none] (\barone, -\barx) rectangle (\barone+\bartwo,-\barx-\barwidth);
|
|
\filldraw[fill=#8, draw=none] (\barone+\bartwo,-\barx ) rectangle (\barone+\bartwo+\barthree,-\barx-\barwidth);
|
|
|
|
\node [label=180:\colorbox{#5}{\textcolor{#4}{##2}}] at (0,-\barx-0.175) {};
|
|
\addtocounter{barcount}{1}
|
|
}
|
|
\begin{tikzpicture}
|
|
\setcounter{barcount}{0}
|
|
|
|
}
|
|
{\end{tikzpicture}} |