From e268fecc18fec7afd0205ec616bb37d2096f38aa Mon Sep 17 00:00:00 2001 From: Xu Yuan Date: Sun, 2 Oct 2011 20:04:28 +0200 Subject: release 0.2 --- release/pgf-pie-0.2/demo/before-after-number.tex | 3 + release/pgf-pie-0.2/demo/cloud.svg | 93 +++++ release/pgf-pie-0.2/demo/cloud.tex | 3 + release/pgf-pie-0.2/demo/color.tex | 6 + release/pgf-pie-0.2/demo/colorwheel.tex | 3 + release/pgf-pie-0.2/demo/explode.tex | 7 + release/pgf-pie-0.2/demo/first-pie.svg | 75 ++++ release/pgf-pie-0.2/demo/first-pie.tex | 3 + release/pgf-pie-0.2/demo/legend.tex | 3 + release/pgf-pie-0.2/demo/polar.svg | 75 ++++ release/pgf-pie-0.2/demo/polar.tex | 3 + release/pgf-pie-0.2/demo/population.tex | 27 ++ release/pgf-pie-0.2/demo/radius.tex | 7 + release/pgf-pie-0.2/demo/scalefont.tex | 3 + release/pgf-pie-0.2/demo/shadow.tex | 4 + release/pgf-pie-0.2/demo/square.svg | 75 ++++ release/pgf-pie-0.2/demo/square.tex | 3 + release/pgf-pie-0.2/demo/sum.tex | 5 + release/pgf-pie-0.2/demo/text-inside.tex | 3 + release/pgf-pie-0.2/demo/text.tex | 3 + release/pgf-pie-0.2/logo.png | Bin 0 -> 9181 bytes release/pgf-pie-0.2/pgf-pie-manual.pdf | Bin 0 -> 194742 bytes release/pgf-pie-0.2/pgf-pie-manual.tex | 197 ++++++++++ release/pgf-pie-0.2/pgf-pie.sty | 439 +++++++++++++++++++++++ 24 files changed, 1040 insertions(+) create mode 100644 release/pgf-pie-0.2/demo/before-after-number.tex create mode 100644 release/pgf-pie-0.2/demo/cloud.svg create mode 100644 release/pgf-pie-0.2/demo/cloud.tex create mode 100644 release/pgf-pie-0.2/demo/color.tex create mode 100644 release/pgf-pie-0.2/demo/colorwheel.tex create mode 100644 release/pgf-pie-0.2/demo/explode.tex create mode 100644 release/pgf-pie-0.2/demo/first-pie.svg create mode 100644 release/pgf-pie-0.2/demo/first-pie.tex create mode 100644 release/pgf-pie-0.2/demo/legend.tex create mode 100644 release/pgf-pie-0.2/demo/polar.svg create mode 100644 release/pgf-pie-0.2/demo/polar.tex create mode 100644 release/pgf-pie-0.2/demo/population.tex create mode 100644 release/pgf-pie-0.2/demo/radius.tex create mode 100644 release/pgf-pie-0.2/demo/scalefont.tex create mode 100644 release/pgf-pie-0.2/demo/shadow.tex create mode 100644 release/pgf-pie-0.2/demo/square.svg create mode 100644 release/pgf-pie-0.2/demo/square.tex create mode 100644 release/pgf-pie-0.2/demo/sum.tex create mode 100644 release/pgf-pie-0.2/demo/text-inside.tex create mode 100644 release/pgf-pie-0.2/demo/text.tex create mode 100644 release/pgf-pie-0.2/logo.png create mode 100644 release/pgf-pie-0.2/pgf-pie-manual.pdf create mode 100644 release/pgf-pie-0.2/pgf-pie-manual.tex create mode 100644 release/pgf-pie-0.2/pgf-pie.sty diff --git a/release/pgf-pie-0.2/demo/before-after-number.tex b/release/pgf-pie-0.2/demo/before-after-number.tex new file mode 100644 index 0000000..0a50ebf --- /dev/null +++ b/release/pgf-pie-0.2/demo/before-after-number.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[before number={\$}, after number=,]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/cloud.svg b/release/pgf-pie-0.2/demo/cloud.svg new file mode 100644 index 0000000..3fb608e --- /dev/null +++ b/release/pgf-pie-0.2/demo/cloud.svg @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/release/pgf-pie-0.2/demo/cloud.tex b/release/pgf-pie-0.2/demo/cloud.tex new file mode 100644 index 0000000..fba25f8 --- /dev/null +++ b/release/pgf-pie-0.2/demo/cloud.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[cloud, text=inside, scale font]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/color.tex b/release/pgf-pie-0.2/demo/color.tex new file mode 100644 index 0000000..cb79b8c --- /dev/null +++ b/release/pgf-pie-0.2/demo/color.tex @@ -0,0 +1,6 @@ +\begin{tikzpicture} + \pie[color={black!10, black!20, black!30, black!40}] + {10/A, 20/B, 30/C, 40/D} + + \pie[pos={8,0}, color=blue!20] {10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} diff --git a/release/pgf-pie-0.2/demo/colorwheel.tex b/release/pgf-pie-0.2/demo/colorwheel.tex new file mode 100644 index 0000000..1543fbe --- /dev/null +++ b/release/pgf-pie-0.2/demo/colorwheel.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie{10/, 10/, 10/, 10/, 10/, 10/, 10/, 10/, 10/, 10/} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/explode.tex b/release/pgf-pie-0.2/demo/explode.tex new file mode 100644 index 0000000..94c83fc --- /dev/null +++ b/release/pgf-pie-0.2/demo/explode.tex @@ -0,0 +1,7 @@ +\begin{tikzpicture} + % explode list + \pie[explode={0, 0, 0, 0.1}] {10/A, 20/B, 30/C, 40/D} + + % explode all + \pie[pos={8,0}, explode=0.1] {10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/first-pie.svg b/release/pgf-pie-0.2/demo/first-pie.svg new file mode 100644 index 0000000..9feb8fe --- /dev/null +++ b/release/pgf-pie-0.2/demo/first-pie.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/release/pgf-pie-0.2/demo/first-pie.tex b/release/pgf-pie-0.2/demo/first-pie.tex new file mode 100644 index 0000000..e8c6376 --- /dev/null +++ b/release/pgf-pie-0.2/demo/first-pie.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/legend.tex b/release/pgf-pie-0.2/demo/legend.tex new file mode 100644 index 0000000..f6665f6 --- /dev/null +++ b/release/pgf-pie-0.2/demo/legend.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[text=legend]{10/First, 20/Second, 30/Third, 40/Fourth} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/polar.svg b/release/pgf-pie-0.2/demo/polar.svg new file mode 100644 index 0000000..a4442a0 --- /dev/null +++ b/release/pgf-pie-0.2/demo/polar.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/release/pgf-pie-0.2/demo/polar.tex b/release/pgf-pie-0.2/demo/polar.tex new file mode 100644 index 0000000..4d86872 --- /dev/null +++ b/release/pgf-pie-0.2/demo/polar.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[polar]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/population.tex b/release/pgf-pie-0.2/demo/population.tex new file mode 100644 index 0000000..9267acb --- /dev/null +++ b/release/pgf-pie-0.2/demo/population.tex @@ -0,0 +1,27 @@ +% data from http://en.wikipedia.org/wiki/List_of_countries_by_population +\begin{tikzpicture} + \pie[cloud, rotate=45, sum=auto, radius=35, after number=, text=pin] {1339/China, + 1210/India, 312/USA, 237/Indonesia, 190/Brazil, 177/Pakistan, + 158/Nigeria, 151/Bangladesh, 142/Russia, 127/Japan, 112/Mexico, + 94/Philippines, 87/Vietnam, 82/Ethiopia, 81/Germany, 80/Egypt, + 75/Iran, 73/Turkey, 67/Thailand, 65/Congo, 65/France, 62/UK, + 60/Italy, 50/South Africa, 48/South Korea, 47/Myanmar, 46/Spain, + 46/Colombia, 45/Ukraine, 43/Tanzania, 40/Argentina, 38/Kenya, + 38/Poland, 36/Algeria, 34/Canada, 32/Morocco, 31/Uganda, 31/Iraq, + 31/Afghanistan, 30/Sudan, 29/Peru, 29/Venezuela, 28/Nepal, + 28/Malaysia, 27/Uzbekistan, 27/Saudi Arabia, 24/Ghana, 24/North + Korea, 23/Syria, 23/Taiwan, 22/Australia, 22/Yemen, 21/Romania, + 20/Madagascar, 20/Sri Lanka, 20/Mozambique, 19/Cote d'Ivoire, + 19/Cameroon, 19/Angola, 17/Chile, 16/Netherlands, 16/Kazakhstan, + 15/Burkina Faso, 15/Niger, 14/Malawi, 14/Mali, 14/Guatemala, + 14/Ecuador, 13/Cambodia, 13/Zambia, 12/Zimbabwe, 12/Senegal, + 11/Cuba, 11/Chad, 10/Belgium, 10/Greece, 10/Portugal, 10/Tunisia, + 10/Czech Republic, 10/Bolivia, 10/Rwanda, 10/Haiti, 10/Hungary, + 10/Guinea, 10/Belarus, 9/Sweden, 9/Dominican Republic, 9/Somalia, + 9/Azerbaijan, 9/Benin, 8/Austria, 8/Burundi, 8/United Arab + Emirates, 8/South Sudan, 8/Honduras, 8/Switzerland, 8/Israel, + 7/Bulgaria, 7/Serbia, 7/Hong Kong } + + % \node[circle,draw=black,thick, fill=white, font=\bf] + % {Population of the world}; +\end{tikzpicture} diff --git a/release/pgf-pie-0.2/demo/radius.tex b/release/pgf-pie-0.2/demo/radius.tex new file mode 100644 index 0000000..944e218 --- /dev/null +++ b/release/pgf-pie-0.2/demo/radius.tex @@ -0,0 +1,7 @@ +\begin{tikzpicture} + \pie{10/, 20/, 30/, 40/} + + \pie[pos={8,0}, rotate=180]{10/, 20/, 30/, 40/} + + \pie[pos={17,0}, radius=4]{10/, 20/, 30/, 40/} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/scalefont.tex b/release/pgf-pie-0.2/demo/scalefont.tex new file mode 100644 index 0000000..df61709 --- /dev/null +++ b/release/pgf-pie-0.2/demo/scalefont.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[scale font]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/shadow.tex b/release/pgf-pie-0.2/demo/shadow.tex new file mode 100644 index 0000000..9ccfd9f --- /dev/null +++ b/release/pgf-pie-0.2/demo/shadow.tex @@ -0,0 +1,4 @@ +% \usetikzlibrary{shadows} +\begin{tikzpicture} + \pie[style=drop shadow]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} diff --git a/release/pgf-pie-0.2/demo/square.svg b/release/pgf-pie-0.2/demo/square.svg new file mode 100644 index 0000000..8e0a48f --- /dev/null +++ b/release/pgf-pie-0.2/demo/square.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/release/pgf-pie-0.2/demo/square.tex b/release/pgf-pie-0.2/demo/square.tex new file mode 100644 index 0000000..dd37da6 --- /dev/null +++ b/release/pgf-pie-0.2/demo/square.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[square]{40/A, 30/B, 20/C, 10/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/sum.tex b/release/pgf-pie-0.2/demo/sum.tex new file mode 100644 index 0000000..13e2b73 --- /dev/null +++ b/release/pgf-pie-0.2/demo/sum.tex @@ -0,0 +1,5 @@ +\begin{tikzpicture} + \pie[sum=auto, after number=, radius=2]{33/Boys, 7/Girls} + + \pie[pos={6,0}, sum=40, after number=, radius=2]{33/Boys} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/text-inside.tex b/release/pgf-pie-0.2/demo/text-inside.tex new file mode 100644 index 0000000..07cf42e --- /dev/null +++ b/release/pgf-pie-0.2/demo/text-inside.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[text=inside]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/demo/text.tex b/release/pgf-pie-0.2/demo/text.tex new file mode 100644 index 0000000..95ef108 --- /dev/null +++ b/release/pgf-pie-0.2/demo/text.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[text=pin]{10/A, 20/B, 30/C, 40/D} +\end{tikzpicture} \ No newline at end of file diff --git a/release/pgf-pie-0.2/logo.png b/release/pgf-pie-0.2/logo.png new file mode 100644 index 0000000..68959bc Binary files /dev/null and b/release/pgf-pie-0.2/logo.png differ diff --git a/release/pgf-pie-0.2/pgf-pie-manual.pdf b/release/pgf-pie-0.2/pgf-pie-manual.pdf new file mode 100644 index 0000000..fc709fe Binary files /dev/null and b/release/pgf-pie-0.2/pgf-pie-manual.pdf differ diff --git a/release/pgf-pie-0.2/pgf-pie-manual.tex b/release/pgf-pie-0.2/pgf-pie-manual.tex new file mode 100644 index 0000000..c8af241 --- /dev/null +++ b/release/pgf-pie-0.2/pgf-pie-manual.tex @@ -0,0 +1,197 @@ +% Manual of pgf-pie.sty, a convenient set of macros for drawing pie +% chart. Written by Xu Yuan This file is part of +% pgf-pie you may get it at http://code.google.com/p/pgf-pie/ + +\documentclass{article} +\usepackage[margin=12mm]{geometry} +\usepackage{hyperref} + +\usepackage{pgf-pie} +\usetikzlibrary{shadows} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage{listings} +\usepackage{color} +\definecolor{listinggray}{gray}{0.92} +\lstset{ % +language=[LaTeX]TeX, +breaklines=true, +frame=single, +% frameround=tttt, +basicstyle=\footnotesize\ttfamily, +backgroundcolor=\color{listinggray}, +keywordstyle=\color{blue} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\hypersetup{ + colorlinks=true, + linkcolor=blue, + anchorcolor=black, + citecolor=olive, + filecolor=magenta, + menucolor=red, + urlcolor=blue +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\demo}[2][1]{ + \begin{center} + \begin{tabular}{cc} + \begin{minipage}{.49\linewidth} + \centering + \resizebox{#1\linewidth}{!}{ + \input{demo/#2} + } + \end{minipage} + & + \begin{minipage}{.45\linewidth} + \lstinputlisting{demo/#2} + \end{minipage} + \end{tabular} + \end{center} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\example}[2][1]{ + \begin{center} + \resizebox{#1\linewidth}{!}{ + \input{demo/#2} + } + \end{center} + \lstinputlisting{demo/#2} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{document} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\title{Drawing Pie Chart by using \texttt{pgf-pie}} +\author{\href{mailto:xuyuan.cn@gmail.com}{Yuan Xu}} +\date{\today{}~(v0.2)} +\maketitle +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{abstract} + \texttt{pgf-pie} is a LaTeX package for drawing pie chart (and + variant charts). As stated by its name, it is based on a very + popular graphic package \texttt{PGF/TikZ}. This document presents + the usage of \texttt{pgf-pie} and collects some pie charts as + examples. \texttt{pgf-pie} can be downloaded from + \href{http://code.google.com/p/pgf-pie/}{http://code.google.com/p/pgf-pie/}. +\end{abstract} + +\tableofcontents + +\section{The Essentials} + +\subsection{First Pie} +\lstinline|\pie| is the only coomand that provided by +\texttt{pgf-pie}. The argument is a list of number and text +combination in the formate of \texttt{number/text}, i.e. \texttt{10/A, + 20/B, 30/C, 40/D}. The result is shown in figure \ref{fig:first-pie}. +\begin{figure} + \centering + \demo[0.6]{first-pie} + \caption{The first pie.} + \label{fig:first-pie} +\end{figure} + +\subsection{Position, Rotation, Size} + +The center of chart can be set by \texttt{pos}, default is +\texttt{\{0,0\}}. The chart can be rotated by setting \texttt{rotate} +(in degrees). The size of chart can be set by \texttt{radius}, default +is 3. + +\demo{radius} + +\subsection{Color} +The color can be specified by \texttt{color}, the default color wheel +is shown in figure \ref{fig:color-wheel}. +\begin{figure} + \centering + \input{demo/colorwheel} + \caption{Default color wheel} + \label{fig:color-wheel} +\end{figure} + +\demo{color} + +\subsection{Explode} +\demo{explode} + +\subsection{Angle of slices} +The value of \texttt{sum} indicats the sum of all data in the chart, +it is 100 by default. It can be calculated automatically when +\texttt{auto} is set. Then the angle of slices are determined by +number value and \texttt{sum}. + +\demo{sum} + +\subsection{Text} + +\subsubsection{Number} +Two parameters can be used to decorate number: \texttt{before number} +and \texttt{after number}. Both are empty by default, but if +\texttt{sum=100}, \texttt{after number} will be set to \% +automatically if user doesn't set it. + +\demo[0.6]{before-after-number} + +\paragraph{Scale font} +The size of font in size pie can be scaled according to how big the +part is automatically. + +\demo[0.6]{scalefont} + +\subsubsection{Label text} +The value of \texttt{text} can be \texttt{label}(default), +\texttt{pin}, \texttt{inside} or \texttt{legend}. + +\demo[0.6]{text} + +\demo[0.5]{text-inside} + +\demo[0.6]{legend} + +\subsection{More about style} +\subsubsection{shadow} +\demo[0.6]{shadow} + +\section{Variant Charts} +\subsection{Polar area diagram} +The polar area diagram is similar to a usual pie chart, except sectors +are equal angles and differ rather in how far each sector extends from +the center of the circle. + +\demo[0.6]{polar} + +\subsection{Square} + +\demo[0.6]{square} + +Note: \texttt{explode} has no affects in sqaure chart. + +\subsection{Clouds} + +\demo[0.6]{cloud} + +\section{Examples} + +% \subsection{Population of the world} +% \example{population} + +% \section{Acknowledgements} +% Many people contributed to \texttt{pgf-pie} by reporting problems, +% suggesting various improvements or submitting code. Here is a list of +% these people: +% \href{mailto:???}{name}. + +\end{document} +%%% Local Variables: +%%% mode: Tex-PDF +%%% TeX-master: t +%%% End: diff --git a/release/pgf-pie-0.2/pgf-pie.sty b/release/pgf-pie-0.2/pgf-pie.sty new file mode 100644 index 0000000..283a5b7 --- /dev/null +++ b/release/pgf-pie-0.2/pgf-pie.sty @@ -0,0 +1,439 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Start of pgf-pie.sty +% +% Some LaTeX macros for pie chart by using PGF/Tikz package. +% Home page of project: http://pgf-pie.googlecode.com/ +% Author: Xu Yuan +% + +\NeedsTeXFormat{LaTeX2e}[1999/12/01] +\ProvidesPackage{pgf-pie}[2011/10/02 v0.2 Some LaTeX macros for pie +chart by using PGF/Tikz package.] + +\RequirePackage{tikz} +\RequirePackage{ifthen} +\RequirePackage{scalefnt} + + +% args: +% #1: begin angle +% #2: end angle +% #3: number +% #4: label +% #5: explode +% #6: fill color +% #7: radius +% #8: center +\newcommand{\pgfpie@slice}[8]{ + \pgfmathparse{0.5*(#1)+0.5*(#2)} + \let\midangle\pgfmathresult + + \path (#8) -- ++(\midangle:#5) coordinate(O); + + \pgfmathparse{#7+#5} + \let\radius\pgfmathresult + + % slice + \draw[line join=round, fill=#6, \style] (O) -- ++(#1:#7) arc (#1:#2:#7) -- cycle; + + \pgfmathparse{min(((#2)-(#1)-10)/110*(-0.3),0)} + \let\temp\pgfmathresult + \pgfmathparse{(max(\temp,-0.5) + 0.8)*#7} + \let\innerpos\pgfmathresult + + \ifthenelse{\equal{\text}{inside}} + { + % label and number together + \path (O) -- ++(\midangle:\innerpos) node + {\scalefont{#3}\shortstack{#4\\\beforenumber#3\afternumber}}; + } + { + % label + \iflegend + \else + \path (O) -- ++ (\midangle:\radius) + node[inner sep=0, \text=\midangle:#4]{}; + \fi + + % number + \path (O) -- ++(\midangle:\innerpos) node + {\scalefont{#3}\beforenumber#3\afternumber}; + } +} + +\newcommand{\pgfpie@findColor}[1] +{ + \pgfmathparse{int(mod(#1,\value{pgfpie@colorLength}))} + \let\ci\pgfmathresult + \foreach \c [count=\j from 0] in \color { + \ifnum \j=\ci + \xdef\thecolor{\c} + \thecolor + \breakforeach + \fi + } +} + +\newcommand{\pgfpie@findExplode}[1] +{ + \pgfmathparse{int(mod(#1,\value{pgfpie@explodeLength}))} + \let\ei\pgfmathresult + \foreach \e [count=\j from 0] in \explode { + \ifnum \j=\ei + \xdef\theexplode{\e} + \breakforeach + \fi + } +} + +% #1: bottom left point +% #2: size +% #3: number +% #4: color +% #5: text +\newcommand{\pgfpie@square}[5] +{ + \ifthenelse{\equal{\text}{inside}} + { + \draw[fill=#4, \style] (#1) rectangle node + {\scalefont{#3}\shortstack{#5\\\beforenumber#3\afternumber}} ++(#2); + } + { + \draw[fill=#4, \style] (#1) rectangle node + {\scalefont{#3}\beforenumber#3\afternumber} ++(#2); + } +} + +% #1: pos +% #2: radius +% #3: number +% #4: color +% $5: style +% $6: label +\newcommand{\pgfpie@cloud}[6] +{ + \draw[fill=#4, #5] (#1) circle[radius=#2]; + \ifthenelse{\equal{\text}{inside}} + { + \node at (#1) {\scalefont{#3}\shortstack{#6\\\beforenumber#3\afternumber}}; + } + { + \node at (#1) {\scalefont{#3}\beforenumber#3\afternumber}; + } +} + +\newcounter{pgfpie@angleBegin} +\newcounter{pgfpie@angleEnd} +\newcounter{pgfpie@explodeLength} +\newcounter{pgfpie@colorLength} +\newcounter{pgfpie@sliceLength} + +\def\setexplode#1\pgfeov{\def\explode{#1}} +\pgfkeyslet{/explode/.@cmd}{\setexplode} + +\def\setcolor#1\pgfeov{\def\color{#1}} +\pgfkeyslet{/color/.@cmd}{\setcolor} + +\def\setradius#1\pgfeov{\def\radius{#1}} +\pgfkeyslet{/radius/.@cmd}{\setradius} + +\def\setpos#1\pgfeov{\def\pos{#1}} +\pgfkeyslet{/pos/.@cmd}{\setpos} + +\def\setstyle#1\pgfeov{\def\style{#1}} +\pgfkeyslet{/style/.@cmd}{\setstyle} + +\def\setbeforenumber#1\pgfeov{\def\beforenumber{#1}} +\pgfkeyslet{/before number/.@cmd}{\setbeforenumber} + +\def\setafternumber#1\pgfeov{\def\afternumber{#1}} +\pgfkeyslet{/after number/.@cmd}{\setafternumber} + +\def\settext#1\pgfeov{\xdef\text{#1}} +\pgfkeyslet{/text/.@cmd}{\settext} + +\def\setsum#1\pgfeov{\xdef\sum{#1}} +\pgfkeyslet{/sum/.@cmd}{\setsum} + +\def\setrotate#1\pgfeov{\xdef\rotate{#1}} +\pgfkeyslet{/rotate/.@cmd}{\setrotate} + +\newif\ifpolar +\pgfkeys{/polar/.is if=polar} + +\newif\iflegend + +\newif\ifsquare +\pgfkeys{/square/.is if=square} + +\newif\ifcloud +\pgfkeys{/cloud/.is if=cloud} + +\newif\ifscalefont +\pgfkeys{/scale font/.is if=scalefont} +\let\scalefontorg\scalefont +\renewcommand{\scalefont}[1] +{ + \ifscalefont + \pgfmathparse{#1 / \sum * 3 + 0.9} + \scalefontorg{\pgfmathresult} + \fi +} + +\newcommand{\pie}[2][] +{ + % load default parameters + \pgfkeys{ + explode=0, + color={blue!60, cyan!60, yellow!60, orange!60, red!60, + blue!60!cyan!60, cyan!60!yellow!60, red!60!cyan!60, + red!60!blue!60, orange!60!cyan!60}, + radius=3, + pos={0,0}, + style={thick}, + before number=, + after number=, + text=label, + sum=100, + rotate=0, + polar=false, + square=false, + cloud=false, + scale font=false, + } + % load user's parameters + \pgfkeys{#1} + % add percentage automatically + \ifthenelse{\equal{\sum}{100}} + { + \pgfkeys{after number=\%} + \pgfkeys{#1} + }{} + + % legend or not + \ifthenelse{\equal{\text}{legend}} + {\legendtrue} + {\legendfalse} + + % handle sum + \ifthenelse{\equal{\sum}{auto}} + { + % sum all input + \xdef\sum{0} + \foreach \p/\t in {#2} + { + \pgfmathparse{\sum + \p} + \xdef\sum{\pgfmathresult} + } + } + {} + + % init counters + \setcounter{pgfpie@explodeLength}{0} + \foreach \e in \explode { \addtocounter{pgfpie@explodeLength}{1} } + + \setcounter{pgfpie@colorLength}{0} + \foreach \c in \color { \addtocounter{pgfpie@colorLength}{1} } + + \setcounter{pgfpie@angleEnd}{0} + + \setcounter{pgfpie@sliceLength}{0} + \foreach \p/\e in {#2} { \addtocounter{pgfpie@sliceLength}{1} } + + \ifsquare + %%%%%%%%%% SQUARE PIE BEGIN %%%%%%%%%%% + \pgfmathparse{\radius*2} + \xdef\verticalLength{\pgfmathresult} + \xdef\horizontalLength{\pgfmathresult} + \path (\pos) -- ++(-\radius, -\radius) coordinate (start); + \pgfmathparse{\verticalLength * \horizontalLength / \sum} + \let\squareUnit\pgfmathresult + + % drawing loop + \foreach \p/\t [count=\i from 0] in {#2} + { + \pgfpie@findColor{\i} + + \ifthenelse{\lengthtest{\verticalLength cm > \horizontalLength cm}} + { + \pgfmathparse{\p * \squareUnit / \horizontalLength} + \let\height\pgfmathresult + + \pgfpie@square{start}{\horizontalLength,\height} + {\p} + {\thecolor} + {\t} + %label + \iflegend + \else + \ifthenelse{\equal{\text}{inside}} + {} + { + \path (start) -- ++(\horizontalLength,\height*0.5) node[inner + sep=0, \text=0:\t]{}; + } + \fi + + \pgfmathparse{\verticalLength - \height} + \xdef\verticalLength{\pgfmathresult} + \path (start) -- ++(0, \height) coordinate (start); + } + { + \pgfmathparse{\p * \squareUnit / \verticalLength } + \let\width\pgfmathresult + + \pgfpie@square{start}{\width,\verticalLength} + {\p} + {\thecolor} + {\t} + %label + \iflegend + \else + \ifthenelse{\equal{\text}{inside}} + {} + { + \path (start) -- ++(\width*0.5,\verticalLength) node[inner + sep=0, \text=90:\t]{}; + } + \fi + + \pgfmathparse{\horizontalLength - \width} + \xdef\horizontalLength{\pgfmathresult} + \path (start) -- ++(\width, 0) coordinate (start); + } + } + + %%%%%%%%%% SQUARE PIE END %%%%%%%%%%% + \else + \ifcloud + %%%%%%%%%% CLOUD PIE BGEIN %%%%%%%%%%% + % drawing loop + \foreach \p/\t [count=\i from 0] in {#2} + { + % find explode + \pgfpie@findExplode{\i} + \def\cloudGap{\theexplode + 0.1} + \pgfmathparse{sqrt(\p / \sum) * \radius} + \let\cloudR\pgfmathresult + \ifnum \i = 0 + % first cloud + \coordinate (O) at (\pos); + \xdef\cloudRone{\cloudR} + \xdef\cloudExtendDir{180+\rotate} + \else + \ifnum \i = 1 + % second cloud + \xdef\cloudRtwo{\cloudR} + \xdef\cloudExtendDir{45+\rotate} + \path (O) -- ++(\cloudExtendDir:\cloudRone+\cloudGap+\cloudRtwo) coordinate (O); + \else + % next cloud + \pgfmathparse{\cloudRone+\cloudGap+\cloudRtwo} + \let\la\pgfmathresult + \pgfmathparse{\cloudRone+\cloudGap+\cloudR} + \let\lb\pgfmathresult + \pgfmathparse{\cloudRtwo+\cloudGap+\cloudR} + \let\lc\pgfmathresult + \pgfmathparse{\la^2+\lc^2-\lb^2} + \let\tmp\pgfmathresult + \pgfmathparse{180 - acos(\tmp / 2 / \la / \lc)} + \let\cloudRot\pgfmathresult + \ifodd \i + \pgfmathparse{-\cloudRot} + \let\cloudRot\pgfmathresult + \fi + \pgfmathparse{\cloudExtendDir - \cloudRot} + \xdef\cloudExtendDir{\pgfmathresult} + \path (O) -- ++(\cloudExtendDir:\lc) coordinate (O); + \xdef\cloudRone{\cloudRtwo} + \xdef\cloudRtwo{\cloudR} + \fi + \fi + + % find color + \pgfpie@findColor{\i} + + \pgfpie@cloud{O}{\cloudR}{\p} + {\thecolor}{\style}{\t} + + % label + \iflegend + \else + \ifthenelse{\equal{\text}{inside}} + {} + { + \path (O) -- ++(\cloudExtendDir:\cloudR) + node[inner sep=0, \text=\cloudExtendDir:\t] {}; + } + \fi + } + %%%%%%%%%% CLOUD PIE BGEIN %%%%%%%%%%% + \else + %%%%%%%%%% CIRCLE PIE BGEIN %%%%%%%%%%% + \ifpolar + \xdef\maxValue{0} + \foreach \p/\e in {#2} { + \ifnum \maxValue < \p + \xdef\maxValue{\p} + \fi + } + \pgfmathparse{\sum / \value{pgfpie@sliceLength}} + \xdef\polarangle{\pgfmathresult} + \pgfmathparse{\radius / sqrt(\maxValue)} + \xdef\polarRadiusUnit{\pgfmathresult} + \else + \xdef\theradius{\radius} + \fi + + % drawing loop + \foreach \p/\t [count=\i from 0] in {#2} + { + \setcounter{pgfpie@angleBegin}{\value{pgfpie@angleEnd}} + \ifpolar + % Polar area diagram + \addtocounter{pgfpie@angleEnd}{\polarangle} + \pgfmathparse{sqrt(\p) * \polarRadiusUnit} + \xdef\theradius{\pgfmathresult} + \else + % normal pie + \addtocounter{pgfpie@angleEnd}{\p} + \fi + + % find explode + \pgfpie@findExplode{\i} + + % find color + \pgfpie@findColor{\i} + + \pgfpie@slice{\thepgfpie@angleBegin/\sum*360+\rotate} + {\thepgfpie@angleEnd/\sum*360+\rotate} + {\p} + {\t} + {\theexplode} + {\thecolor} + {\theradius} + {\pos} + } + %%%%%%%%%% CIRCLE PIE END %%%%%%%%%%% + \fi + \fi + + % legend + \iflegend + \coordinate[xshift=0.8cm, + yshift=(\value{pgfpie@sliceLength}*0.5+1)*0.5cm] (legendpos) at + (current bounding box.east); + + \begin{scope}[node distance=0.5cm] + \foreach \p/\t [count=\i from 0] in {#2} + { + \pgfpie@findColor{\i} + \node[draw, fill=\thecolor, \style, below of=legendpos, label=0:\t] (legendpos) {}; + } + \end{scope} + \fi +} + +%%% End of pgf-pie.sty +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + -- cgit v1.2.3