From 8f53adf67a20b3315fe44f9db7d77c869a69e6b9 Mon Sep 17 00:00:00 2001 From: Xu Yuan Date: Sat, 1 Oct 2011 10:39:18 +0200 Subject: first version --- dev/demo/pie.tex | 1 + dev/pgf-pie-manual.tex | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ dev/pgf-pie.sty | 99 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 dev/demo/pie.tex create mode 100644 dev/pgf-pie-manual.tex create mode 100644 dev/pgf-pie.sty diff --git a/dev/demo/pie.tex b/dev/demo/pie.tex new file mode 100644 index 0000000..540e0c1 --- /dev/null +++ b/dev/demo/pie.tex @@ -0,0 +1 @@ +\pie{20/, 4/, 11/, 49/, 16/} \ No newline at end of file diff --git a/dev/pgf-pie-manual.tex b/dev/pgf-pie-manual.tex new file mode 100644 index 0000000..2b53e2a --- /dev/null +++ b/dev/pgf-pie-manual.tex @@ -0,0 +1,109 @@ +% Manual of pgf-pie.sty, a convenient set of macros for drawing pie +% chart. Written by Xu Yuan This file is part of +% pgf-pie you may get it at http://code.google.com/p/pgf-pie/ + +\documentclass{article} +\usepackage[margin=12mm]{geometry} +\usepackage{hyperref} + +\usepackage{pgf-pie} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage{listings} +\usepackage{color} +\definecolor{listinggray}{gray}{0.92} +\lstset{ % +language=[LaTeX]TeX, +breaklines=true, +frame=single, +% frameround=tttt, +basicstyle=\footnotesize\ttfamily, +backgroundcolor=\color{listinggray}, +keywordstyle=\color{blue} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\hypersetup{ + colorlinks=true, + linkcolor=blue, + anchorcolor=black, + citecolor=olive, + filecolor=magenta, + menucolor=red, + urlcolor=blue +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\demo}[2][1]{ +\begin{minipage}{.49\linewidth} +\centering +\resizebox{#1\linewidth}{!}{ +\input{demo/#2} +} +\end{minipage} +\hspace{0.01\linewidth} +\begin{minipage}{.5\linewidth} +\lstinputlisting{demo/#2} +\end{minipage} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\example}[1]{ +\resizebox{\linewidth}{!}{ +\input{demo/#1} +} +\lstinputlisting{demo/#1} +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{document} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\title{Drawing Pie Chart by using \texttt{pgf-pie}} +\author{\href{mailto:xuyuan.cn@gmail.com}{Yuan Xu}} +\date{\today{}~(v0.1)} +\maketitle +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{abstract} + \texttt{pgf-pie} is a LaTeX package for drawing pie chart. As stated + by its name, it is based on a very popular graphic package + \texttt{PGF/TikZ}. This document presents the usage of + \texttt{pgf-pie} and collects some pie charts as examples. + \texttt{pgf-pie} can be downloaded from + \href{http://code.google.com/p/pgf-pie/}{http://code.google.com/p/pgf-pie/}. +\end{abstract} + +\tableofcontents + +\section{The Essentials} + + +\section{Examples} + +\demo[0.6]{pie} + +% \pie{20/, 4/, 11/, 49/, 16/} + +% \pie{20/type A, 4/type B, 11/type C, 49/type D, 16/other} + +% \pie[explode={0, 0.01, 0},]{20/type A, 4/type B, 11/type C, 49/type D, 16/other} + +% \pie[explode={0, 0.01}, colormap=black!10]{20/type A, 4/type B, +% 11/type C, 49/type D, 16/other} + +% \pie{10/, 10/, 10/, 10/, 10/, 10/, 10/, 10/, 10/, 10/ } + +% \section{Acknowledgements} +% Many people contributed to \texttt{pgf-pie} by reporting problems, +% suggesting various improvements or submitting code. Here is a list of +% these people: +% \href{mailto:???}{name}. + +\end{document} +%%% Local Variables: +%%% mode: Tex-PDF +%%% TeX-master: t +%%% End: diff --git a/dev/pgf-pie.sty b/dev/pgf-pie.sty new file mode 100644 index 0000000..64c01cc --- /dev/null +++ b/dev/pgf-pie.sty @@ -0,0 +1,99 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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 +% + +\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} + +\newcommand{\pgfpie@slice}[6]{ + \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; + + % outer label + \node[label=\midangle:#4] at (\midangle:1) {}; + + % inner label + \pgfmathparse{min((#2-#1-10)/110*(-0.3),0)} + \let\temp\pgfmathresult + \pgfmathparse{max(\temp,-0.5) + 0.8} + \let\innerpos\pgfmathresult + \node at (\midangle:\innerpos) {#3}; +} + +\newcounter{a} +\newcounter{b} +\newcounter{explodelength} +\newcounter{colormaplength} + +\def\setexplode#1\pgfeov{\def\explode{#1}} +\pgfkeyslet{/explode/.@cmd}{\setexplode} + +\def\setcolormap#1\pgfeov{\def\colormap{#1}} +\pgfkeyslet{/colormap/.@cmd}{\setcolormap} + +\newcommand{\pie}[2][] +{ + \pgfkeys{explode=0, + colormap={blue!60, cyan!60, yellow!60, orange!60, red!60}} + \pgfkeys{#1} + + \def\explodearray{{\explode}} + \setcounter{explodelength}{0} + \foreach \e in \explode { \addtocounter{explodelength}{1} } + + \setcounter{colormaplength}{0} + + \foreach \c in \colormap { + \addtocounter{colormaplength}{1} + } + + \setcounter{b}{0} + \begin{tikzpicture}[scale=3, +% x={(1cm,0cm)}, y={(0cm,0.5cm)} +] + + \foreach \p/\t [count=\i from 0] in {#2} + { + \setcounter{a}{\value{b}} + \addtocounter{b}{\p} + + % find explode + \pgfmathparse{\explodearray[int(mod(\i,\value{explodelength}))]} + \let\e\pgfmathresult + + % find color + \pgfmathparse{int(mod(\i,\value{colormaplength}))} + \let\ci\pgfmathresult + \foreach \c [count=\j from 0] in \colormap { + \ifnum \j=\ci + \xdef\thecolor{\c} + \breakforeach + \fi + } + + \pgfpie@slice{\thea/100*360} + {\theb/100*360} + {\p\%}{\t} + {\e} + {\thecolor} + } + + \end{tikzpicture} +} + +%%% End of pgf-pie.sty +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + -- cgit v1.2.3