summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXu Yuan <xu@informatik.hu-berlin.de>2011-10-01 22:30:00 +0200
committerXu Yuan <xu@informatik.hu-berlin.de>2011-10-01 22:30:00 +0200
commit1e9baf6e684d2f4f29eaa9fe1f506ed1233904b7 (patch)
tree11bb6030d69bf8406318b709ce6f64bffd306eac
parent651a3ad72e8b44d8fd0e03f1e93ac8b6c22890b6 (diff)
downloadpgf-pie-1e9baf6e684d2f4f29eaa9fe1f506ed1233904b7.tar.gz
pgf-pie-1e9baf6e684d2f4f29eaa9fe1f506ed1233904b7.tar.bz2
pgf-pie-1e9baf6e684d2f4f29eaa9fe1f506ed1233904b7.zip
polar pie!
-rw-r--r--dev/demo/population.tex6
-rw-r--r--dev/pgf-pie-manual.tex7
-rw-r--r--dev/pgf-pie.sty39
3 files changed, 46 insertions, 6 deletions
diff --git a/dev/demo/population.tex b/dev/demo/population.tex
index d64b8b8..1b39664 100644
--- a/dev/demo/population.tex
+++ b/dev/demo/population.tex
@@ -1,6 +1,6 @@
% 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,
+ \pie[polar, 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,
@@ -22,6 +22,6 @@
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};
+ % \node[circle,draw=black,thick, fill=white, font=\bf]
+ % {Population of the world};
\end{tikzpicture}
diff --git a/dev/pgf-pie-manual.tex b/dev/pgf-pie-manual.tex
index b8acc99..6eb7809 100644
--- a/dev/pgf-pie-manual.tex
+++ b/dev/pgf-pie-manual.tex
@@ -90,6 +90,13 @@ keywordstyle=\color{blue}
\subsection{First Pie}
\demo[0.6]{first-pie}
+\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{Position, Rotation, Size}
The center of chart can be set by \texttt{pos}, default is
diff --git a/dev/pgf-pie.sty b/dev/pgf-pie.sty
index 0fa3b26..84cbb1c 100644
--- a/dev/pgf-pie.sty
+++ b/dev/pgf-pie.sty
@@ -50,6 +50,7 @@ chart by using PGF/Tikz package.]
\newcounter{pgfpie@angleEnd}
\newcounter{pgfpie@explodeLength}
\newcounter{pgfpie@colorLength}
+\newcounter{pgfpie@sliceLength}
\def\setexplode#1\pgfeov{\def\explode{#1}}
\pgfkeyslet{/explode/.@cmd}{\setexplode}
@@ -81,8 +82,12 @@ chart by using PGF/Tikz package.]
\def\setrotate#1\pgfeov{\xdef\rotate{#1}}
\pgfkeyslet{/rotate/.@cmd}{\setrotate}
+\newif\ifpolar
+\pgfkeys{/polar/.is if=polar}
+
\newcommand{\pie}[2][]
{
+ % load default parameters
\pgfkeys{
explode=0,
color={blue!60, cyan!60, yellow!60, orange!60, red!60,
@@ -96,9 +101,12 @@ chart by using PGF/Tikz package.]
text=label,
sum=100,
rotate=0,
+ polar=false,
}
+ % load user's parameters
\pgfkeys{#1}
+ % handle sum
\ifthenelse{\equal{\sum}{auto}}
{
% sum all input
@@ -111,7 +119,7 @@ chart by using PGF/Tikz package.]
}
{}
-
+ % init counters
\setcounter{pgfpie@explodeLength}{0}
\foreach \e in \explode { \addtocounter{pgfpie@explodeLength}{1} }
@@ -120,10 +128,35 @@ chart by using PGF/Tikz package.]
\setcounter{pgfpie@angleEnd}{0}
+ \ifpolar
+ \setcounter{pgfpie@sliceLength}{0}
+ \xdef\maxValue{0}
+ \foreach \p/\e in {#2} {
+ \addtocounter{pgfpie@sliceLength}{1}
+ \ifnum \maxValue < \p
+ \xdef\maxValue{\p}
+ \fi
+ }
+ \pgfmathparse{\sum / \value{pgfpie@sliceLength}}
+ \xdef\polarangle{\pgfmathresult}
+ \pgfmathparse{\radius / \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}}
- \addtocounter{pgfpie@angleEnd}{\p}
+ \ifpolar
+ % Polar area diagram
+ \addtocounter{pgfpie@angleEnd}{\polarangle}
+ \xdef\theradius{\p*\polarRadiusUnit}
+ \else
+ % normal pie
+ \addtocounter{pgfpie@angleEnd}{\p}
+ \fi
% find explode
\pgfmathparse{int(mod(\i,\value{pgfpie@explodeLength}))}
@@ -151,7 +184,7 @@ chart by using PGF/Tikz package.]
{\t}
{\theexplode}
{\thecolor}
- {\radius}
+ {\theradius}
{\pos}
{\style}
}