1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 <xuyuan.cn@gmail.com>
%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{pgf-pie}[2011/10/01 v0.1 Some LaTeX macros for pie
chart by using PGF/Tikz package.]
\RequirePackage{tikz}
\usetikzlibrary{shadows}
% 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
% slice
\draw[thick,fill=#6, drop shadow] (\midangle:#5) -- ++(#1:#7) arc (#1:#2:#7) -- cycle;
% outer label
\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)*#7}
\let\innerpos\pgfmathresult
\node at (\midangle:\innerpos) {#3};
}
\newcounter{pgfpie@angleBegin}
\newcounter{pgfpie@angleEnd}
\newcounter{pgfpie@explodeLength}
\newcounter{pgfpie@colormapLength}
\def\setexplode#1\pgfeov{\def\explode{#1}}
\pgfkeyslet{/explode/.@cmd}{\setexplode}
\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},
radius=3}
\pgfkeys{#1}
\def\explodearray{{\explode}}
\setcounter{pgfpie@explodeLength}{0}
\foreach \e in \explode { \addtocounter{pgfpie@explodeLength}{1} }
\setcounter{pgfpie@colormapLength}{0}
\foreach \c in \colormap { \addtocounter{pgfpie@colormapLength}{1} }
\setcounter{pgfpie@angleEnd}{0}
\foreach \p/\t [count=\i from 0] in {#2}
{
\setcounter{pgfpie@angleBegin}{\value{pgfpie@angleEnd}}
\addtocounter{pgfpie@angleEnd}{\p}
% find explode
\pgfmathparse{\explodearray[int(mod(\i,\value{pgfpie@explodeLength}))]}
\let\e\pgfmathresult
% find color
\pgfmathparse{int(mod(\i,\value{pgfpie@colormapLength}))}
\let\ci\pgfmathresult
\foreach \c [count=\j from 0] in \colormap {
\ifnum \j=\ci
\xdef\thecolor{\c}
\breakforeach
\fi
}
\pgfpie@slice{\thepgfpie@angleBegin/100*360}
{\thepgfpie@angleEnd/100*360}
{\p\%}{\t}
{\e}
{\thecolor}
{\radius}
}
}
%%% End of pgf-pie.sty
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|