summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXu Yuan <xu@informatik.hu-berlin.de>2011-10-01 10:59:07 +0200
committerXu Yuan <xu@informatik.hu-berlin.de>2011-10-01 10:59:07 +0200
commit52a3efdc9c7d9dee62935099e0cd77e45d91f90c (patch)
tree967f25f723750b6602a2f1ff7c8fbb03ab3b684e
parentfd3dfdf3c3d468cc58571605030bf81461a6b74a (diff)
downloadpgf-pie-52a3efdc9c7d9dee62935099e0cd77e45d91f90c.tar.gz
pgf-pie-52a3efdc9c7d9dee62935099e0cd77e45d91f90c.tar.bz2
pgf-pie-52a3efdc9c7d9dee62935099e0cd77e45d91f90c.zip
allow \pie in tikzpicture
-rw-r--r--dev/demo/pie.tex4
-rw-r--r--dev/pgf-pie.sty31
2 files changed, 22 insertions, 13 deletions
diff --git a/dev/demo/pie.tex b/dev/demo/pie.tex
index 540e0c1..3589bbf 100644
--- a/dev/demo/pie.tex
+++ b/dev/demo/pie.tex
@@ -1 +1,3 @@
-\pie{20/, 4/, 11/, 49/, 16/} \ No newline at end of file
+\begin{tikzpicture}
+ \pie{20/, 4/, 11/, 49/, 16/}
+\end{tikzpicture}
diff --git a/dev/pgf-pie.sty b/dev/pgf-pie.sty
index d85467f..fe7e2e3 100644
--- a/dev/pgf-pie.sty
+++ b/dev/pgf-pie.sty
@@ -13,22 +13,28 @@ chart by using PGF/Tikz package.]
\RequirePackage{tikz}
\usetikzlibrary{shadows}
-\newcommand{\pgfpie@slice}[6]{
+% args:
+% #1: begin angle
+% #2: end angle
+% #3: inner label
+% #4: outer label
+% #5: explode
+% #6: fill color
+% #7: radius
+\newcommand{\pgfpie@slice}[7]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
- \pgfmathparse{1}
- \let\radius\pgfmathresult
% slice
- \draw[thick,fill=#6, drop shadow] (\midangle:#5) -- ++(#1:\radius) arc (#1:#2:\radius) -- cycle;
+ \draw[thick,fill=#6, drop shadow] (\midangle:#5) -- ++(#1:#7) arc (#1:#2:#7) -- cycle;
% outer label
- \node[label=\midangle:#4] at (\midangle:1) {};
+ \node[label=\midangle:#4] at (\midangle:#7) {};
% inner label
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
- \pgfmathparse{max(\temp,-0.5) + 0.8}
+ \pgfmathparse{(max(\temp,-0.5) + 0.8)*#7}
\let\innerpos\pgfmathresult
\node at (\midangle:\innerpos) {#3};
}
@@ -44,10 +50,14 @@ chart by using PGF/Tikz package.]
\def\setcolormap#1\pgfeov{\def\colormap{#1}}
\pgfkeyslet{/colormap/.@cmd}{\setcolormap}
+\def\setradius#1\pgfeov{\def\radius{#1}}
+\pgfkeyslet{/radius/.@cmd}{\setradius}
+
\newcommand{\pie}[2][]
{
\pgfkeys{explode=0,
- colormap={blue!60, cyan!60, yellow!60, orange!60, red!60}}
+ colormap={blue!60, cyan!60, yellow!60, orange!60, red!60},
+ radius=3}
\pgfkeys{#1}
\def\explodearray{{\explode}}
@@ -58,9 +68,7 @@ chart by using PGF/Tikz package.]
\foreach \c in \colormap { \addtocounter{pgfpie@colormapLength}{1} }
\setcounter{pgfpie@angleEnd}{0}
- \begin{tikzpicture}[scale=3,
-% x={(1cm,0cm)}, y={(0cm,0.5cm)}
-]
+
\foreach \p/\t [count=\i from 0] in {#2}
{
@@ -86,9 +94,8 @@ chart by using PGF/Tikz package.]
{\p\%}{\t}
{\e}
{\thecolor}
+ {\radius}
}
-
- \end{tikzpicture}
}
%%% End of pgf-pie.sty