banking-breakdown/res/report.tex

217 lines
5.0 KiB
TeX

\documentclass{article}
% Packages necessary for common.tex
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{pgfplots.dateplot}
% Other packages
\usepackage[a4paper, total={12cm, 25cm}]{geometry}
\usepackage{float}
\usepackage{calc}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage[l3]{csvsimple}
\usepackage{subcaption}
\usepackage{lmodern,textcomp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Set common options %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../lib/latex-common/common.tex}
\pgfplotsset{colorscheme/rocket}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Define Custom Commands %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand*\shortyear[1]{\expandafter\@gobbletwo\number\numexpr#1\relax}
\makeatother
\newcommand{\slice}[6]{
\pgfmathparse{0.5*#1+0.5*#2}
\let\midangle\pgfmathresult
% slice
\fill[thick,color=#5] (0,0) -- (#1:1) arc (#1:#2+1:1) -- (0,0);
% 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[color=#6] at (\midangle:\innerpos) {#3};
}
\newcounter{pieElem}
\newcounter{pieSliceA}
\newcounter{pieSliceB}
\newcommand{\pie}[1]{
% Count elements
\setcounter{pieElem}{0}%
\foreach\pieElem in {#1}{\stepcounter{pieElem}}%
\edef\numElements{\arabic{pieElem}}
% Draw pie chart
\setcounter{pieSliceA}{0}%
\setcounter{pieSliceB}{0}%
\foreach \xi/\t [count=\xk from 0] in {#1} {
% Get colors
\pgfmathparse{1000 / (\numElements - 1) * \xk}
\extractcolormapcolor{pieColor\xk}{\pgfmathresult}
\pgfmathparse{(\xk / \numElements < 0.5)*1000}
\extractcolormapcolor{pieTextColor\xk}{\pgfmathresult}
% Draw slice
\setcounter{pieSliceA}{\thepieSliceB}
\addtocounter{pieSliceB}{\xi}
\slice{\thepieSliceA/100*360}{\thepieSliceB/100*360}{\xi\%}{\t}{pieColor\xk}{pieTextColor\xk}
}
}
\newcommand{\csvPie}[1]{
% Count elements
\setcounter{pieElem}{0}%
\csvreader[head to column names]{#1}{}{%
\stepcounter{pieElem}
}
\edef\numElements{\arabic{pieElem}}
% Draw pie chart
\setcounter{pieElem}{0}%
\setcounter{pieSliceA}{0}%
\setcounter{pieSliceB}{0}%
\csvreader[head to column names]{#1}{}{%
% Get colors
\pgfmathparse{1000 / (\numElements - 1) * \thepieElem}
\extractcolormapcolor{pieColor\thepieElem}{\pgfmathresult}
\pgfmathparse{(\thepieElem / \numElements < 0.5)*1000}
\extractcolormapcolor{pieTextColor\thepieElem}{\pgfmathresult}
% Draw slice
\setcounter{pieSliceA}{\thepieSliceB}
\addtocounter{pieSliceB}{10*\real{\value}}
\slice{\thepieSliceA/1000*360}{\thepieSliceB/1000*360}{\value\%}{\category}
{pieColor\thepieElem}{pieTextColor\thepieElem}
\stepcounter{pieElem}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Actual Document %%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{Expense Report\vspace{-1cm}}
\author{}
\begin{document}
\maketitle
\vspace{1cm}
\begin{figure}[H]
\centering
\begin{tikzpicture}[scale=2.5]
\csvPie{category_overview.csv}
\end{tikzpicture}
\caption{Total percenteage of expenses by category}
\end{figure}
\begin{figure}[H]
\centering
\begin{subfigure}[t]{\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
width=\textwidth,
height=0.375\textwidth,
ylabel={Net income in €},
y label style={at={(-0.1,0.5)},anchor=south},
xticklabel=\month.\shortyear{\year},
xtick=data,
xticklabel style={
rotate=60,
anchor=near xticklabel,
},
grid,
enlarge x limits=0.03,
]
% Dummy plot to set x axis ticks
\addplot[draw=none]
table[col sep=comma, x=t, y=value]
{net_income.csv};
% Dummy plot to set x axis scale
\addplot[draw=none]
table[col sep=comma, x=t, y=value]
{detailed_balance.csv};
\addplot[ybar, color=scol2, fill=scol2, line width=1pt]
table[col sep=comma, x=t, y=value, discard if lt={value}{0}]
{net_income.csv};
\addplot[ybar, color=scol0, fill=scol0, line width=1pt]
table[col sep=comma, x=t, y=value, discard if gt={value}{0}]
{net_income.csv};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[t]{\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
width=\textwidth,
height=0.375\textwidth,
ylabel={Total balance in €},
y label style={at={(-0.1,0.5)},anchor=south},
xticklabel=\month.\shortyear{\year},
xtick=data,
enlarge x limits=0.03,
xticklabel style={
rotate=60,
anchor=near xticklabel,
},
grid,
]
% Dummy plot to set x axis ticks
\addplot[draw=none]
table[col sep=comma, x=t, y=value]
{total_value.csv};
\addplot[scol3, mark=none, line width=1pt]
table[col sep=comma, x=t, y=value]
{detailed_balance.csv};
\addplot[scol1, mark=none, line width=1pt]
table[col sep=comma, x=t, y=value]
{total_value.csv};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\caption{Development of account balance over time}
\end{figure}
\end{document}