From 867ed74fe91e548f9458d897699fa6ba7bb83d91 Mon Sep 17 00:00:00 2001 From: Xu Yuan Date: Sat, 1 Oct 2011 20:52:46 +0200 Subject: sum and examples --- dev/demo/before-after-number.tex | 3 +++ dev/demo/population.tex | 27 +++++++++++++++++++++++++++ dev/demo/sum.tex | 3 +++ dev/pgf-pie-manual.tex | 7 ++++++- dev/pgf-pie.sty | 24 +++++++++++++++++++++--- 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 dev/demo/before-after-number.tex create mode 100644 dev/demo/population.tex create mode 100644 dev/demo/sum.tex diff --git a/dev/demo/before-after-number.tex b/dev/demo/before-after-number.tex new file mode 100644 index 0000000..0a50ebf --- /dev/null +++ b/dev/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/dev/demo/population.tex b/dev/demo/population.tex new file mode 100644 index 0000000..d64b8b8 --- /dev/null +++ b/dev/demo/population.tex @@ -0,0 +1,27 @@ +% data from http://en.wikipedia.org/wiki/List_of_countries_by_population +\begin{tikzpicture} + \pie[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=\LARGE\bf] + {Population of the world}; +\end{tikzpicture} diff --git a/dev/demo/sum.tex b/dev/demo/sum.tex new file mode 100644 index 0000000..94fd88b --- /dev/null +++ b/dev/demo/sum.tex @@ -0,0 +1,3 @@ +\begin{tikzpicture} + \pie[sum=auto, after number=, radius=2]{33/Boy, 7/Girl} +\end{tikzpicture} \ No newline at end of file diff --git a/dev/pgf-pie-manual.tex b/dev/pgf-pie-manual.tex index f591461..0d5a2ea 100644 --- a/dev/pgf-pie-manual.tex +++ b/dev/pgf-pie-manual.tex @@ -110,6 +110,10 @@ The value of \texttt{text} can be \texttt{label}(default) or \demo[0.6]{text} +\subsection{Sum} + +\demo[0.6]{sum} + \subsection{Color} \demo{color} @@ -119,7 +123,8 @@ The value of \texttt{text} can be \texttt{label}(default) or \section{Examples} - +\subsection{Population of the world} +\example{population} % \pie{20/, 4/, 11/, 49/, 16/} diff --git a/dev/pgf-pie.sty b/dev/pgf-pie.sty index 5021851..bcaf112 100644 --- a/dev/pgf-pie.sty +++ b/dev/pgf-pie.sty @@ -11,6 +11,7 @@ chart by using PGF/Tikz package.] \RequirePackage{tikz} +\RequirePackage{ifthen} % args: % #1: begin angle @@ -32,7 +33,7 @@ chart by using PGF/Tikz package.] \let\radius\pgfmathresult % slice - \draw[fill=#6, #9] (O) -- ++(#1:#7) arc (#1:#2:#7) -- cycle; + \draw[line join=round, fill=#6, #9] (O) -- ++(#1:#7) arc (#1:#2:#7) -- cycle; % outer label \path (O) -- ++ (\midangle:\radius) node[inner sep=0, \text=\midangle:#4]{}; @@ -74,6 +75,9 @@ chart by using PGF/Tikz package.] \def\settext#1\pgfeov{\xdef\text{#1}} \pgfkeyslet{/text/.@cmd}{\settext} +\def\setsum#1\pgfeov{\xdef\sum{#1}} +\pgfkeyslet{/sum/.@cmd}{\setsum} + \newcommand{\pie}[2][] { \pgfkeys{ @@ -85,9 +89,23 @@ chart by using PGF/Tikz package.] before number=, after number=\%, text=label, + sum=100, } \pgfkeys{#1} + \ifthenelse{\equal{\sum}{auto}} + { + % sum all input + \xdef\sum{0} + \foreach \p/\t in {#2} + { + \pgfmathparse{\sum + \p} + \xdef\sum{\pgfmathresult} + } + } + {} + + \setcounter{pgfpie@explodeLength}{0} \foreach \e in \explode { \addtocounter{pgfpie@explodeLength}{1} } @@ -121,8 +139,8 @@ chart by using PGF/Tikz package.] \fi } - \pgfpie@slice{\thepgfpie@angleBegin/100*360} - {\thepgfpie@angleEnd/100*360} + \pgfpie@slice{\thepgfpie@angleBegin/\sum*360} + {\thepgfpie@angleEnd/\sum*360} {\beforenumber \p \afternumber} {\t} {\theexplode} -- cgit v1.2.3