summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXu Yuan <xu@informatik.hu-berlin.de>2011-10-02 00:12:43 +0200
committerXu Yuan <xu@informatik.hu-berlin.de>2011-10-02 00:12:43 +0200
commitcac24b96a2690e8b2bc0f7cb4f55a53f9cc38579 (patch)
treed8a949361ad30a55134a353af56a2303aa95afb6
parent1e9baf6e684d2f4f29eaa9fe1f506ed1233904b7 (diff)
downloadpgf-pie-cac24b96a2690e8b2bc0f7cb4f55a53f9cc38579.tar.gz
pgf-pie-cac24b96a2690e8b2bc0f7cb4f55a53f9cc38579.tar.bz2
pgf-pie-cac24b96a2690e8b2bc0f7cb4f55a53f9cc38579.zip
legend
-rw-r--r--dev/demo/legend.tex3
-rw-r--r--dev/demo/polar.tex3
-rw-r--r--dev/pgf-pie-manual.tex6
-rw-r--r--dev/pgf-pie.sty47
4 files changed, 48 insertions, 11 deletions
diff --git a/dev/demo/legend.tex b/dev/demo/legend.tex
new file mode 100644
index 0000000..f6665f6
--- /dev/null
+++ b/dev/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/dev/demo/polar.tex b/dev/demo/polar.tex
new file mode 100644
index 0000000..4d86872
--- /dev/null
+++ b/dev/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/dev/pgf-pie-manual.tex b/dev/pgf-pie-manual.tex
index 6eb7809..95a666f 100644
--- a/dev/pgf-pie-manual.tex
+++ b/dev/pgf-pie-manual.tex
@@ -115,11 +115,13 @@ is 3.
\demo[0.6]{before-after-number}
\subsubsection{Text outside pie}
-The value of \texttt{text} can be \texttt{label}(default) or
-\texttt{pin}.
+The value of \texttt{text} can be \texttt{label}(default),
+\texttt{pin} or \texttt{legend}.
\demo[0.6]{text}
+\demo[0.6]{legend}
+
\subsection{Sum}
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
diff --git a/dev/pgf-pie.sty b/dev/pgf-pie.sty
index 84cbb1c..e26c4fb 100644
--- a/dev/pgf-pie.sty
+++ b/dev/pgf-pie.sty
@@ -36,7 +36,11 @@ chart by using PGF/Tikz package.]
\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]{};
+ \iflegend
+ \else
+ \path (O) -- ++ (\midangle:\radius)
+ node[inner sep=0, \text=\midangle:#4]{};
+ \fi
% inner label
\pgfmathparse{min(((#2)-(#1)-10)/110*(-0.3),0)}
@@ -46,6 +50,19 @@ chart by using PGF/Tikz package.]
\path (O) -- ++(\midangle:\innerpos) node {#3};
}
+\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
+ }
+}
+
\newcounter{pgfpie@angleBegin}
\newcounter{pgfpie@angleEnd}
\newcounter{pgfpie@explodeLength}
@@ -85,6 +102,8 @@ chart by using PGF/Tikz package.]
\newif\ifpolar
\pgfkeys{/polar/.is if=polar}
+\newif\iflegend
+
\newcommand{\pie}[2][]
{
% load default parameters
@@ -106,6 +125,11 @@ chart by using PGF/Tikz package.]
% load user's parameters
\pgfkeys{#1}
+ % legend or not
+ \ifthenelse{\equal{\text}{legend}}
+ {\legendtrue}
+ {\legendfalse}
+
% handle sum
\ifthenelse{\equal{\sum}{auto}}
{
@@ -169,14 +193,7 @@ chart by using PGF/Tikz package.]
}
% find color
- \pgfmathparse{int(mod(\i,\value{pgfpie@colorLength}))}
- \let\ci\pgfmathresult
- \foreach \c [count=\j from 0] in \color {
- \ifnum \j=\ci
- \xdef\thecolor{\c}
- \breakforeach
- \fi
- }
+ \pgfpie@findColor{\i}
\pgfpie@slice{\thepgfpie@angleBegin/\sum*360+\rotate}
{\thepgfpie@angleEnd/\sum*360+\rotate}
@@ -188,6 +205,18 @@ chart by using PGF/Tikz package.]
{\pos}
{\style}
}
+
+ % legend
+ \iflegend
+ \coordinate[xshift=0.8cm] (legendpos) at (current bounding box.north 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