summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/sankey/sankey-example4.tex
blob: 7b5e17e20fa66d403fdd50e91067fdd1bc562d51 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
\begin{tikzpicture}
  \renewcommand*\sfdefault{txss}
  \sffamily
  \sisetup{
    detect-all=true,
    group-separator={,},
    group-minimum-digits=4,
  }
  % storage of labels
  \newcommand\LabSet[2]{% node name, label
    \expandafter\edef\csname#1@Lab\endcsname{#2}}
  \newcommand\Lab[1]{% node name
    \csname#1@Lab\endcsname}
  % storage of quantities
  \newcommand\QtySet[2]{% node name, quantity
    \expandafter\edef\csname#1@Qty\endcsname{\fpeval{#2}}}
  \newcommand\Qty[1]{% node name
    \csname#1@Qty\endcsname}
  % all nodes with their name, label and quantity
  \sankeyset{
    def data/.code args={#1/#2/#3}{% node name/label/values
      \LabSet{#1}{#2}
      \QtySet{#1}{#3}
      \typeout{#1: \Qty{#1}€ (\Lab{#1})}
    },
    def data/.list={
      {Pf/Processing\\fees/71713},
      {Sog/Sales of\\good/4547},
      {Sf/Settlement\\fees/842075},
      {Os/Other\\services/37532},
      {R/Revenues/\Qty{Pf}+\Qty{Sog}+\Qty{Sf}+\Qty{Os}},
      {Coi/Cost of Inventory/5151},
      {Ciffi/Cost insecure from financial institutions/758234},
      {Nr/Net revenue/\Qty{R}-\Qty{Coi}-\Qty{Ciffi}},
      {Aadotaifa/Amortization and\\depreciation of tangible and\\
        intangible fixed assets/4688},
      {Ssapc/Social securities and\\pension costs/7860},
      {Was/Wages and salaries/35627},
      {Ooe/Other operating expenses/37346},
      {Nr2/-/\Qty{Nr}-\Qty{Aadotaifa}-\Qty{Ssapc}-\Qty{Was}-\Qty{Ooe}},
      {Oi/Other income/47},
      {Ibiiieait/Income before interest income,\\interest expense and
        income taxes/\Qty{Nr2}+\Qty{Oi}},
      {Fe/Finance expense/561},
      {Ofr/Other financial results/2533},
      {Ibiiieait2/-/\Qty{Ibiiieait}-\Qty{Fe}-\Qty{Ofr}},
      {Fi/Finance income/204},
      {Ibit/Income before income taxes/\Qty{Ibiiieait2}+\Qty{Fi}},
      {It/Income taxes/21134},
      {Niftp/Net income for the period/\Qty{Ibit}-\Qty{It}},
      {Octa/Other currency\\translation adjustments/785},
      {Tci/Total comprehensive income/\Qty{Niftp}+\Qty{Octa}}
    },
  }

  \definecolor{mygreen}{RGB}{9,192,82}
  \tikzset{
    cost node/.style={
      overlay,
      align=flush center,
      node font=\footnotesize\sffamily\bfseries,
      inner sep=0,
      node contents={%
        {\mdseries€\,\num{\Qty{#1}}}\\
        \Lab{#1}\vphantom{g}%
      },
    },
    white hash/.style={
      draw=none,fill=none,
      pattern={Lines[angle=60,line width=2pt,distance=4pt]},
      pattern color=white,
    },
    line sep/.style={draw=white,line width=1pt},
    left label/.style={left=#1,align=flush right,anchor=north east},
    right label/.style={right=#1,align=flush left},
    right label hashed/.style={
      right=1mm of $(#1.left)!.5!(#1-old.left)$,align=flush left,
    },
    left label hashed/.style={
      left=1mm of $(#1.right)!.5!(#1-old.right)$,align=flush right,
    },
  }

  \newcommand\turnandstop[1]{
    \sankeyturn[green to greenwhite]{#1}{-90}
    \sankeynode{as=#1,name=#1-e,at={#1 -| Coi}}
    \sankeyoutin[greenwhite to white]{#1}{#1-e}
    \node[cost node=#1,left label={1mm of #1-e.right}];
  }

  \begin{sankeydiagram}%[debug]
    \sankeyset{
      ratio=28em/1000000,
      minimum radius=2cm,
      start style=none,
      every node/.style={angle=-90},
      % default fill and draw styles
      fill/.style={
        line width=0pt,
        fill=mygreen,
      },
      draw/.style={draw=none},
      % specific fill and draw styles
      green to greenwhite/.style={
        fill/.style={
          line width=0pt,
          right color=mygreen,
          left color=mygreen!20!white,
        }
      },
      greenwhite to white/.style={
        fill/.style={
          line width=0pt,
          right color=mygreen!20!white,
          left color=mygreen!5!white,
        }
      },
      dashed/.style={draw/.style={draw=mygreen,dashed}},
    }

    \coordinate (top) at (0,2em);

    \sankeynodestart{name=Pf,quantity=\Qty{Pf}}
    \node[cost node=Pf,above=.5em of Pf.center];

    \sankeynodestart{name=Sog,quantity=\Qty{Sog},
      at={[xshift=4em]Pf.left},anchor=right}
    \node[cost node=Sog,above=.5em of Sog.center];

    \sankeynodestart{name=Sf,quantity=\Qty{Sf},
      at={[xshift=2em]Sog.left},anchor=right}
    \node[cost node=Sf,above=.5em of Sf.center];

    \sankeynodestart{name=Os,quantity=\Qty{Os},
      at={[xshift=2em]Sf.left},anchor=right}
    \node[cost node=Os,above=.5em of Os.center];

    \sankeynode{
      name=R,quantity=\Qty{R},at={[yshift=-10em]Sf.center},
      forked={\Qty{Os}/Os-a,\Qty{Sf}/Sf-a,\Qty{Sog}/Sog-a,\Qty{Pf}/Pf-a},
    }

    \foreach \nodename in {Pf,Sog,Sf,Os}{
      \sankeyoutin[fill/.style={top color=white,bottom color=mygreen}]
      {\nodename}{\nodename-a}
    }

    \sankeyadvance{R}{1em}
    \node[cost node=R,right label hashed=R];

    \sankeyfork{R}{\Qty{Ciffi}/Ciffi,\Qty{Nr}/Nr,\Qty{Coi}/Coi}

    \sankeyturnleft[minimum radius=1.cm]{Ciffi}{90}
    \node[cost node=Ciffi,at={([shift={(1mm,0)}]Ciffi.center)},rotate=-90,
    anchor=south,align=flush left,node font=\scriptsize\sffamily\bfseries];

    \sankeyturnright[green to greenwhite]{Coi}{90}
    \sankeyadvance[greenwhite to white]{Coi}{1em}
    \node[cost node=Coi,left={1mm of [yshift=.75ex]Coi.left},
    align=flush right,anchor=north east,overlay];

    \sankeyadvance{Nr}{9em}
    \sankeyadvance{Nr}{1em}
    \node[cost node=Nr,left label hashed=Nr,
    node font=\large\sffamily\bfseries];

    \sankeyfork{Nr}{\Qty{Nr2}/Nr2,\Qty{Ooe}/Ooe,
      \Qty{Was}/Was,\Qty{Ssapc}/Ssapc,\Qty{Aadotaifa}/Aadotaifa}

    \turnandstop{Aadotaifa}

    \sankeyadvance{Ssapc}{5em}
    \turnandstop{Ssapc}

    \sankeyadvance{Was}{9em}
    \turnandstop{Was}

    \sankeyadvance{Ooe}{12em}
    \turnandstop{Ooe}

    \sankeyadvance{Nr2}{15em}
    \sankeynode{name=Ibiiieait,quantity=\Qty{Ibiiieait},
      anchor=right,at={Nr2.right},
      forked={\Qty{Oi}/Oi,\Qty{Nr2}/Nr2-e}}

    \sankeyturnleftbackward[minimum radius=1cm,dashed]{Oi}{90}
    \node[cost node=Oi,right label=1mm of Oi.left];

    \sankeyadvance{Ibiiieait}{1em}
    \node[cost node=Ibiiieait,right label hashed=Ibiiieait];

    \sankeyfork{Ibiiieait}
    {\Qty{Ibiiieait2}/Ibiiieait2,\Qty{Ofr}/Ofr,\Qty{Fe}/Fe}

    \turnandstop{Fe}

    \sankeyadvance{Ofr}{3em}
    \turnandstop{Ofr}

    \sankeyadvance{Ibiiieait2}{6em}
    \sankeynode{name=Ibit,quantity={\Qty{Ibiiieait2}+\Qty{Fi}},
      anchor=right,at={Ibiiieait2.right},
      forked={\Qty{Fi}/Fi,\Qty{Ibiiieait2}/Ibiiieait2-e}}

    \sankeyturnleftbackward[minimum radius=1cm,dashed]{Fi}{90}
    \node[cost node=Fi,right label=1mm of Fi.left];

    \sankeyadvance{Ibit}{1em}
    \node[cost node=Ibit,right label hashed=Ibit];

    \sankeyfork{Ibit}{\Qty{Niftp}/Niftp,\Qty{It}/It}

    \turnandstop{It}

    \sankeyadvance{Niftp}{6em}

    \sankeyadvance{Niftp}{1em}
    \node[cost node=Niftp,right label hashed=Niftp];

    \sankeynode{name=Tci,quantity=\Qty{Niftp}+\Qty{Octa},
      anchor=right,at={[yshift=-6em]Niftp.right},
      forked={\Qty{Octa}/Octa,\Qty{Niftp}/Niftp-e}}
    \sankeyoutin{Niftp}{Niftp-e}

    \sankeyturnleftbackward[minimum radius=1cm]{Octa}{90}
    \node[cost node=Octa,right label=1mm of Octa.left];

    \sankeyadvance{Tci}{1em}
    \node[cost node=Tci,right label hashed=Tci];

    \newcommand\hashband[1]{
      \draw[line sep] (#1-old.right) -- (#1-old.left);
      \draw[line sep] (#1.right) -- (#1.left);
      \path[white hash] (#1-old.right) rectangle (#1.left);
    }

    \foreach \nodename in {R,Nr,Nr,Ibiiieait,Ibit,Niftp,Tci}{
      \hashband{\nodename}
    }

  \end{sankeydiagram}
\end{tikzpicture}