Emacs: Pie chart support.

master
Ambrevar 2012-10-13 13:31:27 +02:00
parent da6611d4e6
commit 205c12dd61
5 changed files with 162 additions and 2 deletions

View File

@ -123,9 +123,12 @@
;; TeX and LaTeX
;;==============================================================================
(setq tex-run-command "pdftex")
;; Let's use pdftex.
;; To use GnuPlot we need to allow external application to be called from TeX.
;; WARNING: the "--shell-escape" option is a potential security issue.
(setq tex-run-command "pdftex --shell-escape")
;; (setq tex-command "pdftex") ; Same as above ?
(setq latex-run-command "pdflatex")
(setq latex-run-command "pdflatex --shell-escape")
;; TODO: display in TeX/LaTeX only.
(defun tex-pdf-view ()

View File

@ -0,0 +1,81 @@
# -*- mode: snippet -*-
# contributor : Pierre Neidhardt <ambrevar at gmail dot com> 2012-08-22
# key: piegen
# group: tikz
# name: pie chart generator
# --
\newcounter{pieSlicePercentage}
\newcounter{pieCounterCurrent}
\newcounter{pieCounterNext}
\newcounter{pieCounterTotal}
\newcommand{\pieslice}[3]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
\setcounter{pieSlicePercentage}{\p*100/\thepieCounterTotal}
% slice
\draw[thick,fill=#3!\thepieSlicePercentage] (0,0) -- (#1:1) arc (#1:#2:1) -- cycle;
}
\newcommand{\pieslicelabel}[3]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
\setcounter{pieSlicePercentage}{\p*100/\thepieCounterTotal}
% Outer label.
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
\let\temp\pgfmathresult
\pgfmathparse{max(\temp,-0.5) + 1.55}
\let\outerpos\pgfmathresult
\node at (\midangle:\outerpos) {\textbf{#3}};
% 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) {\thepieSlicePercentage \%};
}
\newcommand{\piechart}[3]{
\setcounter{pieCounterCurrent}{0}
\setcounter{pieCounterNext}{0}
\setcounter{pieCounterTotal}{0}
\begin{center}
\begin{tikzpicture}[scale=#2]
%% Get the total to turn the values into percentages.
\foreach \p/\t in {#3} {
\setcounter{pieCounterTotal}{\thepieCounterTotal+\p}
}
%% Draw the slices.
\foreach \p/\t in {#3} {
\setcounter{pieCounterCurrent}{\value{pieCounterNext}}
\addtocounter{pieCounterNext}{\p}
\pieslice{\thepieCounterCurrent/\thepieCounterTotal*360}
{\thepieCounterNext/\thepieCounterTotal*360}
{#1}
}
\setcounter{pieCounterCurrent}{0}
\setcounter{pieCounterNext}{0}
%% Write the labels.
\foreach \p/\t in {#3}{
\setcounter{pieCounterCurrent}{\value{pieCounterNext}}
\addtocounter{pieCounterNext}{\p}
\pieslicelabel{\thepieCounterCurrent/\thepieCounterTotal*360}
{\thepieCounterNext/\thepieCounterTotal*360}
{\t}
}
\end{tikzpicture}
\end{center}
}

View File

@ -0,0 +1,7 @@
# -*- mode: snippet -*-
# contributor : Pierre Neidhardt <ambrevar at gmail dot com> 2012-08-22
# key: pie
# group: tikz
# name: pie chart
# --
\piechart{${1:color}}{${2:scale}}{${3:value1/label1, value2/label2,...}}

View File

@ -0,0 +1,10 @@
# -*- mode: snippet -*-
# contributor : Pierre Neidhardt <ambrevar at gmail dot com> 2012-08-22
# key: plot
# group: tikz
# name: plot
# --
\\${1:plottype}{${2:plotname}}%
{${3:abscissa legend}}
{${4:ordinate legend}}
$0

View File

@ -0,0 +1,59 @@
# -*- mode: snippet -*-
# contributor : Pierre Neidhardt <ambrevar at gmail dot com> 2012-08-22
# key: plotgen
# group: tikz
# name: plot generator
# --
\newcommand{\\${1}}[7]{
\begin{figure}[h!]
\caption{#1}
\begin{center}
\begin{tikzpicture}[scale=0.5,x=1cm,y=0.15cm]
%% User parameters.
\def\xmin{0}
\def\xmax{10}
\def\ymin{0}
\def\ymax{60}
\def\xstep{1}
\def\ystep{10}
%% Grid
\draw[style=help lines, ystep=\ystep, xstep=\xstep] (\xmin,\ymin) grid
(\xmax,\ymax);
%% Axes
\draw[->] (\xmin,\ymin) -- (\xmax+0.5*\xstep,\ymin)
node[below,yshift=-1em] {#2};
\draw[->] (\xmin,\ymin) -- (\xmin,\ymax+0.5*\ystep)
node[above] {#3};
%% xticks and yticks
\foreach \x in {\xmin,\xstep,...,\xmax}
\node at (\x, \ymin) [below] {\x};
\foreach \y in {\ymin,\ystep,...,\ymax}
\node at (\xmin,\y) [left] {\y};
%% DATA
%% Example from file.
%% Smooth the curve and mark the data point with a dot.
%% Data should be stored as
%% x1 y1
%% x2 y2
% \draw[color=blue]
% plot[smooth,mark=*,mark size=1pt, id=iter_sorted]
% file {#5}
% node [right] {#4};
%% Example trendline
%% \draw[color=orange,domain=\xmin+\xstep:\xmax]
%% plot[smooth, raw gnuplot, id=trend3]
%% function{f(x)=a*x*log(x)+b; fit f(x) '#5' via a,b; plot f(x)}
%% node [right,yshift=1em] {$\alpha_1 \cdot n\cdot \log(n) + \beta_1$};
$0
\end{tikzpicture}
\end{center}
\end{figure}
}