Debian Codegraph @

texmf-dist/doc/latex/sankey/sankey-example4.tex

raw
1 \begin{tikzpicture}
2 \renewcommand*\sfdefault{txss}
3 \sffamily
4 \sisetup{
5 detect-all=true,
6 group-separator={,},
7 group-minimum-digits=4,
8 }
9 % storage of labels
10 \newcommand\LabSet[2]{% node name, label
11 \expandafter\edef\csname#1@Lab\endcsname{#2}}
12 \newcommand\Lab[1]{% node name
13 \csname#1@Lab\endcsname}
14 % storage of quantities
15 \newcommand\QtySet[2]{% node name, quantity
16 \expandafter\edef\csname#1@Qty\endcsname{\fpeval{#2}}}
17 \newcommand\Qty[1]{% node name
18 \csname#1@Qty\endcsname}
19 % all nodes with their name, label and quantity
20 \sankeyset{
21 def data/.code args={#1/#2/#3}{% node name/label/values
22 \LabSet{#1}{#2}
23 \QtySet{#1}{#3}
24 \typeout{#1: \Qty{#1}€ (\Lab{#1})}
25 },
26 def data/.list={
27 {Pf/Processing\\fees/71713},
28 {Sog/Sales of\\good/4547},
29 {Sf/Settlement\\fees/842075},
30 {Os/Other\\services/37532},
31 {R/Revenues/\Qty{Pf}+\Qty{Sog}+\Qty{Sf}+\Qty{Os}},
32 {Coi/Cost of Inventory/5151},
33 {Ciffi/Cost insecure from financial institutions/758234},
34 {Nr/Net revenue/\Qty{R}-\Qty{Coi}-\Qty{Ciffi}},
35 {Aadotaifa/Amortization and\\depreciation of tangible and\\
36 intangible fixed assets/4688},
37 {Ssapc/Social securities and\\pension costs/7860},
38 {Was/Wages and salaries/35627},
39 {Ooe/Other operating expenses/37346},
40 {Nr2/-/\Qty{Nr}-\Qty{Aadotaifa}-\Qty{Ssapc}-\Qty{Was}-\Qty{Ooe}},
41 {Oi/Other income/47},
42 {Ibiiieait/Income before interest income,\\interest expense and
43 income taxes/\Qty{Nr2}+\Qty{Oi}},
44 {Fe/Finance expense/561},
45 {Ofr/Other financial results/2533},
46 {Ibiiieait2/-/\Qty{Ibiiieait}-\Qty{Fe}-\Qty{Ofr}},
47 {Fi/Finance income/204},
48 {Ibit/Income before income taxes/\Qty{Ibiiieait2}+\Qty{Fi}},
49 {It/Income taxes/21134},
50 {Niftp/Net income for the period/\Qty{Ibit}-\Qty{It}},
51 {Octa/Other currency\\translation adjustments/785},
52 {Tci/Total comprehensive income/\Qty{Niftp}+\Qty{Octa}}
53 },
54 }
55
56 \definecolor{mygreen}{RGB}{9,192,82}
57 \tikzset{
58 cost node/.style={
59 overlay,
60 align=flush center,
61 node font=\footnotesize\sffamily\bfseries,
62 inner sep=0,
63 node contents={%
64 {\mdseries€\,\num{\Qty{#1}}}\\
65 \Lab{#1}\vphantom{g}%
66 },
67 },
68 white hash/.style={
69 draw=none,fill=none,
70 pattern={Lines[angle=60,line width=2pt,distance=4pt]},
71 pattern color=white,
72 },
73 line sep/.style={draw=white,line width=1pt},
74 left label/.style={left=#1,align=flush right,anchor=north east},
75 right label/.style={right=#1,align=flush left},
76 right label hashed/.style={
77 right=1mm of $(#1.left)!.5!(#1-old.left)$,align=flush left,
78 },
79 left label hashed/.style={
80 left=1mm of $(#1.right)!.5!(#1-old.right)$,align=flush right,
81 },
82 }
83
84 \newcommand\turnandstop[1]{
85 \sankeyturn[green to greenwhite]{#1}{-90}
86 \sankeynode{as=#1,name=#1-e,at={#1 -| Coi}}
87 \sankeyoutin[greenwhite to white]{#1}{#1-e}
88 \node[cost node=#1,left label={1mm of #1-e.right}];
89 }
90
91 \begin{sankeydiagram}%[debug]
92 \sankeyset{
93 ratio=28em/1000000,
94 minimum radius=2cm,
95 start style=none,
96 every node/.style={angle=-90},
97 % default fill and draw styles
98 fill/.style={
99 line width=0pt,
100 fill=mygreen,
101 },
102 draw/.style={draw=none},
103 % specific fill and draw styles
104 green to greenwhite/.style={
105 fill/.style={
106 line width=0pt,
107 right color=mygreen,
108 left color=mygreen!20!white,
109 }
110 },
111 greenwhite to white/.style={
112 fill/.style={
113 line width=0pt,
114 right color=mygreen!20!white,
115 left color=mygreen!5!white,
116 }
117 },
118 dashed/.style={draw/.style={draw=mygreen,dashed}},
119 }
120
121 \coordinate (top) at (0,2em);
122
123 \sankeynodestart{name=Pf,quantity=\Qty{Pf}}
124 \node[cost node=Pf,above=.5em of Pf.center];
125
126 \sankeynodestart{name=Sog,quantity=\Qty{Sog},
127 at={[xshift=4em]Pf.left},anchor=right}
128 \node[cost node=Sog,above=.5em of Sog.center];
129
130 \sankeynodestart{name=Sf,quantity=\Qty{Sf},
131 at={[xshift=2em]Sog.left},anchor=right}
132 \node[cost node=Sf,above=.5em of Sf.center];
133
134 \sankeynodestart{name=Os,quantity=\Qty{Os},
135 at={[xshift=2em]Sf.left},anchor=right}
136 \node[cost node=Os,above=.5em of Os.center];
137
138 \sankeynode{
139 name=R,quantity=\Qty{R},at={[yshift=-10em]Sf.center},
140 forked={\Qty{Os}/Os-a,\Qty{Sf}/Sf-a,\Qty{Sog}/Sog-a,\Qty{Pf}/Pf-a},
141 }
142
143 \foreach \nodename in {Pf,Sog,Sf,Os}{
144 \sankeyoutin[fill/.style={top color=white,bottom color=mygreen}]
145 {\nodename}{\nodename-a}
146 }
147
148 \sankeyadvance{R}{1em}
149 \node[cost node=R,right label hashed=R];
150
151 \sankeyfork{R}{\Qty{Ciffi}/Ciffi,\Qty{Nr}/Nr,\Qty{Coi}/Coi}
152
153 \sankeyturnleft[minimum radius=1.cm]{Ciffi}{90}
154 \node[cost node=Ciffi,at={([shift={(1mm,0)}]Ciffi.center)},rotate=-90,
155 anchor=south,align=flush left,node font=\scriptsize\sffamily\bfseries];
156
157 \sankeyturnright[green to greenwhite]{Coi}{90}
158 \sankeyadvance[greenwhite to white]{Coi}{1em}
159 \node[cost node=Coi,left={1mm of [yshift=.75ex]Coi.left},
160 align=flush right,anchor=north east,overlay];
161
162 \sankeyadvance{Nr}{9em}
163 \sankeyadvance{Nr}{1em}
164 \node[cost node=Nr,left label hashed=Nr,
165 node font=\large\sffamily\bfseries];
166
167 \sankeyfork{Nr}{\Qty{Nr2}/Nr2,\Qty{Ooe}/Ooe,
168 \Qty{Was}/Was,\Qty{Ssapc}/Ssapc,\Qty{Aadotaifa}/Aadotaifa}
169
170 \turnandstop{Aadotaifa}
171
172 \sankeyadvance{Ssapc}{5em}
173 \turnandstop{Ssapc}
174
175 \sankeyadvance{Was}{9em}
176 \turnandstop{Was}
177
178 \sankeyadvance{Ooe}{12em}
179 \turnandstop{Ooe}
180
181 \sankeyadvance{Nr2}{15em}
182 \sankeynode{name=Ibiiieait,quantity=\Qty{Ibiiieait},
183 anchor=right,at={Nr2.right},
184 forked={\Qty{Oi}/Oi,\Qty{Nr2}/Nr2-e}}
185
186 \sankeyturnleftbackward[minimum radius=1cm,dashed]{Oi}{90}
187 \node[cost node=Oi,right label=1mm of Oi.left];
188
189 \sankeyadvance{Ibiiieait}{1em}
190 \node[cost node=Ibiiieait,right label hashed=Ibiiieait];
191
192 \sankeyfork{Ibiiieait}
193 {\Qty{Ibiiieait2}/Ibiiieait2,\Qty{Ofr}/Ofr,\Qty{Fe}/Fe}
194
195 \turnandstop{Fe}
196
197 \sankeyadvance{Ofr}{3em}
198 \turnandstop{Ofr}
199
200 \sankeyadvance{Ibiiieait2}{6em}
201 \sankeynode{name=Ibit,quantity={\Qty{Ibiiieait2}+\Qty{Fi}},
202 anchor=right,at={Ibiiieait2.right},
203 forked={\Qty{Fi}/Fi,\Qty{Ibiiieait2}/Ibiiieait2-e}}
204
205 \sankeyturnleftbackward[minimum radius=1cm,dashed]{Fi}{90}
206 \node[cost node=Fi,right label=1mm of Fi.left];
207
208 \sankeyadvance{Ibit}{1em}
209 \node[cost node=Ibit,right label hashed=Ibit];
210
211 \sankeyfork{Ibit}{\Qty{Niftp}/Niftp,\Qty{It}/It}
212
213 \turnandstop{It}
214
215 \sankeyadvance{Niftp}{6em}
216
217 \sankeyadvance{Niftp}{1em}
218 \node[cost node=Niftp,right label hashed=Niftp];
219
220 \sankeynode{name=Tci,quantity=\Qty{Niftp}+\Qty{Octa},
221 anchor=right,at={[yshift=-6em]Niftp.right},
222 forked={\Qty{Octa}/Octa,\Qty{Niftp}/Niftp-e}}
223 \sankeyoutin{Niftp}{Niftp-e}
224
225 \sankeyturnleftbackward[minimum radius=1cm]{Octa}{90}
226 \node[cost node=Octa,right label=1mm of Octa.left];
227
228 \sankeyadvance{Tci}{1em}
229 \node[cost node=Tci,right label hashed=Tci];
230
231 \newcommand\hashband[1]{
232 \draw[line sep] (#1-old.right) -- (#1-old.left);
233 \draw[line sep] (#1.right) -- (#1.left);
234 \path[white hash] (#1-old.right) rectangle (#1.left);
235 }
236
237 \foreach \nodename in {R,Nr,Nr,Ibiiieait,Ibit,Niftp,Tci}{
238 \hashband{\nodename}
239 }
240
241 \end{sankeydiagram}
242 \end{tikzpicture}