| 1 |
% \iffalse meta-comment |
| 2 |
% vim: tw=80 spl=en |
| 3 |
% |
| 4 |
%% File: statistics.dtx (C) Copyright 2014-2019 RIVAUD Julien |
| 5 |
%% |
| 6 |
%% It may be distributed and/or modified under the conditions of the |
| 7 |
%% General Public License (GPL), either version 3 of this |
| 8 |
%% license or (at your option) any later version. |
| 9 |
% |
| 10 |
%<*driver|package> |
| 11 |
% The version of expl3 required is tested as early as possible, as |
| 12 |
% some really old versions do not define \ProvidesExplPackage. |
| 13 |
\NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 14 |
\RequirePackage{expl3}[2018/06/19] |
| 15 |
%</driver|package> |
| 16 |
%<*driver> |
| 17 |
\documentclass[full]{l3doc} |
| 18 |
\usepackage{statistics} |
| 19 |
\usepackage{fontspec} |
| 20 |
\usepackage{xparse} |
| 21 |
\usepackage{xcolor} |
| 22 |
\usepackage{geometry} |
| 23 |
\usetikzlibrary{patterns} |
| 24 |
\geometry{ |
| 25 |
a4paper, |
| 26 |
vmargin=2.5cm, right=1.5cm, textwidth=385pt, |
| 27 |
marginparwidth=21cm-1.5cm-0.5cm-0.4cm-385pt, |
| 28 |
%marginparsep=0.4cm, |
| 29 |
} |
| 30 |
%</driver> |
| 31 |
%<*driver|package> |
| 32 |
\def\ExplFileName{statistics} |
| 33 |
\def\ExplFileDescription{Compute and typeset statistics table and graphics} |
| 34 |
\def\ExplFileDate{2019/09/29} |
| 35 |
\def\ExplFileVersion{2.2} |
| 36 |
%</driver|package> |
| 37 |
%<*driver> |
| 38 |
\ExplSyntaxOn |
| 39 |
\let\tltostr\tl_to_str:N |
| 40 |
\NewDocumentEnvironment{demo}{}{ |
| 41 |
\char_set_catcode_other:N \\ |
| 42 |
\peek_meaning:NTF [ { |
| 43 |
\__statsdocs_demo_begin: |
| 44 |
}{ |
| 45 |
\__statsdocs_demo_begin: [] |
| 46 |
} |
| 47 |
}{ |
| 48 |
\mode_if_vertical:TF { |
| 49 |
\penalty 0 |
| 50 |
}{ |
| 51 |
\par\nobreak |
| 52 |
} |
| 53 |
\skip_vertical:N \abovedisplayskip |
| 54 |
\noindent\leavevmode |
| 55 |
\hbox_set:Nn \l_tmpb_box { |
| 56 |
\colorbox{yellow!5!white}{ |
| 57 |
\parbox{\linewidth}{ |
| 58 |
\raggedright |
| 59 |
\tl_use:N \l_tmpb_tl |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
\hbox_set:Nn \l_tmpa_box { |
| 64 |
\colorbox{blue!5!white}{ |
| 65 |
\parbox{\linewidth}{ |
| 66 |
\ttfamily |
| 67 |
\raggedright |
| 68 |
\tl_use:N \l_tmpa_tl |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
\fp_set:Nn \l_tmpa_fp { |
| 73 |
round( |
| 74 |
3000 * |
| 75 |
\dim_ratio:nn { \box_ht:N \l_tmpb_box } { \box_ht:N \l_tmpa_box } |
| 76 |
) |
| 77 |
} |
| 78 |
\box_use:N \l_tmpa_box \\ \box_use:N \l_tmpb_box |
| 79 |
\int_set:Nn \interlinepenalty {\fp_to_int:N \l_tmpa_fp} |
| 80 |
\par |
| 81 |
\penalty 0 |
| 82 |
\skip_vertical:N \belowdisplayskip |
| 83 |
} |
| 84 |
\cs_new_protected:Nn \__statsdocs_demo_begin: { |
| 85 |
\char_set_catcode_escape:N \\ |
| 86 |
\__statsdocs_demo_begin:w |
| 87 |
} |
| 88 |
\NewDocumentCommand \__statsdocs_demo_begin:w { +O{} } { |
| 89 |
\char_set_catcode_other:N \^^M |
| 90 |
\char_set_catcode_other:n {32} |
| 91 |
\char_set_catcode_other:N \# |
| 92 |
\char_set_catcode_other:N \\ |
| 93 |
\char_set_catcode_other:N \{ |
| 94 |
\char_set_catcode_other:N \} |
| 95 |
\__statsdocs_read_demo:w |
| 96 |
} |
| 97 |
\group_begin: |
| 98 |
\char_set_catcode_group_begin:N \[ |
| 99 |
\char_set_catcode_group_end:N \] |
| 100 |
\char_set_catcode_escape:N \| |
| 101 |
\char_set_catcode_other:N \{ |
| 102 |
\char_set_catcode_other:N \} |
| 103 |
\char_set_catcode_other:N \\ |
| 104 |
|cs_new_protected:Npn |__statsdocs_read_demo:w #1 \end{demo}[ |
| 105 |
|__statsdocs_do_demo:n [#1] |
| 106 |
] |
| 107 |
|group_end: |
| 108 |
\cs_new_protected:Nn \__statsdocs_do_demo:n { |
| 109 |
\str_set:Nn \l_tmpa_str {#1} |
| 110 |
\tl_trim_spaces:N \l_tmpa_str |
| 111 |
\str_set:Nx \l_tmpb_str {\char_generate:nn{`\^^M}{12}} |
| 112 |
\str_if_eq:eeT \l_tmpb_str { \str_head:N \l_tmpa_str } { |
| 113 |
\str_set:Nx \l_tmpa_str { \str_tail:N \l_tmpa_str } |
| 114 |
} |
| 115 |
\tl_reverse:N \l_tmpa_str |
| 116 |
\str_if_eq:eeT \l_tmpb_str { \str_head:N \l_tmpa_str } { |
| 117 |
\str_set:Nx \l_tmpa_str { \str_tail:N \l_tmpa_str } |
| 118 |
} |
| 119 |
\tl_reverse:N \l_tmpa_str |
| 120 |
\tl_set:Nx \l_tmpa_tl {~\l_tmpa_str} |
| 121 |
\exp_args:NNV \tl_replace_all:Nnn \l_tmpa_tl \l_tmpb_str {\par} |
| 122 |
\tl_set:Nx \l_tmpb_tl {\char_generate:nn{32}{12}} |
| 123 |
\exp_args:NNnV \tl_replace_all:Nnn \l_tmpa_tl {~} \l_tmpb_tl |
| 124 |
\exp_args:NNnV \tl_set_rescan:Nnn \l_tmpb_tl { |
| 125 |
\char_set_catcode_escape:N \\ |
| 126 |
\char_set_catcode_space:n {32} |
| 127 |
\char_set_catcode_parameter:N \# |
| 128 |
\char_set_catcode_end_line:N \^^M |
| 129 |
\char_set_catcode_group_begin:N \{ |
| 130 |
\char_set_catcode_group_end:N \} |
| 131 |
} \l_tmpa_str |
| 132 |
\end{demo} |
| 133 |
} |
| 134 |
\ExplSyntaxOff |
| 135 |
\NewDocumentEnvironment{key}{}{\begin{variable}}{\end{variable}} |
| 136 |
\begin{document} |
| 137 |
\DocInput{\jobname.dtx} |
| 138 |
\end{document} |
| 139 |
%</driver> |
| 140 |
% \fi |
| 141 |
% |
| 142 |
% \title{^^A |
| 143 |
% The \textsf{\ExplFileName} package\\ \ExplFileDescription^^A |
| 144 |
% \thanks{This file describes v\ExplFileVersion, |
| 145 |
% last revised \ExplFileDate.}^^A |
| 146 |
% } |
| 147 |
% |
| 148 |
% \author{^^A |
| 149 |
% Julien ``\_FrnchFrgg\_'' \textsc{Rivaud}\thanks |
| 150 |
% {^^A |
| 151 |
% E-mail: |
| 152 |
% \href{mailto:[email protected]} |
| 153 |
% {[email protected]}^^A |
| 154 |
% }^^A |
| 155 |
% } |
| 156 |
% |
| 157 |
% \date{Released \ExplFileDate} |
| 158 |
% |
| 159 |
% \maketitle |
| 160 |
% |
| 161 |
% \tableofcontents |
| 162 |
% |
| 163 |
% \begin{documentation} |
| 164 |
% |
| 165 |
% \section{\pkg{\ExplFileName} documentation} |
| 166 |
% |
| 167 |
% The \pkg{\ExplFileName} package can compute and typeset statistics like |
| 168 |
% frequency tables, cumulative distribution functions (increasing or decreasing, |
| 169 |
% in frequency or absolute count domain), from the counts of individual values, |
| 170 |
% or ranges, or even the raw value list with repetitions. |
| 171 |
% |
| 172 |
% It can also compute and draw a bar diagram in case of individual values, or, |
| 173 |
% when the data repartition is known from ranges, an histogram or the continuous |
| 174 |
% cumulative distribution function. |
| 175 |
% |
| 176 |
% You can ask \pkg{\ExplFileName} to display no result, selective results or all |
| 177 |
% of them. Similarly \pkg{\ExplFileName} can draw only some parts of the graphs. |
| 178 |
% Every part of the generated tables or graphics is customizable. |
| 179 |
% |
| 180 |
% \subsection{Specifying and converting data} |
| 181 |
% |
| 182 |
% To compute and typeset things, \pkg{\ExplFileName} starts from what this |
| 183 |
% documentation calls a \meta{data source}. Such a source can take two forms: |
| 184 |
% \begin{itemize} |
| 185 |
% \item A comma-separated list of \meta{value} |[=| \meta{count} |]|; |
| 186 |
% \item A \cs{\meta{macro}} containing such a list. |
| 187 |
% \end{itemize} |
| 188 |
% |
| 189 |
% If \meta{count} is missing, it defaults to~$1$. \emph{A priori} the |
| 190 |
% \meta{value}s need not be unique nor sorted, but \cs{StatsTable} and |
| 191 |
% \cs{StatsGraph} expect them to be. If you want your data to be in the form of |
| 192 |
% a raw list of unsorted and repeated values, you can thus use the following |
| 193 |
% command to convert the data to a form suitable for \cs{StatsTable} and |
| 194 |
% \cs{StatsGraph}: |
| 195 |
% |
| 196 |
% \begin{function}{\StatsSortData} |
| 197 |
% \begin{syntax} |
| 198 |
% \cs{StatsSortData} \cs{\meta{destination}} = \marg{data source} |
| 199 |
% \end{syntax} |
| 200 |
% This command expect each \meta{value} in the \meta{data source} to be |
| 201 |
% convertible to a floating point number (as understood by \pkg{l3fp} from the |
| 202 |
% \LaTeX3 kernel). It defines \cs{\meta{destination}} to hold an equivalent |
| 203 |
% data source, where \meta{value}s are sorted in increasing order, and |
| 204 |
% \meta{count}s are consolidated. As for all other \pkg{\ExplFileName} |
| 205 |
% commands, \meta{data source} can be either given directly between braces, or |
| 206 |
% as a \cs{\meta{macro}} which contains the list. |
| 207 |
% \end{function} |
| 208 |
% |
| 209 |
% \begin{demo} |
| 210 |
% \StatsSortData \mydata = { 2, 11=8, 6=3, 2=2, 11=1 } |
| 211 |
% \def \rawdata { 2=2, 11=9, 6, 2, 6, 6 } |
| 212 |
% \StatsSortData \yourdata = \rawdata |
| 213 |
% mydata contains [\mydata]\\ |
| 214 |
% yourdata contains [\yourdata] |
| 215 |
% \end{demo} |
| 216 |
% |
| 217 |
% The \cs{StatsTable} command will always assume that the \meta{data source} is |
| 218 |
% sorted and will not try to parse the \meta{value}s. On the contrary, |
| 219 |
% \cs{StatsGraph} \emph{will} parse each \meta{value}, and will act differently |
| 220 |
% depending on whether every \meta{value} is a \meta{range} or the form |
| 221 |
% \hbox{\cs{IN} \meta{|[| or |]|} \meta{min} |;| \meta{max} \meta{|[| or |]|}}, |
| 222 |
% or not. |
| 223 |
% |
| 224 |
% If your \meta{data source} is not given in ranges, but you want to count the |
| 225 |
% values falling in each \meta{range} of a list you can use: |
| 226 |
% |
| 227 |
% \begin{function}{\StatsRangeData} |
| 228 |
% \begin{syntax} |
| 229 |
%\cs{StatsSortData}\ |
| 230 |
%\cs{\meta{destination}}\ |
| 231 |
%=\ |
| 232 |
%\marg{data source}\ |
| 233 |
%(\meta{range list}) |
| 234 |
% \end{syntax} |
| 235 |
% This command expect each \meta{value} in the \meta{data source} to be |
| 236 |
% convertible to a floating point number (as understood by \pkg{l3fp} from the |
| 237 |
% \LaTeX3 kernel). It also expects \meta{range list} to be a comma-separated |
| 238 |
% list of \meta{range}s, and will define \cs{\meta{destination}} to a |
| 239 |
% \meta{data source} whose \meta{value}s are the said \meta{range}s and whose |
| 240 |
% counts are, well\dots\ the number of floating point values that lie in those |
| 241 |
% \meta{range}s. |
| 242 |
% |
| 243 |
% \cs{StatsRangeData} does not need the \meta{range}s to be sorted, nor even |
| 244 |
% disjoint, but in that case the behavior of \cs{StatsGraph} is unspecified. |
| 245 |
% \end{function} |
| 246 |
% |
| 247 |
% Here is an example\footnote{The \cs{tltostr} command is defined in this |
| 248 |
% documentation to be an alias for the \LaTeX3 command \cs{tl_to_str:N} which is |
| 249 |
% equivalent to \cs{detokenize}\cs{expandafter}|\{|\cs{\meta{macro}}|\}|.}: |
| 250 |
% \begin{demo} |
| 251 |
% \StatsRangeData \facebook = { 0, 1, 1.5, 1.5, 2, 3, 2.4, 2, 2.4=5, |
| 252 |
% 3, 4=10, 5=6, 6=9, 6.5=5, 7, 7.1, 7.2, |
| 253 |
% 7.3, 7.4, 7.5, 7.6, 7.7, 7, 7, 8, 8, 8, |
| 254 |
% 9=5, 12=12} |
| 255 |
% (\IN[0;1;[, \IN[1;2;[, \IN[2;4;[, |
| 256 |
% \IN[4;7;[, \IN[7;10;[, \IN[10;14;[) |
| 257 |
% \tltostr \facebook |
| 258 |
% \end{demo} |
| 259 |
% \def \facebook { |
| 260 |
% \IN[0;1;[ = 1, \IN[1;2;[ = 3, \IN[2;4;[ = 10, |
| 261 |
% \IN[4;7;[ = 30, \IN[7;10;[ = 18, \IN[10;14;[ = 12 |
| 262 |
% } |
| 263 |
% |
| 264 |
% This data source will be used throughout the documentation. |
| 265 |
% \label{def:datasource} |
| 266 |
% |
| 267 |
% \subsection{Setting options} |
| 268 |
% |
| 269 |
% \begin{function}{\statisticssetup} |
| 270 |
% \begin{syntax} |
| 271 |
% \cs{statisticssetup} \oarg{module} \marg{options} |
| 272 |
% \end{syntax} |
| 273 |
% This command lets you specify options for several tables or graphs. The |
| 274 |
% options are set locally to the current group. Options for tables are in the |
| 275 |
% |table| \meta{module} and are the same as in the optional arguments of |
| 276 |
% \cs{StatsTable}. Options for grapsh are in the |graph| \meta{module} and are |
| 277 |
% the same as in the optional arguments of \cs{StatsGraph}. You can also use |
| 278 |
% \cs{statisticssetup} without a \meta{module} and prefix all keys by the module |
| 279 |
% name and a forward slash. |
| 280 |
% % \end{function} |
| 281 |
% |
| 282 |
% \begin{demo} |
| 283 |
% \statisticssetup{table/values=My values} |
| 284 |
% \statisticssetup[table]{counts=FooBar} |
| 285 |
% \StatsTable \facebook |
| 286 |
% \end{demo} |
| 287 |
% |
| 288 |
% \subsection{Statistics tables} |
| 289 |
% |
| 290 |
% \subsubsection{\cs{StatsTable} invocation} |
| 291 |
% |
| 292 |
% To typeset a table full of statistics values, you use the command: |
| 293 |
% |
| 294 |
% \begin{function}{\StatsTable} |
| 295 |
% \begin{syntax} |
| 296 |
% \cs{StatsTable} \oarg{options_1} \marg{data source} \oarg{options_2} |
| 297 |
% \end{syntax} |
| 298 |
% \meta{options_1} and \meta{options_2} are both optional and taken into |
| 299 |
% account. You will probably not use both at the same time even if |
| 300 |
% \cs{StatsTable} will accept it (and apply \meta{options_2} after |
| 301 |
% \meta{options_1}, potentially overriding some settings). The idea is to let |
| 302 |
% you decide where you feel the options should be. I find more logical to |
| 303 |
% specify options after a \cs{macro} data source, but before an inline |
| 304 |
% \marg{data source}. Your mileage may vary. |
| 305 |
% \end{function} |
| 306 |
% |
| 307 |
% If you do not use any option, you only get the line of values\footnote{The |
| 308 |
% \cs{facebook} data source is defined on page \pageref{def:datasource}.}: |
| 309 |
% \begin{demo} |
| 310 |
% \StatsTable \facebook |
| 311 |
% \end{demo} |
| 312 |
% |
| 313 |
% OK, this is ugly. Let us add some reasonable amount of space (a better choice |
| 314 |
% would be to use the \pkg{cellprops} package to control the spacing and a lot |
| 315 |
% more): |
| 316 |
% \begin{demo} |
| 317 |
% \setlength\extrarowheight{1.5pt} |
| 318 |
% \StatsTable \facebook |
| 319 |
% \end{demo} |
| 320 |
% \setlength\extrarowheight{1.5pt} |
| 321 |
% |
| 322 |
% \subsubsection{Choosing and naming rows} |
| 323 |
% |
| 324 |
% Let's add some rows to the table: |
| 325 |
% |
| 326 |
% \begin{key}{values, counts, frequencies, icc, icf, dcc, dcf} |
| 327 |
% \begin{syntax} |
| 328 |
% values $[$ = \meta{row header text} $]$ |
| 329 |
% counts $[$ = \meta{row header text} $]$ |
| 330 |
% frequencies $[$ = \meta{row header text} $]$ |
| 331 |
% icc $[$ = \meta{row header text} $]$ |
| 332 |
% icf $[$ = \meta{row header text} $]$ |
| 333 |
% dcc $[$ = \meta{row header text} $]$ |
| 334 |
% dcf $[$ = \meta{row header text} $]$ |
| 335 |
% \end{syntax} |
| 336 |
% These keys add the corresponding rows to the table. |icc| means increasing |
| 337 |
% cumulative counts, |icf| is the same with frequencies, |dcc| is the row of |
| 338 |
% decreasing cumulative counts and |dcf| for frequencies. If you omit |
| 339 |
% \meta{row header text} the key only activates the corresponding row; if you |
| 340 |
% additionally use a value then the first cell of the row will use that value as |
| 341 |
% text. |
| 342 |
% |
| 343 |
% The initial header is |\valuename| for values, |\countname| for counts, |
| 344 |
% |\freqname| for frequencies, |\iccname| for icc, |\icfname| for icf, |
| 345 |
% |\dccname| for dcc and |\dcfname| for dcf. |
| 346 |
% \end{key} |
| 347 |
% |
| 348 |
% \begin{demo} |
| 349 |
% \StatsTable \facebook[ |
| 350 |
% values=Time in \si{h}, |
| 351 |
% counts, frequencies, icc, dcc, icf, dcf |
| 352 |
% ] |
| 353 |
% \end{demo} |
| 354 |
% |
| 355 |
% \begin{key}{novalues, nocounts, nofrequencies, |
| 356 |
% noicc, nodcc, noicf, nodcf} |
| 357 |
% \begin{syntax} |
| 358 |
% novalues, nocounts, nofrequencies, noicc, nodcc, noicf, nodcf |
| 359 |
% \end{syntax} |
| 360 |
% If you want to \emph{disable} a row you can use the \texttt{no\meta{row}}~key. |
| 361 |
% This is particularly useful for the |values| row, but you might need these |
| 362 |
% keys to disable a row that you previously enabled with \cs{statisticssetup}. |
| 363 |
% |
| 364 |
% \begin{demo} |
| 365 |
% \StatsTable \facebook [novalues, counts, icc] |
| 366 |
% \end{demo} |
| 367 |
% \end{key} |
| 368 |
% |
| 369 |
% \begin{key}{values/header, counts/header, frequencies/header, |
| 370 |
% icc/header, icf/header, dcc/header, dcf/header} |
| 371 |
% \begin{syntax} |
| 372 |
% values/header = \meta{row header text} |
| 373 |
% counts/header = \meta{row header text} |
| 374 |
% frequencies/header = \meta{row header text} |
| 375 |
% icc/header = \meta{row header text} |
| 376 |
% icf/header = \meta{row header text} |
| 377 |
% dcc/header = \meta{row header text} |
| 378 |
% dcf/header = \meta{row header text} |
| 379 |
% \end{syntax} |
| 380 |
% These keys set the corresponding row header text, which will be used as the |
| 381 |
% first cell of the row if the row is enabled. These keys does not enable their |
| 382 |
% row by themselves, contrary to keys like |values| or |counts|. |
| 383 |
% |
| 384 |
% The initial header is |\valuename| for values, |\countname| for counts, |
| 385 |
% |\freqname| for frequencies, |\iccname| for icc, |\icfname| for icf, |
| 386 |
% |\dccname| for dcc and |\dcfname| for dcf. |
| 387 |
% \end{key} |
| 388 |
% |
| 389 |
% \begin{demo} |
| 390 |
% \statisticssetup{table/counts/header=People count} |
| 391 |
% \StatsTable \facebook[counts, frequencies, icc] |
| 392 |
% \end{demo} |
| 393 |
% |
| 394 |
% \subsubsection{Formatting cells} |
| 395 |
% |
| 396 |
% \begin{key}[label={table/values/format, table/counts/format, |
| 397 |
% table/frequencies/format, table/icc/format, table/icf/format, |
| 398 |
% table/dcc/format, table/dcf/format}] |
| 399 |
% {values/format, counts/format, frequencies/format, |
| 400 |
% icc/format, icf/format, dcc/format, dcf/format} |
| 401 |
% \begin{syntax} |
| 402 |
% values/format = \meta{formatting code} |
| 403 |
% counts/format = \meta{formatting code} |
| 404 |
% frequencies/format = \meta{formatting code} |
| 405 |
% icc/format = \meta{formatting code} |
| 406 |
% icf/format = \meta{formatting code} |
| 407 |
% dcc/format = \meta{formatting code} |
| 408 |
% dcf/format = \meta{formatting code} |
| 409 |
% \end{syntax} |
| 410 |
% Each key in this list takes a value which will be used for each cell in the |
| 411 |
% corresponding row. In this value, every occurrence of |#1| will be replaced by |
| 412 |
% the content of the cell, which can be further configured by the |
| 413 |
% |allcounts/format| key (for the rows |counts|, |icc| and~|dcc|) or the |
| 414 |
% |allfreqs/format| key (for the rows |frequencies|, |icf| and~|dcf|). The idea |
| 415 |
% is that the latter keys are intended for number formatting (decimal count, |
| 416 |
% decimal separator, etc.) while the \texttt{\meta{row}/format} keys are |
| 417 |
% intended for font/color changes. In this key, \cs{currentcolumn} expands to |
| 418 |
% the data column number, starting from~$1$, to enable different formatting |
| 419 |
% depending on the column. These keys are all initially equal to |#1| which means |
| 420 |
% they pass-through the content unmodified. |
| 421 |
% \end{key} |
| 422 |
% |
| 423 |
% \begin{demo} |
| 424 |
% \StatsTable \facebook[ |
| 425 |
% counts, icc, |
| 426 |
% icc/format = \colorbox{blue!\currentcolumn 0!white}{#1} |
| 427 |
% ] |
| 428 |
% \end{demo} |
| 429 |
% |
| 430 |
% \begin{key}{allcounts/format} |
| 431 |
% \begin{syntax} |
| 432 |
% allcounts/format = \meta{formatting code} |
| 433 |
% \end{syntax} |
| 434 |
% This key take some formatting code, in which every occurrence of |#1| will be |
| 435 |
% replaced by the integer count\footnotemark in each cell of every row |
| 436 |
% containing counts. The initial value is |\num{#1}|, using the \pkg{siunitx} |
| 437 |
% package. |
| 438 |
% |
| 439 |
% The result of this formatting code will then be passed to |counts/format|, |
| 440 |
% |icc/format| or |dcc/format| depending on the row, for further parsing and |
| 441 |
% formatting. |
| 442 |
% \end{key} |
| 443 |
% \footnotetext{As returned by \cs{fp_use:N} or \cs{fp_eval:n}.} |
| 444 |
% |
| 445 |
% \begin{demo} |
| 446 |
% \StatsTable \facebook[ |
| 447 |
% counts, icc, |
| 448 |
% icc/format = \colorbox{blue!\currentcolumn 0!white}{#1}, |
| 449 |
% allcounts/format = {\num[round-integer-to-decimal, |
| 450 |
% round-mode=figures]{#1}} |
| 451 |
% ] |
| 452 |
% \end{demo} |
| 453 |
% |
| 454 |
% \begin{key}{allfreqs/format} |
| 455 |
% \begin{syntax} |
| 456 |
% allfreqs/format = \meta{formatting code} |
| 457 |
% \end{syntax} |
| 458 |
% This key take some formatting code, in which every occurrence of |#1| will be |
| 459 |
% replaced by the current frequency\footnotemark in each cell of every row |
| 460 |
% containing frequencies. The initial value is |\num{#1}|, using the |
| 461 |
% \pkg{siunitx} package. |
| 462 |
% |
| 463 |
% The result of this formatting code will then be passed to |freqs/format|, |
| 464 |
% |icf/format| or |dcf/format| depending on the row, for further parsing and |
| 465 |
% formatting. |
| 466 |
% |
| 467 |
% The initial value is set by the |allfreqs/format/percent| key and typesets |
| 468 |
% values in percentage (that is, multiplied by~$100$ with a trailing~$\%$). |
| 469 |
% \end{key} |
| 470 |
% \footnotetext{As returned by \cs{fp_use:N} or \cs{fp_eval:n}.} |
| 471 |
% |
| 472 |
% \begin{demo} |
| 473 |
% \StatsTable \facebook[ |
| 474 |
% icc, frequencies, icf, |
| 475 |
% allfreqs/format = {\num[round-mode=places, |
| 476 |
% round-integer-to-decimal, |
| 477 |
% round-precision=3]{#1}} |
| 478 |
% ] |
| 479 |
% \end{demo} |
| 480 |
% Note that if you use |allfreqs/format| to round the frequencies to an |
| 481 |
% acceptable precision, your frequencies might not add up to~$1$ anymore, and |
| 482 |
% summing the frequencies up to some value might not give the same result as |
| 483 |
% computing the cumulative frequency from the cumulative count. If you |
| 484 |
% want to avoid that, consider using the |digits| key of the |table| module, |
| 485 |
% which rounds the cumulative frequencies \emph{then} computes the individual |
| 486 |
% frequencies as differences of consecutive cumulative ones. This essentially |
| 487 |
% spreads the rounding errors so that they cancel each other, with a result not |
| 488 |
% unlike that of the \textsc{Bresenham} algorithm. |
| 489 |
% |
| 490 |
% \begin{key}{allfreqs/format/percent} |
| 491 |
% \begin{syntax} |
| 492 |
% allfreqs/format/percent |
| 493 |
% \end{syntax} |
| 494 |
% This key sets up |allfreqs/format| to display the frequencies as percentages, |
| 495 |
% that is, multiplied by~$100$ with a trailing~$\%$. This is the initial |
| 496 |
% setting. |
| 497 |
% |
| 498 |
% \begin{texnote} |
| 499 |
% This key is a shorthand for\\ |
| 500 |
% |allfreqs/format = \SI{\fp_eval:n{#1*100}}{\percent}|. |
| 501 |
% \end{texnote} |
| 502 |
% \end{key} |
| 503 |
% |
| 504 |
% \begin{demo} |
| 505 |
% \StatsTable \facebook[ frequencies, icf, allfreqs/format/percent ] |
| 506 |
% \end{demo} |
| 507 |
% |
| 508 |
% \begin{key}{allfreqs/format/real} |
| 509 |
% \begin{syntax} |
| 510 |
% allfreqs/format/real |
| 511 |
% \end{syntax} |
| 512 |
% This key sets up |allfreqs/format| to |\num{#1}| which displays the |
| 513 |
% frequencies as straight real numbers. |
| 514 |
% \end{key} |
| 515 |
% |
| 516 |
% \begin{demo} |
| 517 |
% \StatsTable \facebook[ frequencies, icf, allfreqs/format/real ] |
| 518 |
% \end{demo} |
| 519 |
% |
| 520 |
% \begin{key}{digits} |
| 521 |
% \begin{syntax} |
| 522 |
% digits = \meta{integer} |
| 523 |
% \end{syntax} |
| 524 |
% This key sets the number of digits after the decimal point to use for rounding |
| 525 |
% cumulative frequencies. Point-wise frequencies are computed from these rounded |
| 526 |
% cumulative frequencies to ensure consistency with the cumulative counts, and |
| 527 |
% ensure the sum of frequencies equals~$1$. This essentially |
| 528 |
% spreads the rounding errors so that they cancel each other, with a result not |
| 529 |
% unlike that of the \textsc{Bresenham} algorithm. |
| 530 |
% |
| 531 |
% The rounding takes place before any formatting by |allfreqs/format| or |
| 532 |
% individual \texttt{\meta{row}/format}. The initial value is~$3$ (which means |
| 533 |
% one digit after the decimal separator in percentage). |
| 534 |
% \end{key} |
| 535 |
% |
| 536 |
% \begin{demo} |
| 537 |
% \StatsTable \facebook[ frequencies, icf, digits=2 ] |
| 538 |
% \end{demo} |
| 539 |
% |
| 540 |
% \subsubsection{Hiding and showing column contents} |
| 541 |
% |
| 542 |
% In addition to \texttt{\meta{row}/format}, |allcounts/format| and |
| 543 |
% |allfreqs/format| which can all use \cs{currentcolumn} to apply different |
| 544 |
% formatting to different columns, you can also use the following keys: |
| 545 |
% |
| 546 |
% \begin{key}[label=table/showonly]{showonly, showonly/hidden, showonly/shown} |
| 547 |
% \begin{syntax} |
| 548 |
% showonly = \meta{integer and integer range list} |
| 549 |
% showonly/hidden = \meta{formatting code} |
| 550 |
% showonly/shown = \meta{formatting code} |
| 551 |
% \end{syntax} |
| 552 |
% The |showonly| key enables you to choose which columns you want \emph{shown} |
| 553 |
% --- and thus which ones you want to have their contents hidden. It takes a |
| 554 |
% comma-separated list of single numbers or \texttt{\meta{start}-\meta{end}} |
| 555 |
% ranges of numbers. An empty value means \emph{show everything}, and this is |
| 556 |
% the initial value. To hide all contents, you can set |showonly| to a |
| 557 |
% non-existent column number like~$0$. |
| 558 |
% |
| 559 |
% Every column whose number is in the |showonly| list (of ranges) is deemed |
| 560 |
% \emph{shown}, which means all cells will be ultimately wrapped in the |
| 561 |
% |showonly/shown| formatting code, where as usual |#1|~is replaced by the |
| 562 |
% contents. That key initially just passes through the contents as-is. |
| 563 |
% |
| 564 |
% Every column whose number is \emph{not} in the list is \emph{hidden}, |
| 565 |
% \emph{i.e.} its cell contents are wrapped in the |showonly/hidden| formatting |
| 566 |
% code. This key is initially empty which means the contents are ignored and the |
| 567 |
% cell stays empty --- which means its width will collapse and only the column |
| 568 |
% separation will remain. You can decide to still typeset the contents in white, |
| 569 |
% or even put them in a PDF~``OCG layer'' with the \pkg{ocgx2} package for |
| 570 |
% instance. |
| 571 |
% \end{key} |
| 572 |
% |
| 573 |
% \begin{demo} |
| 574 |
% \StatsTable \facebook[ counts, frequencies, showonly={2,4-6} ] |
| 575 |
% \StatsTable \facebook[ counts, frequencies, showonly={2,4-6}, |
| 576 |
% showonly/hidden = \color{white}#1 ] |
| 577 |
% \end{demo} |
| 578 |
% |
| 579 |
% \subsubsection{Formatting the table} |
| 580 |
% |
| 581 |
% \begin{key}{maxcols} |
| 582 |
% \begin{syntax} |
| 583 |
% maxcols = \meta{comma-separated list of integers} |
| 584 |
% \end{syntax} |
| 585 |
% Setting this key to a positive integer~$n$ makes \cs{StatsTable} wrap after |
| 586 |
% having added $n$~columns to the current table. The table is closed, and a new |
| 587 |
% one is created with the row headers typeset anew. Setting this key to a |
| 588 |
% negative number or zero disables wrapping. If you set the key to a list of |
| 589 |
% integers, each one is used as the value for the corresponding subtable, with |
| 590 |
% the last number staying in effect for all remaining subtables. The initial |
| 591 |
% value is~$0$. |
| 592 |
% \end{key} |
| 593 |
% |
| 594 |
% \begin{texnote} |
| 595 |
% If there is a non-positive integer in the list, all subsequent integers are |
| 596 |
% ignored since there will be no further wrapping thus no other subtable. |
| 597 |
% \end{texnote} |
| 598 |
% |
| 599 |
% \begin{key}{tablesep} |
| 600 |
% \begin{syntax} |
| 601 |
% tablesep = \meta{\TeX\ content} |
| 602 |
% \end{syntax} |
| 603 |
% This key holds some \TeX\ content that will be inserted after each table when |
| 604 |
% wrapping. It should probably contain something that creates a line return |
| 605 |
% (either |\\| or |\par|), but can contain arbitrary code. |
| 606 |
% The initial value is |\\|. |
| 607 |
% \end{key} |
| 608 |
% |
| 609 |
% \begin{demo} |
| 610 |
% \StatsTable \facebook[ counts, maxcols=4, |
| 611 |
% tablesep=\par{\color{red}\hrule} ] |
| 612 |
% \end{demo} |
| 613 |
% |
| 614 |
% \begin{key}{preline} |
| 615 |
% \begin{syntax} |
| 616 |
% preline = \meta{array content} |
| 617 |
% \end{syntax} |
| 618 |
% This key holds some \TeX\ content that will be inserted first in the |
| 619 |
% \env{array} environment, before any row content. It should probably be some |
| 620 |
% kind of \cs{noalign} material, like a \cs{hline} or similar constructs. |
| 621 |
% The initial value is \cs{firsthline}, with a fallback to \cs{hline} if the |
| 622 |
% former doesn't exist. |
| 623 |
% \end{key} |
| 624 |
% |
| 625 |
% \begin{key}{postline} |
| 626 |
% \begin{syntax} |
| 627 |
% postline = \meta{array content} |
| 628 |
% \end{syntax} |
| 629 |
% This key holds some \TeX\ content that will be inserted last in the |
| 630 |
% \env{array} environment, after any row content. It should probably be some |
| 631 |
% kind of \cs{noalign} material, like a \cs{hline} or similar constructs. |
| 632 |
% The initial value is \cs{lasthline}, with a fallback to \cs{hline} if the |
| 633 |
% former doesn't exist. |
| 634 |
% \end{key} |
| 635 |
% |
| 636 |
% \begin{key}{outline} |
| 637 |
% \begin{syntax} |
| 638 |
% outline = \meta{array content} |
| 639 |
% \end{syntax} |
| 640 |
% This key sets both |preline| and |postline| to the same value. |
| 641 |
% \end{key} |
| 642 |
% |
| 643 |
% \begin{key}{newline} |
| 644 |
% \begin{syntax} |
| 645 |
% newline = \meta{array content} |
| 646 |
% \end{syntax} |
| 647 |
% This key holds some \TeX\ content that will be inserted at the end of each |
| 648 |
% row, to separate it from the next. \emph{It should contain some kind of |
| 649 |
% \cs{cr}}, probably in the form of |\\|, but can also contain \cs{hline}s after |
| 650 |
% the |\\|. The initial value is |\\| which creates tables without lines |
| 651 |
% separating rows (as \pkg{booktabs} would recommend). |
| 652 |
% \end{key} |
| 653 |
% |
| 654 |
% \begin{demo} |
| 655 |
% \setlength\extrarowheight{1ex} |
| 656 |
% \StatsTable \facebook[ counts, preline=\hline\hline, |
| 657 |
% postline=\hline\hline\hline, |
| 658 |
% newline=\\[1ex]\hline ] |
| 659 |
% \end{demo} |
| 660 |
% |
| 661 |
% \begin{key}{coltype} |
| 662 |
% \begin{syntax} |
| 663 |
% coltype = \meta{preamble elements} |
| 664 |
% \end{syntax} |
| 665 |
% This key sets the part of the array preamble that will be repeated for each |
| 666 |
% content column in the table. It can contain any preamble content, like "|" for |
| 667 |
% vertical lines, but should only countain a single column specifier. |
| 668 |
% The initial value is "c". |
| 669 |
% \end{key} |
| 670 |
% |
| 671 |
% \begin{key}{headcoltype} |
| 672 |
% \begin{syntax} |
| 673 |
% headcoltype = \meta{preamble elements} |
| 674 |
% \end{syntax} |
| 675 |
% This key sets the part of the array preamble that will be used for the first |
| 676 |
% column in the table, which contains the headers. It can contain any preamble |
| 677 |
% content, like "|" for vertical lines, but should only countain a single column |
| 678 |
% specifier. The initial value is "l". |
| 679 |
% \end{key} |
| 680 |
% |
| 681 |
% \begin{demo} |
| 682 |
% \StatsTable \facebook[ counts, coltype=@{}c, headcoltype=r ] |
| 683 |
% \end{demo} |
| 684 |
% |
| 685 |
% Note: these keys are here for convenience, but if you find yourself trying to |
| 686 |
% do very clever things in them, you should consider using the \pkg{cellprops} |
| 687 |
% package which is able to do much more complex border and background layouts |
| 688 |
% with ease. In particular they probably shouldn't be used to workaround the |
| 689 |
% very poor spacing of \env{array}: there are better solutions. |
| 690 |
% |
| 691 |
% Several classic uses of these keys can be replaced by the following key: |
| 692 |
% \begin{key}{frame} |
| 693 |
% \begin{syntax} |
| 694 |
% frame = none $\vert$ clean $\vert$ full |
| 695 |
% \end{syntax} |
| 696 |
% The |frame| key selects a preset for |preline|, |postline|, |headcoltype| and |
| 697 |
% |coltype|. The possible presets are: |
| 698 |
% \begin{itemize} |
| 699 |
% \item |none|: clears |preline| and |postline|, sets |headcoltype = l| and |
| 700 |
% |coltype = c|. This removes all lines in the table and is useful if you |
| 701 |
% use other means like \pkg{cellprops} to style the table. |
| 702 |
% \item |clean|: sets |preline = \firsthline|, |postline = \lasthline|, |
| 703 |
% |headcoltype = l| and |coltype = c|. This corresponds to the initial |
| 704 |
% setting, and yields a layout similar to \pkg{booktabs} recommendations, |
| 705 |
% especially if you set \cs{firsthline} and \cs{lasthline} to be a little |
| 706 |
% thicker. |
| 707 |
% \item |full|: sets |preline = \firsthline|, |postline = \lasthline|, |
| 708 |
% "headcoltype = |l|" and "coltype = c|". This separates all cells |
| 709 |
% with rules. |
| 710 |
% \end{itemize} |
| 711 |
% \end{key} |
| 712 |
% |
| 713 |
% \begin{demo} |
| 714 |
% \statisticssetup{table/showonly/hidden=\color{white}#1} |
| 715 |
% \StatsTable \facebook[ counts, frequencies, frame=none ] |
| 716 |
% \StatsTable \facebook[ counts, frequencies, frame=full, showonly=2-4 ] |
| 717 |
% \end{demo} |
| 718 |
% |
| 719 |
% \begin{key}{valign} |
| 720 |
% \begin{syntax} |
| 721 |
% valign = t $\vert$ c $\vert$ b |
| 722 |
% \end{syntax} |
| 723 |
% The value of this key is used for the optional argument of the \env{array} |
| 724 |
% environment. This enables to align either the baseline of the first line, that |
| 725 |
% of the last line, or the vertical center of the table with the surrounding |
| 726 |
% baseline. The initial value is |t|. |
| 727 |
% \end{key} |
| 728 |
% |
| 729 |
% |
| 730 |
% \subsection{Statistics graphs} |
| 731 |
% |
| 732 |
% \subsubsection{\cs{StatsGraph} invocation} |
| 733 |
% |
| 734 |
% To typeset a graphic from the statistics values, you use the command: |
| 735 |
% \begin{function}{\StatsGraph} |
| 736 |
% \begin{syntax} |
| 737 |
% \cs{StatsGraph} \oarg{options_1} \marg{data source} \oarg{options_2} |
| 738 |
% \end{syntax} |
| 739 |
% \meta{options_1} and \meta{options_2} are both optional and taken into |
| 740 |
% account. You will probably not use both at the same time even if |
| 741 |
% \cs{StatsGraph} will accept it (and apply \meta{options_2} after |
| 742 |
% \meta{options_1}, potentially overriding some settings). The idea is to let |
| 743 |
% you decide where you feel the options should be. I find more logical to |
| 744 |
% specify options after a \cs{macro} data source, but before an inline |
| 745 |
% \marg{data source}. Your mileage may vary. |
| 746 |
% \end{function} |
| 747 |
% |
| 748 |
% \begin{demo} |
| 749 |
% \StatsGraph \facebook |
| 750 |
% \end{demo} |
| 751 |
% |
| 752 |
% \cs{StatsGraph} will draw a different kind of graph depending on the |
| 753 |
% \meta{data source} itself, and the |cumulative| option key. A summary is |
| 754 |
% shown in the table below: |
| 755 |
% \begin{center} |
| 756 |
% \setlength\extrarowheight{1ex} |
| 757 |
% \begin{tabular}{ccc} |
| 758 |
% \firsthline |
| 759 |
% values are ranges & without |cumulative| & with |cumulative| \\[0.8ex] |
| 760 |
% \hline |
| 761 |
% no & bar diagram\footnotemark & \emph{not implemented yet} \\[1ex] |
| 762 |
% yes & histogram & |
| 763 |
% \parbox[c]{10em}{\centering cumulative distribution function} \\[2ex] |
| 764 |
% \lasthline |
| 765 |
% \end{tabular} |
| 766 |
% \footnotetext{In this documentation this is called a \emph{comb graph}.} |
| 767 |
% \end{center} |
| 768 |
% |
| 769 |
% \begin{demo} |
| 770 |
% \def \combdata { 36=3, 37=8, 38=2, 39=6, 40=6, 41=3, 42=2, 45=2, 46=2 } |
| 771 |
% \StatsGraph \combdata |
| 772 |
% \end{demo} |
| 773 |
% \def \combdata { 36=3, 37=8, 38=2, 39=6, 40=6, 41=3, 42=2, 45=2, 46=2 } |
| 774 |
% |
| 775 |
% \begin{demo} |
| 776 |
% \StatsGraph \facebook [cumulative] |
| 777 |
% \end{demo} |
| 778 |
% |
| 779 |
% \subsubsection{TikZ picture and datavisualization settings} |
| 780 |
% |
| 781 |
% \begin{key}{picture, picture/reset} |
| 782 |
% \begin{syntax} |
| 783 |
% picture = \meta{TikZ key options} |
| 784 |
% picture/reset |
| 785 |
% \end{syntax} |
| 786 |
% The |picture| key \emph{appends} content to the optional argument of the |
| 787 |
% \env{tikzpicture} environment. It can contain any list of TikZ keys. The |
| 788 |
% |picture/reset| key clears all content accumulated by the |picture| key, |
| 789 |
% including the initial value. |
| 790 |
% |
| 791 |
% The initial value is:\\ |
| 792 |
% |baseline = (current bounding box.center), label position = right|. |
| 793 |
% \end{key} |
| 794 |
% |
| 795 |
% \begin{key}{axissystem, axissystem/reset} |
| 796 |
% \begin{syntax} |
| 797 |
% axissystem = \meta{TikZ cartesian axis system options} |
| 798 |
% axissystem/reset |
| 799 |
% \end{syntax} |
| 800 |
% The |axissystem| key adds keys to the list of options passed to the |
| 801 |
% |scientific axes| datavisualization key, The |axissystem/reset| key clears all |
| 802 |
% content accumulated by the |axissystem| key, including the initial value, |
| 803 |
% which is set by the initial value of the |width| key. |
| 804 |
% \end{key} |
| 805 |
% |
| 806 |
% \begin{demo} |
| 807 |
% \StatsGraph \combdata [axissystem={end labels, clean}] |
| 808 |
% \end{demo} |
| 809 |
% |
| 810 |
% Two small helper keys are provided for a very common usage of |axissystem|: |
| 811 |
% |
| 812 |
% \begin{key}{width} |
| 813 |
% \begin{syntax} |
| 814 |
% width = \meta{\TeX\ dimension expression} |
| 815 |
% \end{syntax} |
| 816 |
% This key sets the width of the graphic to the given \meta{\TeX\ dimension |
| 817 |
% expression}, labels and padding excluded. The expression is evaluated at graph |
| 818 |
% creation time. The initial value is |0.75\columnwidth|. |
| 819 |
% \begin{texnote} |
| 820 |
% This key is a shortcut for |axissystem = { width = |\meta{dimension}| }| |
| 821 |
% \end{texnote} |
| 822 |
% \end{key} |
| 823 |
% |
| 824 |
% \begin{key}{height} |
| 825 |
% \begin{syntax} |
| 826 |
% height = \meta{\TeX\ dimension expression} |
| 827 |
% \end{syntax} |
| 828 |
% This key sets the width of the graphic to the given \meta{\TeX\ dimension |
| 829 |
% expression}, labels and padding excluded. The expression is evaluated at graph |
| 830 |
% creation time. Initially this is \emph{unset}, which means the default of |
| 831 |
% the cartesian axis system will be used, that is the choosen width divided by |
| 832 |
% the golden ratio $\varphi = \frac{1+\sqrt{5}}{2}$. |
| 833 |
% \begin{texnote} |
| 834 |
% This key is a shortcut for |axissystem = { height = |\meta{dimension}| }| |
| 835 |
% \end{texnote} |
| 836 |
% \end{key} |
| 837 |
% |
| 838 |
% To have more precise control over the scale of the graph, you can use the |
| 839 |
% individual axis options provided by \pkg{\ExplFileName} to set an explicit |
| 840 |
% scaling with TikZ DataVisualization keys like |unit length|. See the PGF/TikZ |
| 841 |
% manual for more information. |
| 842 |
% |
| 843 |
% \begin{demo} |
| 844 |
% \statisticssetup[graph]{ width = 0.25\columnwidth, height=4cm } |
| 845 |
% \centering |
| 846 |
% \StatsGraph \facebook |
| 847 |
% \StatsGraph \facebook [cumulative] |
| 848 |
% \StatsGraph \combdata |
| 849 |
% \end{demo} |
| 850 |
% |
| 851 |
% \begin{key}{tikzinfo', tikzinfo'/reset} |
| 852 |
% \begin{syntax} |
| 853 |
% tikzinfo' = \meta{TikZ picture code} |
| 854 |
% tikzinfo'/reset |
| 855 |
% \end{syntax} |
| 856 |
% This key \emph{appends} content to be added in the |info'| section of the |
| 857 |
% |\datavisualization| command. It can contain any TikZ code, and can use the |
| 858 |
% |visualization cs| coordinate system. The result of this TikZ code is drawn |
| 859 |
% \emph{before} the data itself and will end up behind unless you play with TikZ |
| 860 |
% layers. Some information might be unavailable or wrong since the data has not |
| 861 |
% been drawn yet. |
| 862 |
% |
| 863 |
% The |tikzinfo'/reset| key clears all content accumulated by the |tikzinfo'| |
| 864 |
% key. The initial value is empty. |
| 865 |
% \end{key} |
| 866 |
% |
| 867 |
% \begin{key}{tikzinfo, tikzinfo/reset} |
| 868 |
% \begin{syntax} |
| 869 |
% tikzinfo = \meta{TikZ picture code} |
| 870 |
% tikzinfo/reset |
| 871 |
% \end{syntax} |
| 872 |
% This key \emph{appends} content to be added in the |info| section of the |
| 873 |
% |\datavisualization| command. It can contain any TikZ code, and can use the |
| 874 |
% |visualization cs| coordinate system. The result of this TikZ code is drawn |
| 875 |
% \emph{after} the data itself and will end up in front of it unless you play |
| 876 |
% with TikZ layers. |
| 877 |
% |
| 878 |
% The |tikzinfo/reset| key clears all content accumulated by the |tikzinfo| |
| 879 |
% key. The initial value is empty. |
| 880 |
% \end{key} |
| 881 |
% |
| 882 |
% \begin{demo} |
| 883 |
% \StatsGraph \facebook [ |
| 884 |
% cumulative, |
| 885 |
% tikzinfo = { |
| 886 |
% \path (data bounding box.south west) coordinate (O); |
| 887 |
% \path (visualization cs:x=8, y=50) coordinate (A); |
| 888 |
% \draw[red] (O |- A) -- (A) -- (A |- O); |
| 889 |
% } |
| 890 |
% ] |
| 891 |
% \end{demo} |
| 892 |
% |
| 893 |
% \subsubsection{Styling the graph} |
| 894 |
% |
| 895 |
% \begin{key}{style, style/reset, |
| 896 |
% comb/style, comb/style/reset, |
| 897 |
% histogram/style, histogram/style/reset, |
| 898 |
% cumulative/style, cumulative/style/reset,} |
| 899 |
% \begin{syntax} |
| 900 |
% style = \meta{TikZ path options} |
| 901 |
% \meta{graph type}/style = \meta{TikZ path options} |
| 902 |
% style/reset, \meta{graph type}/style/reset |
| 903 |
% \end{syntax} |
| 904 |
% The \texttt{\meta{graph type}/style} keys append options to the TikZ path |
| 905 |
% created by the datavisualization when the corresponding graph type is used. |
| 906 |
% You can clear these options with \texttt{\meta{graph type}/style/reset}. |
| 907 |
% If you omit the graph type, this sets the label for all graph types |
| 908 |
% simultaneously. |
| 909 |
% |
| 910 |
% The initial values are: |
| 911 |
% \begin{verbatim} |
| 912 |
% comb/style = ultra-thick, |
| 913 |
% cumulative/style = %empty |
| 914 |
% histogram/style = { |
| 915 |
% every~path/.prefix~style=fill, |
| 916 |
% semithick, black, fill=black, fill~opacity=0.1 |
| 917 |
% }, |
| 918 |
% \end{verbatim} |
| 919 |
% \end{key} |
| 920 |
% |
| 921 |
% \begin{demo} |
| 922 |
% \statisticssetup[graph]{width=0.45\linewidth, |
| 923 |
% style=blue, cumulative/style=densely dashed } |
| 924 |
% \StatsGraph \facebook [ cumulative ] |
| 925 |
% \hfill \StatsGraph \facebook[style={ |
| 926 |
% fill opacity=0, pattern=north west lines, |
| 927 |
% }] |
| 928 |
% \end{demo} |
| 929 |
% |
| 930 |
% \subsubsection{Selecting which parts of the graph are shown} |
| 931 |
% |
| 932 |
% By default, the complete graph is shown; you can ask \cs{StatsGraph} to only |
| 933 |
% show the parts corresponding to some of the input data: |
| 934 |
% |
| 935 |
% \begin{key}[label=graph/showonly]{showonly} |
| 936 |
% \begin{syntax} |
| 937 |
% showonly = \meta{integer and integer range list} |
| 938 |
% \end{syntax} |
| 939 |
% The |showonly| key enables you to set which parts of the graph you want |
| 940 |
% \emph{shown}. It takes a comma-separated list of single numbers or |
| 941 |
% \texttt{\meta{start}-\meta{end}} ranges of numbers. An empty value means |
| 942 |
% \emph{show everything}, and this is the initial value. To hide all contents, |
| 943 |
% you can set |showonly| to a non-existent part number like~$-1$. |
| 944 |
% \end{key} |
| 945 |
% |
| 946 |
% \medskip |
| 947 |
% For comb graphs, the $n$-th part is the vertical bar corresponding to the |
| 948 |
% $n$-th value in the data source. For histograms, this is the rectangle |
| 949 |
% corresponding to the $n$-th range. |
| 950 |
% |
| 951 |
% For cumulative distribution functions of data sources with ranges, this is the |
| 952 |
% direct image of the $n$-th range by the function. The horizontal segment |
| 953 |
% between $-\infty$ and the lower bound of the first range is assigned |
| 954 |
% number~$0$, and the part right of the last range is selected by number~$N+1$ |
| 955 |
% where $N$~is the total number of ranges. |
| 956 |
% |
| 957 |
% Currently, the drawing of hidden parts is inhibited altogether, but in the |
| 958 |
% future it is planned to have them drawn with another visualizer and a separate |
| 959 |
% style. |
| 960 |
% |
| 961 |
% \begin{demo} |
| 962 |
% \statisticssetup{ graph/width=0.45\columnwidth } |
| 963 |
% \StatsGraph \facebook [ showonly={2,4-6} ] |
| 964 |
% \StatsGraph \facebook [ cumulative, showonly={1,3-5,7} ] |
| 965 |
% \end{demo} |
| 966 |
% |
| 967 |
% \subsubsection{Unit selection and vertical axis settings} |
| 968 |
% |
| 969 |
% \begin{key}[label={graph/counts, graph/frequencies}]{counts, frequencies} |
| 970 |
% \begin{syntax} |
| 971 |
% counts $[$ = \meta{label} $]$ |
| 972 |
% frequencies $[$ = \meta{label} $]$ |
| 973 |
% \end{syntax} |
| 974 |
% These keys select the corresponding unit to use for the vertical axis of comb |
| 975 |
% graphs and cumulative distribution graphs, and for the area display of |
| 976 |
% histograms. Additionnally, if a \meta{label} is provided, it is passed to the |
| 977 |
% |counts/label| or the |frequencies/label| key. |
| 978 |
% |
| 979 |
% The initially selected unit is |counts|. |
| 980 |
% \end{key} |
| 981 |
% |
| 982 |
% \begin{key}{comb/counts, comb/frequencies, |
| 983 |
% histogram/counts, histogram/frequencies, |
| 984 |
% cumulative/counts, cumulative/frequencies} |
| 985 |
% \begin{syntax} |
| 986 |
% \meta{graph type}/counts $[$ = \meta{label} $]$ |
| 987 |
% \meta{graph type}/frequencies $[$ = \meta{label} $]$ |
| 988 |
% \end{syntax} |
| 989 |
% These keys select the unit to use for specific types of graphs separately. |
| 990 |
% They can be used in the inline options of \cs{StatsGraph} too, but they |
| 991 |
% probably only make sense in \cs{statisticssetup} to define different defaults |
| 992 |
% for different graph types. |
| 993 |
% \begin{texnote} |
| 994 |
% The |counts| key is actually a meta-key for\\ |
| 995 |
% |comb/counts, histogram/counts, cumulative/counts|, which applies the same |
| 996 |
% value (or no value at all) to all three type-specific keys. The |frequencies| |
| 997 |
% key is similar. |
| 998 |
% \end{texnote} |
| 999 |
% \end{key} |
| 1000 |
% |
| 1001 |
% \begin{demo} |
| 1002 |
% \statisticssetup[graph]{ |
| 1003 |
% width=0.4\columnwidth, |
| 1004 |
% frequencies=Hello world, comb/counts=Students |
| 1005 |
% } |
| 1006 |
% \StatsGraph \facebook \hfill \StatsGraph \combdata \\ |
| 1007 |
% \StatsGraph \facebook [cumulative] \hfill \StatsGraph \facebook[counts] |
| 1008 |
% \end{demo} |
| 1009 |
% |
| 1010 |
% Note that setting a label for the vertical axis of histogram does not make |
| 1011 |
% much sense, even if your decision will be respected. |
| 1012 |
% |
| 1013 |
% \begin{key}{counts/label, frequencies/label, |
| 1014 |
% comb/counts/label, comb/frequencies/label, |
| 1015 |
% histogram/counts/label, histogram/frequencies/label, |
| 1016 |
% cumulative/counts/label, cumulative/frequencies/label} |
| 1017 |
% \begin{syntax} |
| 1018 |
% \meta{unit}/label = \meta{label} |
| 1019 |
% \meta{graph type}/\meta{unit}/label = \meta{label} |
| 1020 |
% \end{syntax} |
| 1021 |
% These keys set the label to use for the $y$~axis of the graph when the |
| 1022 |
% corresponding unit is selected, \emph{without} selecting it at that point. |
| 1023 |
% This is useful to provide your own defaults through \cs{statisticssetup}. |
| 1024 |
% |
| 1025 |
% The keys |counts/label| and |frequencies/label| set the label for all three |
| 1026 |
% graph types, while the others are here to set individual defaults. |
| 1027 |
% \end{key} |
| 1028 |
% |
| 1029 |
% Initial values are as follows: |
| 1030 |
% \begin{itemize} |
| 1031 |
% \item |comb/counts/label = \countname| |
| 1032 |
% \item |comb/frequencies/label = \freqname| |
| 1033 |
% \item |cumulative/counts/label = \ccountname| |
| 1034 |
% \item |cumulative/frequencies/label = \cfreqname| |
| 1035 |
% \item |histogram/counts/label| and |histogram/frequencies/label| are unset |
| 1036 |
% \end{itemize} |
| 1037 |
% |
| 1038 |
% \begin{texnote} |
| 1039 |
% The \texttt{\meta{type}/\meta{unit}/label} key is a shorthand for |
| 1040 |
% \texttt{\meta{type}/\meta{unit}/axis} | = { label = |\meta{label}| }|, which |
| 1041 |
% means that using \texttt{\meta{type}/\meta{unit}/axis/reset} will also remove |
| 1042 |
% any defined label. |
| 1043 |
% \end{texnote} |
| 1044 |
% \begin{texnote} |
| 1045 |
% As before, \texttt{\meta{unit}/label = \meta{label}} is equivalent to\par |
| 1046 |
% \begingroup\obeylines\ttfamily |
| 1047 |
% comb/\meta{unit}/label = \meta{label}, |
| 1048 |
% histogram/\meta{unit}/label = \meta{label}, |
| 1049 |
% cumulative/\meta{unit}/label = \meta{label} |
| 1050 |
% \endgroup |
| 1051 |
% \end{texnote} |
| 1052 |
% |
| 1053 |
% \begin{key}{y/label, comb/y/label, histogram/y/label, cumulative/y/label} |
| 1054 |
% \begin{syntax} |
| 1055 |
% y/label = \meta{label} |
| 1056 |
% \meta{graph type}/y/label = \meta{label} |
| 1057 |
% \end{syntax} |
| 1058 |
% These keys set the label to use for the $y$~axis of the graph for both units |
| 1059 |
% at the same time. |y/label| sets the label for all graph types and all units |
| 1060 |
% simultaneously, while \texttt{\meta{graph type}/y/label} can be used for |
| 1061 |
% individual graph types. |
| 1062 |
% \end{key} |
| 1063 |
% |
| 1064 |
% This can be useful to set the label in inline options without having to |
| 1065 |
% explicitely type the graph type or the selected unit: |
| 1066 |
% |
| 1067 |
% \begin{demo} |
| 1068 |
% \statisticssetup[graph]{ |
| 1069 |
% width=0.38\columnwidth, |
| 1070 |
% comb/frequencies, cumulative/counts, |
| 1071 |
% } |
| 1072 |
% \StatsGraph \combdata [ y/label=Students ] |
| 1073 |
% \StatsGraph \facebook [ cumulative, y/label=Respondents ] |
| 1074 |
% \end{demo} |
| 1075 |
% |
| 1076 |
% \begin{key}{counts/axis, frequencies/axis, |
| 1077 |
% comb/counts/axis, comb/frequencies/axis, |
| 1078 |
% histogram/counts/axis, histogram/frequencies/axis, |
| 1079 |
% cumulative/counts/axis, cumulative/frequencies/axis, |
| 1080 |
% counts/axis/reset, frequencies/axis/reset, |
| 1081 |
% comb/.../axis/reset, |
| 1082 |
% histogram/.../axis/reset, |
| 1083 |
% cumulative/.../axis/reset} |
| 1084 |
% \begin{syntax} |
| 1085 |
% \meta{unit}/axis = \meta{TikZ datavisualization axis options} |
| 1086 |
% \meta{unit}/axis/reset |
| 1087 |
% \meta{graph type}/\meta{unit}/axis =\ |
| 1088 |
%\meta{TikZ datavisualization axis options} |
| 1089 |
% \meta{graph type}/\meta{unit}/axis/reset |
| 1090 |
% \end{syntax} |
| 1091 |
% The \texttt{\meta{unit}/axis} keys append options to the TikZ $y$~axis when |
| 1092 |
% the corresponding unit is selected. You can clear these options with |
| 1093 |
% \texttt{\meta{unit}/axis/reset}. The \texttt{\meta{graph |
| 1094 |
% type}/\meta{unit}/axis} and \texttt{\meta{graph type}/\meta{unit}/axis/reset} |
| 1095 |
% keys do the same, but only for a specific graph type. |
| 1096 |
% |
| 1097 |
% Initial values are as follows: |
| 1098 |
% \begin{itemize} |
| 1099 |
% \item |comb/counts/axis| and |cumulative/counts/axis| are equal to\\ |
| 1100 |
% |ticks and grid={many, int about strategy, integer minor steps*},|\\ |
| 1101 |
% |label=|\meta{initial value of the label key} |
| 1102 |
% \item |cumulative/counts/axis| and |cumulative/frequencies/axis| are |
| 1103 |
% equal to\\ |
| 1104 |
% |ticks and grid=many, label=|\meta{initial value of the label key} |
| 1105 |
% \item |histogram/counts/axis| and |histogram/frequencies/axis| are equal to\\ |
| 1106 |
% |ticks=none, grid=|\meta{code to auto-compute the step} (see the |
| 1107 |
% |histogram/autostep| key below). |
| 1108 |
% \end{itemize} |
| 1109 |
% \end{key} |
| 1110 |
% |
| 1111 |
% \begin{key}{y/axis, y/axis/reset, |
| 1112 |
% comb/axis, comb/axis/reset, |
| 1113 |
% histogram/axis, histogram/axis/reset, |
| 1114 |
% cumulative/axis, cumulative/axis/reset} |
| 1115 |
% \begin{syntax} |
| 1116 |
% y/axis = \meta{TikZ datavisualization axis options} |
| 1117 |
% y/axis/reset |
| 1118 |
% \meta{graph type}/y/axis = \meta{TikZ datavisualization axis options} |
| 1119 |
% \meta{graph type}/y/axis/reset |
| 1120 |
% \end{syntax} |
| 1121 |
% The \texttt{y/axis} keys append options to the TikZ $y$~axis for all possible |
| 1122 |
% units and all graph types at the same time. The \texttt{y/axis/reset} key |
| 1123 |
% clears these options for all units and all types simultaneously. |
| 1124 |
% |
| 1125 |
% The \texttt{\meta{graph type}/y/axis} and \texttt{\meta{graph |
| 1126 |
% type}/y/axis/reset} keys do the same, but only for a specific graph type. |
| 1127 |
% \end{key} |
| 1128 |
% |
| 1129 |
% \begin{demo} |
| 1130 |
% \statisticssetup[graph]{ |
| 1131 |
% width=0.4\columnwidth, |
| 1132 |
% comb/frequencies/axis = { ticks={step=0.08} }, |
| 1133 |
% histogram/y/axis = { grid = none }, |
| 1134 |
% } |
| 1135 |
% \StatsGraph \combdata [ frequencies, y/axis = { |
| 1136 |
% ticks={style=blue}, unit length=4cm per 0.25 units, |
| 1137 |
% } ] |
| 1138 |
% \hfill \StatsGraph \facebook |
| 1139 |
% \end{demo} |
| 1140 |
% |
| 1141 |
% \begin{key}{/tikz/datavisualization/integer minor steps, |
| 1142 |
% /tikz/datavisualization/integer minor steps*} |
| 1143 |
% \begin{syntax} |
| 1144 |
% integer minor steps $[$ = \meta{integer expression} $]$ |
| 1145 |
% integer minor steps* $[$ = \meta{integer expression} $]$ |
| 1146 |
% \end{syntax} |
| 1147 |
% These are not keys in the |graph| module, but TikZ keys. They add code to |
| 1148 |
% automatically compute |minor steps between steps| after the axis step has been |
| 1149 |
% computed with the choosen strategy, so that the following constraints are |
| 1150 |
% respected: |
| 1151 |
% \begin{itemize} |
| 1152 |
% \item a minor step corresponds to an integer number; |
| 1153 |
% \item at most \meta{integer expression} ticks are present on the axis (minor |
| 1154 |
% and major included, subminor not counted). |
| 1155 |
% \end{itemize} |
| 1156 |
% In addition, the starred version ensures that the major step is never below |
| 1157 |
% one, which makes sense for counts where sub-unit graduations are confusing at |
| 1158 |
% best. |
| 1159 |
% \end{key} |
| 1160 |
% |
| 1161 |
% If ommited, the \meta{integer expression} defaults to~$50$. |
| 1162 |
% |
| 1163 |
% These TikZ keys should not explode if the computed step is not an integer, but |
| 1164 |
% will probably not give a useful result, and in particular whether the minor |
| 1165 |
% step will be integer is not defined in that case. |
| 1166 |
% |
| 1167 |
% \begin{texnote} |
| 1168 |
% The keys are independent of \pkg{statistics} and could be reused elsewhere. |
| 1169 |
% \end{texnote} |
| 1170 |
% |
| 1171 |
% \begin{key}{counts/format, frequencies/format, y/format, |
| 1172 |
% comb/counts/format, comb/frequencies/format, comb/y/format, |
| 1173 |
% histogram/counts/format, histogram/frequencies/format, |
| 1174 |
% histogram/y/format, |
| 1175 |
% cumulative/counts/format, cumulative/frequencies/format, |
| 1176 |
% cumulative/y/format} |
| 1177 |
% \begin{syntax} |
| 1178 |
% \meta{unit}/format = \meta{formatting code} |
| 1179 |
% \meta{graph type}/\meta{unit}/format = \meta{formatting code} |
| 1180 |
% \end{syntax} |
| 1181 |
% These keys set the format to use for all counts or frequenties that are |
| 1182 |
% typeset on the graphs. This includes the ticks on axes, and areas above |
| 1183 |
% histogram rectangles. The value should be \TeX\ code to render the actual |
| 1184 |
% number, in which all occurrences of |#1| are replaced by the number to |
| 1185 |
% typeset. |
| 1186 |
% |
| 1187 |
% Keys of the form |\meta{graph type}/\meta{unit}/format| are used to set the |
| 1188 |
% formatter of numbers in a specific unit when used in a specific graph. Keys of |
| 1189 |
% the form |\meta{unit}/format| set the formatter for all graph types at the |
| 1190 |
% same time, which is often desirable since it is rare that a frequency needs to |
| 1191 |
% be typeset differently in \emph{e.g.} comb graphs and histograms. |
| 1192 |
% |
| 1193 |
% You can use |\meta{graph type}/y/format| or |y/format| to set the formatter |
| 1194 |
% for both units at the same time, which is mainly useful for inline options to |
| 1195 |
% avoid repeating the selected unit for each key. |
| 1196 |
% |
| 1197 |
% Initial settings are: |counts/format = \num{#1}| and |
| 1198 |
% |frequencies/format/percent| (see below for an exlpanation of that key). |
| 1199 |
% \end{key} |
| 1200 |
% |
| 1201 |
% \begin{demo} |
| 1202 |
% \StatsGraph \combdata [ |
| 1203 |
% y/label=, width=0.4\columnwidth, |
| 1204 |
% y/format=#1\text{ student\ifnum#1=1\else s\fi} |
| 1205 |
% ] |
| 1206 |
% \end{demo} |
| 1207 |
% |
| 1208 |
% \begin{key}{frequencies/format/real, |
| 1209 |
% comb/frequencies/format/real, |
| 1210 |
% histogram/frequencies/format/real, |
| 1211 |
% cumulative/frequencies/format/real} |
| 1212 |
% \begin{syntax} |
| 1213 |
% frequencies/format/real = \meta{number of decimals} |
| 1214 |
% \meta{graph type}/frequencies/format/real = \meta{number of decimals} |
| 1215 |
% \end{syntax} |
| 1216 |
% These keys make the corresponding format typeset its argument as a real |
| 1217 |
% number, using the \cs{num} command of the \pkg{siunitx} package. |
| 1218 |
% \begin{texnote} |
| 1219 |
% This is equivalent to:\\ |
| 1220 |
% |frequencies/format = \num[round-mode=places,round-precision=##1]{####1}| |
| 1221 |
% \end{texnote} |
| 1222 |
% \end{key} |
| 1223 |
% |
| 1224 |
% \begin{key}{frequencies/format/percent, |
| 1225 |
% comb/frequencies/format/percent, |
| 1226 |
% histogram/frequencies/format/percent, |
| 1227 |
% cumulative/frequencies/format/percent} |
| 1228 |
% \begin{syntax} |
| 1229 |
% frequencies/format/percent = \meta{number of decimals} |
| 1230 |
% \meta{graph type}/frequencies/format/percent = \meta{number of decimals} |
| 1231 |
% \end{syntax} |
| 1232 |
% These keys make the corresponding format typeset its argument as a percentage, |
| 1233 |
% using the \cs{num} command of the \pkg{siunitx} package. This is the initial |
| 1234 |
% setting. |
| 1235 |
% \begin{texnote} |
| 1236 |
% This is equivalent to:\\ |
| 1237 |
% |frequencies/format = { \SI[round-mode=places,round-precision=##1]{| \\ |
| 1238 |
% | \fp_eval:n{####1*100}| \\ |
| 1239 |
% |}{\percent}| |
| 1240 |
% \end{texnote} |
| 1241 |
% \end{key} |
| 1242 |
% |
| 1243 |
% \begin{key}{counts/margin, frequencies/margin, y/margin, |
| 1244 |
% comb/counts/margin, comb/frequencies/margin, comb/y/margin, |
| 1245 |
% histogram/counts/margin, histogram/frequencies/margin, |
| 1246 |
% histogram/y/margin, |
| 1247 |
% cumulative/counts/margin, cumulative/frequencies/margin, |
| 1248 |
% cumulative/y/margin} |
| 1249 |
% \begin{syntax} |
| 1250 |
% \meta{unit}/margin = \meta{numeric expression} |
| 1251 |
% \meta{graph type}/\meta{unit}/margin = \meta{numeric expression} |
| 1252 |
% \end{syntax} |
| 1253 |
% These keys set the margin that will be used for the relevant axis in the |
| 1254 |
% corresponding graph type, that is the amount of space above the data that |
| 1255 |
% will be reserved by \cs{StatsGraph}. The \meta{numeric expression} should |
| 1256 |
% compute a count or a frequency depending on the selected unit, and will |
| 1257 |
% correspond to the empty space reserved above the graph \emph{in this very |
| 1258 |
% unit}. |
| 1259 |
% |
| 1260 |
% In this expression, the following constants will be available: \cs{min} which |
| 1261 |
% is the minimum count or frequency where something is drawn in the graph |
| 1262 |
% (currently this is always zero); \cs{max} which is the maximum count or |
| 1263 |
% frequency in the graph; and \cs{range} which is |\max - \min|. |
| 1264 |
% |
| 1265 |
% As usual, keys of the form |\meta{graph type}/\meta{unit}/margin| are used to |
| 1266 |
% define the margin in a specific unit when used in a specific graph, whereas |
| 1267 |
% keys of the form |\meta{unit}/margin| set the margin for all graph types at |
| 1268 |
% the same time. |
| 1269 |
% |
| 1270 |
% You can use |\meta{graph type}/y/margin| or |y/margin| to set the margin |
| 1271 |
% for both units at the same time, which is mainly useful for inline options to |
| 1272 |
% avoid repeating the selected unit for each key. |
| 1273 |
% |
| 1274 |
% The inital value is |y/margin = \range / 10|. |
| 1275 |
% \end{key} |
| 1276 |
% |
| 1277 |
% \begin{texnote} |
| 1278 |
% This expression will be evaluated with the rules of |\fp_eval:n| |
| 1279 |
% (with |\fp_gset:Nn| to be exact). |
| 1280 |
% \end{texnote} |
| 1281 |
% |
| 1282 |
% \begin{demo} |
| 1283 |
% \StatsGraph \combdata [ width=0.4\columnwidth, y/margin=2 ] |
| 1284 |
% \end{demo} |
| 1285 |
% |
| 1286 |
% \subsubsection{Horizontal axis settings} |
| 1287 |
% |
| 1288 |
% \begin{key}{values/label, x/label, |
| 1289 |
% comb/values/label, comb/x/label, |
| 1290 |
% histogram/values/label, histogram/x/label, |
| 1291 |
% cumulative/values/label, cumulative/x/label} |
| 1292 |
% \begin{syntax} |
| 1293 |
% values/label = \meta{label}, x/label = \meta{label} |
| 1294 |
% \meta{graph type}/values/label = \meta{label} |
| 1295 |
% \meta{graph type}/x/label = \meta{label} |
| 1296 |
% \end{syntax} |
| 1297 |
% These keys set the label to use for the $x$~axis of the graph when the |
| 1298 |
% corresponding graph type is used. The keys with |x| are aliases for the |
| 1299 |
% similar keys with |values|. If you omit the graph type, this sets the label |
| 1300 |
% for all graph types simultaneously. |
| 1301 |
% |
| 1302 |
% The initial value is |values/label = \valuename|. |
| 1303 |
% \end{key} |
| 1304 |
% |
| 1305 |
% \begin{texnote} |
| 1306 |
% The \texttt{\meta{type}/values/label} key is a shorthand for |
| 1307 |
% \texttt{\meta{type}/values/axis} | = { label = |\meta{label}| }|, which |
| 1308 |
% means that using \texttt{\meta{type}/values/axis/reset} will also remove |
| 1309 |
% any defined label. |
| 1310 |
% \end{texnote} |
| 1311 |
% |
| 1312 |
% \begin{demo} |
| 1313 |
% \statisticssetup[graph]{ |
| 1314 |
% width=0.38\columnwidth, |
| 1315 |
% comb/frequencies, cumulative/counts, |
| 1316 |
% } |
| 1317 |
% \StatsGraph \combdata [ values/label=Shoe size ] |
| 1318 |
% \StatsGraph \facebook [ cumulative, x/label=Time spent on Facebook ] |
| 1319 |
% \end{demo} |
| 1320 |
% |
| 1321 |
% \begin{key}{values/axis, x/axis, |
| 1322 |
% comb/values/axis, comb/x/axis, |
| 1323 |
% histogram/values/axis, histogram/x/axis, |
| 1324 |
% cumulative/values/axis, cumulative/x/axis, |
| 1325 |
% values/axis/reset, x/axis/reset, |
| 1326 |
% comb/values/axis/reset, comb/x/axis/reset, |
| 1327 |
% histogram/values/axis/reset, histogram/x/axis/reset, |
| 1328 |
% cumulative/values/axis/reset, cumulative/x/axis/reset} |
| 1329 |
% \begin{syntax} |
| 1330 |
% \meta{graph type}/values/axis = \meta{TikZ datavisualization axis options} |
| 1331 |
% \meta{graph type}/x/axis = \meta{TikZ datavisualization axis options} |
| 1332 |
% \meta{graph type}/values/axis/reset, \meta{graph type}/x/axis/reset |
| 1333 |
% \end{syntax} |
| 1334 |
% The \texttt{\meta{graph type}/values/axis} keys append options to the TikZ |
| 1335 |
% $x$~axis when the corresponding graph type is used. You can clear these |
| 1336 |
% options with \texttt{\meta{graph type}/values/axis/reset}. The keys with |x| |
| 1337 |
% are aliases for the similar keys with |values|. If you omit the graph type, |
| 1338 |
% this sets the label for all graph types simultaneously. |
| 1339 |
% |
| 1340 |
% The initial value is: |
| 1341 |
% \begin{verbatim} |
| 1342 |
% values/axis = { |
| 1343 |
% label = \valuename, |
| 1344 |
% ticks and grid={many, integer minor steps} |
| 1345 |
% } |
| 1346 |
% \end{verbatim} |
| 1347 |
% \end{key} |
| 1348 |
% |
| 1349 |
% \begin{demo} |
| 1350 |
% \statisticssetup[graph]{ |
| 1351 |
% width=0.4\columnwidth, |
| 1352 |
% comb/frequencies/axis = { ticks={step=0.08} }, |
| 1353 |
% histogram/y/axis = { grid = none }, |
| 1354 |
% } |
| 1355 |
% \StatsGraph \combdata [ frequencies, y/axis = { |
| 1356 |
% ticks={style=blue}, unit length=4cm per 0.25 units, |
| 1357 |
% } ] |
| 1358 |
% \hfill \StatsGraph \facebook |
| 1359 |
% \end{demo} |
| 1360 |
% |
| 1361 |
% \begin{key}{values/format, x/format, |
| 1362 |
% comb/values/format, comb/x/format, |
| 1363 |
% histogram/values/format, histogram/x/format, |
| 1364 |
% cumulative/values/format, cumulative/x/format} |
| 1365 |
% \begin{syntax} |
| 1366 |
% values/format = \meta{formatting code}, x/format = \meta{formatting code} |
| 1367 |
% \meta{graph type}/values/format = \meta{formatting code} |
| 1368 |
% \meta{graph type}/x/format = \meta{formatting code} |
| 1369 |
% \end{syntax} |
| 1370 |
% These keys set the format to use for all values that are typeset on the |
| 1371 |
% graphs, which currently means the values typeset alongside ticks on the |
| 1372 |
% x~axis. The \meta{formatting code} should be \TeX\ code to render the actual |
| 1373 |
% number, in which all occurrences of |#1| are replaced by the value to |
| 1374 |
% typeset. The formatting code is typeset in math mode. |
| 1375 |
% |
| 1376 |
% Keys of the form |\meta{graph type}/value/format| are used to set the |
| 1377 |
% formatter of values when used in a specific graph. The keys with |x| are |
| 1378 |
% aliases for the similar keys with |values|. If you omit the graph type, this |
| 1379 |
% sets the label for all graph types simultaneously. |
| 1380 |
% |
| 1381 |
% The initial value is |values/format = \num{#1}|. |
| 1382 |
% \end{key} |
| 1383 |
% |
| 1384 |
% \begin{demo} |
| 1385 |
% \StatsGraph \combdata [ |
| 1386 |
% width=0.5\columnwidth, |
| 1387 |
% x/format=\fbox{$#1$} |
| 1388 |
% ] |
| 1389 |
% \end{demo} |
| 1390 |
% |
| 1391 |
% \begin{key}{values/margin, x/margin, |
| 1392 |
% comb/values/margin, comb/x/margin, |
| 1393 |
% histogram/values/margin, histogram/x/margin, |
| 1394 |
% cumulative/values/margin, cumulative/x/margin} |
| 1395 |
% \begin{syntax} |
| 1396 |
% values/margin = \meta{numeric expression},\ |
| 1397 |
%x/margin = \meta{numeric expression} |
| 1398 |
% \meta{graph type}/values/margin = \meta{numeric expression} |
| 1399 |
% \meta{graph type}/x/margin = \meta{numeric expression} |
| 1400 |
% \end{syntax} |
| 1401 |
% These keys set the margin that will be used for the x~axis in the |
| 1402 |
% corresponding graph type, that is the amount of space left and right of the |
| 1403 |
% data that will be reserved by \cs{StatsGraph}. The \meta{numeric expression}, |
| 1404 |
% when evaluated, will correspond to the empty space reserved left of the |
| 1405 |
% smallest value and right of the biggest one, with the same scale as the values |
| 1406 |
% themselves. |
| 1407 |
% |
| 1408 |
% In this expression, the following constants will be available: \cs{min} which |
| 1409 |
% is the minimum value in the graph; \cs{max} which is the maximum value; |
| 1410 |
% \cs{range} which is |\max - \min|; and \cs{xstep} which is the distance |
| 1411 |
% between two minor ticks in the graph (this is the axis step if |
| 1412 |
% |minor steps between steps| is empty). |
| 1413 |
% |
| 1414 |
% The inital value is |x/margin = \xstep / 2|. |
| 1415 |
% \end{key} |
| 1416 |
% |
| 1417 |
% \begin{texnote} |
| 1418 |
% This expression will be evaluated with the rules of |\fp_eval:n| |
| 1419 |
% (with |\fp_gset:Nn| to be exact). |
| 1420 |
% \end{texnote} |
| 1421 |
% |
| 1422 |
% \begin{demo} |
| 1423 |
% \StatsGraph \combdata [ width=0.5\columnwidth, x/margin=2 ] |
| 1424 |
% \end{demo} |
| 1425 |
% |
| 1426 |
% \subsubsection{Settings specific to cumulative graphs} |
| 1427 |
% |
| 1428 |
% \begin{key}{cumulative} |
| 1429 |
% \begin{syntax} |
| 1430 |
% cumulative $[$ = \meta{truth value} $]$ |
| 1431 |
% \end{syntax} |
| 1432 |
% This key activates or deactivates the cumulative mode of \cs{StatsGraph}. The |
| 1433 |
% \meta{truth value} must be either |true| or |false| or be ommited, in which |
| 1434 |
% case it defaults to |true|. |
| 1435 |
% |
| 1436 |
% This mode is currently ignored if the counts are given for pointwise values, |
| 1437 |
% as opposed to value ranges. Support is planned but a suitable interface still |
| 1438 |
% needs to be devised for settings corresponding to the discontinuities. |
| 1439 |
% |
| 1440 |
% The initial value is |cumulative = false|. |
| 1441 |
% \end{key} |
| 1442 |
% |
| 1443 |
% \begin{key}{decreasing} |
| 1444 |
% \begin{syntax} |
| 1445 |
% decreasing $[$ = \meta{truth value} $]$ |
| 1446 |
% \end{syntax} |
| 1447 |
% This key selects whether the cumulative mode of \cs{StatsGraph} plots the |
| 1448 |
% decreasing cumulative distribution function (that maps $x$ to the frequency of |
| 1449 |
% $\left[x;+\infty\right[$) instead of the classical increasing one (mapping $x$ |
| 1450 |
% to the frequency of $\left]-\infty;x\right]$). The \meta{truth value} must be |
| 1451 |
% either |true| or |false| or be ommited, in which case it defaults to |true|. |
| 1452 |
% |
| 1453 |
% The initial value is |decreasing = false|. |
| 1454 |
% \end{key} |
| 1455 |
% |
| 1456 |
% \begin{demo} |
| 1457 |
% \statisticssetup[graph]{ width = 0.25\columnwidth, height=4cm } |
| 1458 |
% \centering |
| 1459 |
% \StatsGraph \facebook |
| 1460 |
% \StatsGraph \facebook [cumulative] |
| 1461 |
% \StatsGraph \facebook [cumulative, decreasing] |
| 1462 |
% \end{demo} |
| 1463 |
% |
| 1464 |
% \subsubsection{Settings specific to histograms} |
| 1465 |
% |
| 1466 |
% \begin{key}{histogram/areas} |
| 1467 |
% \begin{syntax} |
| 1468 |
% histogram/areas $[$ = \meta{truth value} $]$ |
| 1469 |
% \end{syntax} |
| 1470 |
% This key activates or deactivates the typesetting of counts or frequencies |
| 1471 |
% above the rectangles in the histogram. They correspond to the area of the |
| 1472 |
% rectangle according to histogram rules, which explains the name of the key. |
| 1473 |
% |
| 1474 |
% If ommited the \meta{truth value} defaults to |true|, which is also the |
| 1475 |
% initial value. |
| 1476 |
% \end{key} |
| 1477 |
% |
| 1478 |
% \begin{demo} |
| 1479 |
% \StatsGraph \facebook [width=0.5\columnwidth, histogram/areas = false] |
| 1480 |
% \end{demo} |
| 1481 |
% |
| 1482 |
% \begin{key}{histogram/areas/style, histogram/areas/style/reset} |
| 1483 |
% \begin{syntax} |
| 1484 |
% histogram/areas/style = \meta{TikZ node options} |
| 1485 |
% histogram/areas/style/reset |
| 1486 |
% \end{syntax} |
| 1487 |
% This key appends options to the TikZ nodes containing the areas (counts or |
| 1488 |
% frequencies). Note that the typesetting of the areas will be controlled by |
| 1489 |
% the \texttt{histogram/\meta{unit}/format} keys, which means that the |
| 1490 |
% |histogram/areas/style| is intended for common styling. |
| 1491 |
% |
| 1492 |
% The initial value is |histogram/areas/style = { auto, font=\small }|. |
| 1493 |
% |
| 1494 |
% \begin{texnote} |
| 1495 |
% The node is positionned in the middle of the top edge of the rectangle so if |
| 1496 |
% you do not want it there some style option like |auto| or |above| should be |
| 1497 |
% used. |
| 1498 |
% \end{texnote} |
| 1499 |
% \end{key} |
| 1500 |
% |
| 1501 |
% \begin{demo} |
| 1502 |
% \StatsGraph \facebook [ histogram/areas/style/reset, |
| 1503 |
% histogram/areas/style = { fill=white } ] |
| 1504 |
% \end{demo} |
| 1505 |
% |
| 1506 |
% \begin{key}{histogram/counts/autostep, histogram/frequencies/autostep, |
| 1507 |
% histogram/y/autostep} |
| 1508 |
% \begin{syntax} |
| 1509 |
% histogram/\meta{unit}/autostep $[$ = \meta{floating point expression} $]$ |
| 1510 |
% histogram/y/autostep $[$ = \meta{floating point expression} $]$ |
| 1511 |
% \end{syntax} |
| 1512 |
% This key setups the y~axis grid so that a grid tile corresponds to |
| 1513 |
% \meta{floating point expression} items. This expression is interpreted as a |
| 1514 |
% count, but you can use the \cs{total} constant which is the total count. |
| 1515 |
% In particular, |\total/100| represents exactly \SI{1}{\percent}. |
| 1516 |
% |
| 1517 |
% This key essentially divides the \meta{floating point expression} by the |
| 1518 |
% horizontal distance between minor steps of the values axis, then uses the |
| 1519 |
% result as the vertical step. As a convenience, |histogram/y/autostep| forwards |
| 1520 |
% its value to |histogram/legend/area| in addition to the |
| 1521 |
% \texttt{histogram/\meta{unit}/autostep} keys. |
| 1522 |
% |
| 1523 |
% If ommited the \meta{floating point expression} defaults to $1$. |
| 1524 |
% The initial value is |histogram/y/autostep = 1|. |
| 1525 |
% |
| 1526 |
% \begin{texnote} |
| 1527 |
% \texttt{histogram/\meta{unit}/autostep} uses |
| 1528 |
% \texttt{histogram/\meta{unit}/axis} internally, so |
| 1529 |
% \texttt{histogram/\meta{unit}/axis/reset} will neuter its effect. |
| 1530 |
% \end{texnote} |
| 1531 |
% \end{key} |
| 1532 |
% |
| 1533 |
% \begin{demo} |
| 1534 |
% \StatsGraph \facebook [frequencies, histogram/y/autostep=2*\total/100] |
| 1535 |
% \end{demo} |
| 1536 |
% |
| 1537 |
% \begin{key}{histogram/legend, histogram/legend/x, histogram/legend/w} |
| 1538 |
% \begin{syntax} |
| 1539 |
% histogram/legend = "{" \meta{legend keys} "}" |
| 1540 |
% histogram/legend/x = $[$ \meta{floating point expression} $]$ |
| 1541 |
% histogram/legend/w = \meta{floating point expression} |
| 1542 |
% \end{syntax} |
| 1543 |
% If |histogram/legend/x| is set to an empty value, no legend will be typeset. |
| 1544 |
% Else, it should be a \meta{floating point expression} which corresponds to the |
| 1545 |
% \emph{value} at which the left side of the legend rectangle will lie. In that |
| 1546 |
% case |histogram/legend/w| should be a \meta{floating point expression} |
| 1547 |
% representing the width (in value units) of the legend rectangle. |
| 1548 |
% |
| 1549 |
% In both of these expressions, the following constants are available: |
| 1550 |
% \end{key} |
| 1551 |
% \begin{itemize} |
| 1552 |
% \item \cs{min} which is the minimum value where data is present; |
| 1553 |
% \item \cs{max} which is the maximum value where data is present; |
| 1554 |
% \item \cs{range} which is |\max - \min|; |
| 1555 |
% \item \cs{xstep} which is the distance between two minor steps of the x axis. |
| 1556 |
% \end{itemize} |
| 1557 |
% |
| 1558 |
% In fact, you probably will not set these keys directly, but will use the |
| 1559 |
% |histogram/legend| key, which requires as value a comma-separated list of |
| 1560 |
% sub-keys that will be used under the |histogram/legend/| path. In particular, |
| 1561 |
% |histogram/legend = { x=2, y=3 }| is equivalent to |
| 1562 |
% |histogram/legend/x=2, histogram/legend/y=3|. |
| 1563 |
% |
| 1564 |
% \begin{key}{histogram/legend/y, histogram/legend/h, histogram/legend/area} |
| 1565 |
% \begin{syntax} |
| 1566 |
% histogram/legend/y = \meta{floating point expression} |
| 1567 |
% histogram/legend/h = \meta{floating point expression} |
| 1568 |
% histogram/legend/area = \meta{floating point expression} |
| 1569 |
% \end{syntax} |
| 1570 |
% If |histogram/legend/x| is not empty, |histogram/legend/y| and |
| 1571 |
% |histogram/legend/h| should be \meta{floating point expression}s which |
| 1572 |
% correspond to the y~coordinate of the bottom side and the vertical dimension |
| 1573 |
% respectively of the legend rectangle, in count per value units. |
| 1574 |
% |
| 1575 |
% In both of these expressions, the following constants are available: |
| 1576 |
% \end{key} |
| 1577 |
% \begin{itemize} |
| 1578 |
% \item \cs{min} which is the $y$~coordinate of the bottom of all histogram |
| 1579 |
% rectangles (this is always~$0$); |
| 1580 |
% \item \cs{max} which is the $y$~coordinate of the tallest histogram rectangle; |
| 1581 |
% \item \cs{range} which is |\max - \min|; |
| 1582 |
% \item \cs{xstep} which is the distance between two minor steps of the x axis. |
| 1583 |
% \item \cs{width} which is the width of the legend rectangle as computed by |
| 1584 |
% evaluating |histogram/legend/w|; |
| 1585 |
% \item \cs{total} which is the total number of elements, useful when you want |
| 1586 |
% to size the legend using frequencies (the dimensions here always use counts). |
| 1587 |
% \end{itemize} |
| 1588 |
% Additionnally, when evaluating |histogram/legend/y| the |\height|~constant |
| 1589 |
% will be available and equal to the just computed value of |
| 1590 |
% |histogram/legend/h|. |
| 1591 |
% |
| 1592 |
% The key |histogram/legend/area = |\meta{fp expression} is a shorthand for:\\ |
| 1593 |
% |histogram/legend/h = (|\meta{fp expression}|) / \width|. |
| 1594 |
% |
| 1595 |
% Again, you probably will not set these keys directly but using the |
| 1596 |
% |histogram/legend| key. |
| 1597 |
% |
| 1598 |
% \begin{key}{histogram/legend/options, histogram/legend/options/reset, |
| 1599 |
% histogram/legend/label} |
| 1600 |
% \begin{syntax} |
| 1601 |
% histogram/legend/options = \meta{TikZ node options} |
| 1602 |
% histogram/legend/options/reset |
| 1603 |
% histogram/legend/label = \meta{TikZ label value} |
| 1604 |
% \end{syntax} |
| 1605 |
% The key |histogram/legend/options| appends the \meta{TikZ node options} to the |
| 1606 |
% list of options that will be passed to the TikZ node responsible for the |
| 1607 |
% legend rectangle, \emph{after} the options in |histogram/style|. You can use |
| 1608 |
% it to tweak the apparance of the legend. |
| 1609 |
% |
| 1610 |
% The key |histogram/legend/label = |\meta{label} is a shorthand for:\\ |
| 1611 |
% |histogram/legend/options = { label = {|\meta{fp expression}|} }|, and thus |
| 1612 |
% uses the TikZ label syntax. |
| 1613 |
% |
| 1614 |
% Again, you probably will not set these keys directly but using the |
| 1615 |
% |histogram/legend| key. |
| 1616 |
% \end{key} |
| 1617 |
% |
| 1618 |
% The initial value is |histogram/legend = { x=, y=0, w=\xstep, area=1 }| which |
| 1619 |
% means that no legend is typeset, and the legend options are empty. |
| 1620 |
% |
| 1621 |
% \begin{texnote} |
| 1622 |
% |area=1| is actually set by the initial value of |histogram/y/autostep|. |
| 1623 |
% \end{texnote} |
| 1624 |
% |
| 1625 |
% \begin{demo} |
| 1626 |
% \statisticssetup[graph]{ width = 0.48\columnwidth } |
| 1627 |
% \StatsGraph \facebook [ |
| 1628 |
% histogram/legend = { x=9, y=8, label=1 student } |
| 1629 |
% ] |
| 1630 |
% \StatsGraph \facebook [ |
| 1631 |
% frequencies, histogram/y/autostep=0.02*\total, |
| 1632 |
% histogram/legend = { x=12, y=2*\height, w=2, area=0.08*\total, |
| 1633 |
% label=above:\SI{8}{\percent} } |
| 1634 |
% ] |
| 1635 |
% \end{demo} |
| 1636 |
% |
| 1637 |
% \end{documentation} |
| 1638 |
% |
| 1639 |
% \cleardoublepage |
| 1640 |
% \begin{implementation} |
| 1641 |
% |
| 1642 |
% \section{\pkg{\ExplFileName} implementation} |
| 1643 |
% |
| 1644 |
% \begin{macrocode} |
| 1645 |
%<*package> |
| 1646 |
%<@@=statistics> |
| 1647 |
% \end{macrocode} |
| 1648 |
% |
| 1649 |
% \begin{macrocode} |
| 1650 |
\ProvidesExplPackage |
| 1651 |
{\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} |
| 1652 |
% \end{macrocode} |
| 1653 |
% |
| 1654 |
% \begin{macrocode} |
| 1655 |
\RequirePackage{xparse} |
| 1656 |
\RequirePackage{siunitx} |
| 1657 |
\RequirePackage{tikz} |
| 1658 |
\RequirePackage{etoolbox} |
| 1659 |
|
| 1660 |
\ExplSyntaxOff |
| 1661 |
\usetikzlibrary{datavisualization, fit} |
| 1662 |
\ExplSyntaxOn |
| 1663 |
% \end{macrocode} |
| 1664 |
% |
| 1665 |
% Translations |
| 1666 |
% |
| 1667 |
% \begin{macrocode} |
| 1668 |
\tl_new:N \valuename |
| 1669 |
\tl_new:N \countname |
| 1670 |
\tl_new:N \freqname |
| 1671 |
\tl_new:N \ccountname |
| 1672 |
\tl_new:N \cfreqname |
| 1673 |
\tl_new:N \iccname |
| 1674 |
\tl_new:N \icfname |
| 1675 |
\tl_new:N \dccname |
| 1676 |
\tl_new:N \dcfname |
| 1677 |
|
| 1678 |
\tl_set:Nn \valuename { Values } |
| 1679 |
\tl_set:Nn \countname { Count } |
| 1680 |
\tl_set:Nn \ccountname { Cumulative~count } |
| 1681 |
\tl_set:Nn \freqname { Frequency } |
| 1682 |
\tl_set:Nn \cfreqname { Cumulative~frequency } |
| 1683 |
\tl_set:Nn \iccname { ICC } |
| 1684 |
\tl_set:Nn \icfname { ICF } |
| 1685 |
\tl_set:Nn \dccname { DCC } |
| 1686 |
\tl_set:Nn \dcfname { DCF } |
| 1687 |
|
| 1688 |
\AtEndPreamble { |
| 1689 |
\tl_if_exist:NT \captionsfrench { |
| 1690 |
\tl_put_right:Nn \captionsfrench { |
| 1691 |
\tl_set:Nn \valuename { Modalit\'e } |
| 1692 |
\tl_set:Nn \countname { Effectif } |
| 1693 |
\tl_set:Nn \ccountname { Effectif~cumul\'e } |
| 1694 |
\tl_set:Nn \freqname { Fr\'equence } |
| 1695 |
\tl_set:Nn \cfreqname { Fr\'equence~cumul\'ee } |
| 1696 |
\tl_set:Nn \iccname { ECC } |
| 1697 |
\tl_set:Nn \icfname { FCC } |
| 1698 |
\tl_set:Nn \dccname { ECD } |
| 1699 |
\tl_set:Nn \dcfname { FCD } |
| 1700 |
} |
| 1701 |
} |
| 1702 |
} |
| 1703 |
% \end{macrocode} |
| 1704 |
% |
| 1705 |
% \subsection{Common facilities} |
| 1706 |
% |
| 1707 |
% \begin{macrocode} |
| 1708 |
\cs_new_protected:Nn \@@_keys_define:nn { |
| 1709 |
\keys_define:nn { statistics / #1 } { #2 } |
| 1710 |
} |
| 1711 |
\cs_new_protected:Nn \@@_setup:nn { |
| 1712 |
\keys_set:nn { statistics / #1 } { #2 } |
| 1713 |
} |
| 1714 |
\NewDocumentCommand \statisticssetup { o +m } { |
| 1715 |
\IfNoValueTF { #1 } { |
| 1716 |
\keys_set:nn { statistics } { #2 } |
| 1717 |
}{ |
| 1718 |
\keys_set:nn { statistics / #1 } { #2 } |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
\tl_new:N \l_@@_data_tl |
| 1723 |
\seq_new:N \l_@@_show_seq |
| 1724 |
|
| 1725 |
\int_new:N \l_@@_nbvals_int |
| 1726 |
\int_new:N \l_@@_currange_int |
| 1727 |
|
| 1728 |
\fp_new:N \l_@@_total_fp |
| 1729 |
\fp_new:N \l_@@_curtotal_fp |
| 1730 |
|
| 1731 |
\fp_new:N \l_@@_range_min_fp |
| 1732 |
\fp_new:N \l_@@_range_max_fp |
| 1733 |
\tl_new:N \l_@@_range_minrel_tl |
| 1734 |
\tl_new:N \l_@@_range_maxrel_tl |
| 1735 |
\cs_new_protected_nopar:Npn |
| 1736 |
\@@_parse_range:w \IN#1#2;#3;#4#5\q_stop { |
| 1737 |
% \end{macrocode} |
| 1738 |
% |
| 1739 |
% \begin{itemize} |
| 1740 |
% \item |#1| is the first |[| or |]| |
| 1741 |
% \item |#4| is the second |[| or |]| and |#5| eats all trailing tokens |
| 1742 |
% \end{itemize} |
| 1743 |
% |
| 1744 |
% \begin{macrocode} |
| 1745 |
\fp_set:Nn \l_@@_range_min_fp { #2 } |
| 1746 |
\fp_set:Nn \l_@@_range_max_fp { #3 } |
| 1747 |
} |
| 1748 |
\cs_new_protected_nopar:Npn |
| 1749 |
\@@_parse_range_full:w \IN#1#2;#3;#4#5\q_stop { |
| 1750 |
\fp_set:Nn \l_@@_range_min_fp { #2 } |
| 1751 |
\fp_set:Nn \l_@@_range_max_fp { #3 } |
| 1752 |
\tl_if_eq:nnTF { #1 } { [ } { |
| 1753 |
\tl_set:Nn \l_@@_range_minrel_tl { <=} |
| 1754 |
}{ |
| 1755 |
\tl_set:Nn \l_@@_range_minrel_tl { < } |
| 1756 |
} |
| 1757 |
\tl_if_eq:nnTF { #4 } { ] } { |
| 1758 |
\tl_set:Nn \l_@@_range_maxrel_tl { <= } |
| 1759 |
}{ |
| 1760 |
\tl_set:Nn \l_@@_range_maxrel_tl { < } |
| 1761 |
} |
| 1762 |
\exp_args:NNnx |
| 1763 |
\prg_set_conditional:Nnn \@@_if_in_range:n { T } { |
| 1764 |
\exp_not:N \fp_compare:nTF { |
| 1765 |
\exp_not:N \l_@@_range_min_fp |
| 1766 |
\exp_not:V \l_@@_range_minrel_tl |
| 1767 |
\exp_not:n { ##1 } |
| 1768 |
\exp_not:V \l_@@_range_maxrel_tl |
| 1769 |
\exp_not:N \l_@@_range_max_fp }{ |
| 1770 |
\exp_not:N \prg_return_true: |
| 1771 |
}{ |
| 1772 |
\exp_not:N \prg_return_false: |
| 1773 |
} |
| 1774 |
} |
| 1775 |
} |
| 1776 |
% \end{macrocode} |
| 1777 |
% |
| 1778 |
% \subsection{Compute and typeset statistics tables} |
| 1779 |
% |
| 1780 |
% \begin{macrocode} |
| 1781 |
\NewDocumentCommand \@@_IN:w { m u{;} u{;} m } { |
| 1782 |
\ensuremath{ \left#1 \num{#2} \mathbin{;} \num{#3} \right#4 } |
| 1783 |
} |
| 1784 |
|
| 1785 |
\cs_new_protected:Nn \@@_setshow:n { |
| 1786 |
\seq_clear:N \l_@@_show_seq |
| 1787 |
\clist_map_inline:nn {#1} { |
| 1788 |
\tl_if_in:nnTF {##1} {-} { |
| 1789 |
\@@_setshow_aux:w ##1 \q_stop |
| 1790 |
}{ |
| 1791 |
\seq_put_right:Nn \l_@@_show_seq {##1} |
| 1792 |
} |
| 1793 |
} |
| 1794 |
} |
| 1795 |
\cs_new_protected:Npn \@@_setshow_aux:w #1 - #2 \q_stop { |
| 1796 |
\int_step_inline:nnnn {#1} {1} {#2} { |
| 1797 |
\seq_put_right:Nn \l_@@_show_seq {##1} |
| 1798 |
} |
| 1799 |
} |
| 1800 |
\cs_new_protected_nopar:Nn \@@_set_if_shown:N { |
| 1801 |
\seq_if_empty:NTF \l_@@_show_seq { |
| 1802 |
\bool_set_true:N #1 |
| 1803 |
}{ |
| 1804 |
\seq_if_in:NVTF |
| 1805 |
\l_@@_show_seq |
| 1806 |
\l_@@_currange_int { |
| 1807 |
\bool_set_true:N #1 |
| 1808 |
}{ |
| 1809 |
\bool_set_false:N #1 |
| 1810 |
} |
| 1811 |
} |
| 1812 |
} |
| 1813 |
|
| 1814 |
\int_new:N \l_@@_table_maxcols_int |
| 1815 |
\int_set:Nn \l_@@_table_maxcols_int {0} |
| 1816 |
|
| 1817 |
\@@_keys_define:nn { table } { |
| 1818 |
showonly .value_required:n = true, |
| 1819 |
showonly .code:n = \@@_setshow:n{#1}, |
| 1820 |
|
| 1821 |
showonly/hidden .value_required:n = true, |
| 1822 |
showonly/hidden .code:n = { |
| 1823 |
\cs_set_protected:Nn |
| 1824 |
\@@_table_hidden_format:n |
| 1825 |
{ #1 } |
| 1826 |
}, |
| 1827 |
showonly/hidden .initial:n = , |
| 1828 |
|
| 1829 |
showonly/shown .value_required:n = true, |
| 1830 |
showonly/shown .code:n = { |
| 1831 |
\cs_set_protected:Nn |
| 1832 |
\@@_table_shown_format:n |
| 1833 |
{ #1 } |
| 1834 |
}, |
| 1835 |
showonly/shown .initial:n = #1, |
| 1836 |
|
| 1837 |
maxcols .clist_set:N = \l_@@_table_maxcols_clist, |
| 1838 |
maxcols .value_required:n = true, |
| 1839 |
maxcols .initial:n = , |
| 1840 |
|
| 1841 |
tablesep .tl_set:N = \l_@@_table_sep_tl, |
| 1842 |
tablesep .value_required:n = true, |
| 1843 |
tablesep .initial:n = \\, |
| 1844 |
|
| 1845 |
valign .tl_set:N = \l_@@_table_valign_tl, |
| 1846 |
valign .value_required:n = true, |
| 1847 |
valign .initial:n = t, |
| 1848 |
|
| 1849 |
coltype .tl_set:N = \l_@@_table_coltype_tl, |
| 1850 |
coltype .value_required:n = true, |
| 1851 |
|
| 1852 |
headcoltype .tl_set:N = \l_@@_table_headcoltype_tl, |
| 1853 |
headcoltype .value_required:n = true, |
| 1854 |
|
| 1855 |
newline .tl_set:N = \l_@@_table_newline_tl, |
| 1856 |
newline .value_required:n = true, |
| 1857 |
|
| 1858 |
preline .tl_set:N = \l_@@_table_preline_tl, |
| 1859 |
preline .value_required:n = true, |
| 1860 |
|
| 1861 |
postline .tl_set:N = \l_@@_table_postline_tl, |
| 1862 |
postline .value_required:n = true, |
| 1863 |
|
| 1864 |
outline .meta:n = { preline={#1}, postline={#1} }, |
| 1865 |
outline .value_required:n = true, |
| 1866 |
|
| 1867 |
frame .choice:, |
| 1868 |
frame/full .meta:n = { preline=\firsthline, postline=\lasthline, |
| 1869 |
newline=\\\hline, |
| 1870 |
headcoltype=|l|, coltype=c| }, |
| 1871 |
frame/full .value_forbidden:n = true, |
| 1872 |
|
| 1873 |
frame/none .meta:n = { outline=, newline=\\, |
| 1874 |
headcoltype=l, coltype=c }, |
| 1875 |
frame/none .value_forbidden:n = true, |
| 1876 |
|
| 1877 |
frame/clean .meta:n = { preline=\firsthline, postline=\lasthline, |
| 1878 |
newline=\\, |
| 1879 |
headcoltype=l, coltype=c }, |
| 1880 |
frame/clean .initial:n = , |
| 1881 |
frame/clean .value_forbidden:n = true, |
| 1882 |
|
| 1883 |
digits .int_set:N = \l_@@_table_round_int, |
| 1884 |
digits .initial:n = 3, |
| 1885 |
|
| 1886 |
allcounts/format .code:n = { |
| 1887 |
\cs_set_protected:Nn |
| 1888 |
\@@_table_allcounts_format:n |
| 1889 |
{ #1 } |
| 1890 |
}, |
| 1891 |
allcounts/format .value_required:n = true, |
| 1892 |
allcounts/format .initial:n = { \num{#1} }, |
| 1893 |
|
| 1894 |
allfreqs/format .code:n = { |
| 1895 |
\cs_set_protected:Nn |
| 1896 |
\@@_table_allfreqs_format:n |
| 1897 |
{ #1 } |
| 1898 |
}, |
| 1899 |
allfreqs/format .value_required:n = true, |
| 1900 |
|
| 1901 |
allfreqs/format/real .meta:n = { |
| 1902 |
allfreqs/format = \num{##1} |
| 1903 |
}, |
| 1904 |
allfreqs/format/real .value_forbidden:n = true, |
| 1905 |
|
| 1906 |
allfreqs/format/percent .meta:n = { |
| 1907 |
allfreqs/format = \SI{\fp_eval:n{##1*100}}{\percent} |
| 1908 |
}, |
| 1909 |
allfreqs/format/percent .initial:n = , |
| 1910 |
allfreqs/format/percent .value_forbidden:n = true, |
| 1911 |
|
| 1912 |
allfreqs/format/scaled .meta:n = { |
| 1913 |
allfreqs/format = \num{\fp_eval:n{##1*#1}} |
| 1914 |
}, |
| 1915 |
allfreqs/format/scaled .value_required:n = true, |
| 1916 |
} |
| 1917 |
|
| 1918 |
\cs_new:Nn \@@_define_row:nnn { |
| 1919 |
% \end{macrocode} |
| 1920 |
% |
| 1921 |
% \begin{itemize} |
| 1922 |
% \item |#1| (tl): row name; |
| 1923 |
% \item |#2| (bool): enabled by default |
| 1924 |
% \item |#3| (tl): default header; |
| 1925 |
% \end{itemize} |
| 1926 |
% |
| 1927 |
% \begin{macrocode} |
| 1928 |
\tl_new:c { l_@@_table_#1_name_tl } |
| 1929 |
\bool_new:c { l_@@_table_#1_bool } |
| 1930 |
\@@_keys_define:nn { table } { |
| 1931 |
#1 .code:n = { |
| 1932 |
\bool_set_true:c { l_@@_table_#1_bool } |
| 1933 |
\quark_if_no_value:nF { ##1 } { |
| 1934 |
\@@_setup:nn { table } { |
| 1935 |
#1/header = { ##1 } |
| 1936 |
} |
| 1937 |
} |
| 1938 |
}, |
| 1939 |
#1 .default:n = \q_no_value, |
| 1940 |
|
| 1941 |
no#1 .code:n = |
| 1942 |
\bool_set_false:c { l_@@_table_#1_bool }, |
| 1943 |
no#1 .value_forbidden:n = true, |
| 1944 |
|
| 1945 |
#1/header .tl_set:c = { l_@@_table_#1_name_tl }, |
| 1946 |
#1/header .value_required:n = true, |
| 1947 |
#1/header .initial:n = { #3 }, |
| 1948 |
|
| 1949 |
#1/format .code:n = { |
| 1950 |
\cs_set_protected:cn |
| 1951 |
{ _@@_table_#1_format:n } |
| 1952 |
{ ##1 } |
| 1953 |
}, |
| 1954 |
#1/format .value_required:n = true, |
| 1955 |
#1/format .initial:n = { ##1 }, |
| 1956 |
} |
| 1957 |
\bool_set:cn { l_@@_table_#1_bool } { #2 } |
| 1958 |
} |
| 1959 |
|
| 1960 |
\@@_define_row:nnn { values } \c_true_bool \valuename |
| 1961 |
\@@_define_row:nnn { counts } \c_false_bool \countname |
| 1962 |
\@@_define_row:nnn { frequencies } \c_false_bool \freqname |
| 1963 |
\@@_define_row:nnn { icc } \c_false_bool \iccname |
| 1964 |
\@@_define_row:nnn { icf } \c_false_bool \icfname |
| 1965 |
\@@_define_row:nnn { dcc } \c_false_bool \dccname |
| 1966 |
\@@_define_row:nnn { dcf } \c_false_bool \dcfname |
| 1967 |
|
| 1968 |
\@@_setup:nn { table } { |
| 1969 |
values/format = \ensuremath{#1}, |
| 1970 |
} |
| 1971 |
|
| 1972 |
\cs_undefine:N \@@_define_row:nnn |
| 1973 |
|
| 1974 |
\seq_new:N \l_@@_table_contents_seq |
| 1975 |
\tl_new:N \l_@@_table_preamble_tl |
| 1976 |
|
| 1977 |
\tl_new:N \l_@@_table_values_tl |
| 1978 |
\tl_new:N \l_@@_table_counts_tl |
| 1979 |
\tl_new:N \l_@@_table_frequencies_tl |
| 1980 |
\tl_new:N \l_@@_table_icc_tl |
| 1981 |
\tl_new:N \l_@@_table_icf_tl |
| 1982 |
\tl_new:N \l_@@_table_dcc_tl |
| 1983 |
\tl_new:N \l_@@_table_dcf_tl |
| 1984 |
|
| 1985 |
\fp_new:N \l_@@_table_curICF_fp |
| 1986 |
\fp_new:N \l_@@_table_prevICF_fp |
| 1987 |
|
| 1988 |
\bool_new:N \l_@@_table_firstrow_bool |
| 1989 |
|
| 1990 |
\seq_new:N \l_@@_store_values_seq |
| 1991 |
\seq_new:N \l_@@_store_counts_seq |
| 1992 |
|
| 1993 |
\cs_generate_variant:Nn \keyval_parse:NNn { NNV } |
| 1994 |
\NewDocumentCommand \StatsTable { +O{} +m +O{} } { |
| 1995 |
\group_begin: |
| 1996 |
% \end{macrocode} |
| 1997 |
% |
| 1998 |
% Ensure some macros exist with sensible definitions |
| 1999 |
% |
| 2000 |
% \begin{macrocode} |
| 2001 |
\cs_if_exist:NF \firsthline { |
| 2002 |
\cs_set_eq:NN \firsthline \hline |
| 2003 |
} |
| 2004 |
\cs_if_exist:NF \lasthline { |
| 2005 |
\cs_set_eq:NN \lasthline \hline |
| 2006 |
} |
| 2007 |
\cs_if_exist:NF \IN { |
| 2008 |
\cs_set_eq:NN \IN \@@_IN:w |
| 2009 |
} |
| 2010 |
% \end{macrocode} |
| 2011 |
% |
| 2012 |
% Handle optional settings |
| 2013 |
% |
| 2014 |
% \begin{macrocode} |
| 2015 |
\@@_setup:nn { table } { #1, #3 } |
| 2016 |
% \end{macrocode} |
| 2017 |
% |
| 2018 |
% Get the data inline or from a variable |
| 2019 |
% |
| 2020 |
% \begin{macrocode} |
| 2021 |
\tl_if_single:nTF { #2 } { |
| 2022 |
% \end{macrocode} |
| 2023 |
% |
| 2024 |
% Generate meaningful error by using the non-existent variable |
| 2025 |
% |
| 2026 |
% \begin{macrocode} |
| 2027 |
\cs_if_exist:NF #2 { #2 } |
| 2028 |
\tl_set_eq:NN \l_@@_data_tl #2 |
| 2029 |
}{ |
| 2030 |
\tl_set:Nn \l_@@_data_tl { #2 } |
| 2031 |
} |
| 2032 |
% \end{macrocode} |
| 2033 |
% |
| 2034 |
% Define getters for some items of the table, to be used for instance to |
| 2035 |
% programmatically choose the formatting. |
| 2036 |
% |
| 2037 |
% \begin{macrocode} |
| 2038 |
\cs_set_nopar:Npn \getvalue { |
| 2039 |
\seq_item:Nn \l_@@_store_values_seq |
| 2040 |
} |
| 2041 |
\cs_set_nopar:Npn \getcount { |
| 2042 |
\seq_item:Nn \l_@@_store_count_seq |
| 2043 |
} |
| 2044 |
% \end{macrocode} |
| 2045 |
% |
| 2046 |
% Compute the total population count/frequency |
| 2047 |
% |
| 2048 |
% \begin{macrocode} |
| 2049 |
\fp_zero:N \l_@@_total_fp |
| 2050 |
\keyval_parse:NNV |
| 2051 |
\@@_table_count:n |
| 2052 |
\@@_table_count:nn |
| 2053 |
\l_@@_data_tl |
| 2054 |
% \end{macrocode} |
| 2055 |
% |
| 2056 |
% Loop again and output the table |
| 2057 |
% |
| 2058 |
% \begin{macrocode} |
| 2059 |
\@@_table_start: |
| 2060 |
\fp_zero:N \l_@@_table_prevICF_fp |
| 2061 |
\keyval_parse:NNV |
| 2062 |
\@@_table_make:n |
| 2063 |
\@@_table_make:nn |
| 2064 |
\l_@@_data_tl |
| 2065 |
\@@_table_end: |
| 2066 |
% \end{macrocode} |
| 2067 |
% |
| 2068 |
% Done |
| 2069 |
% |
| 2070 |
% \begin{macrocode} |
| 2071 |
\group_end: |
| 2072 |
} |
| 2073 |
% \end{macrocode} |
| 2074 |
% |
| 2075 |
% table building functions |
| 2076 |
% |
| 2077 |
% \begin{macrocode} |
| 2078 |
\cs_new_protected_nopar:Nn \@@_table_start: { |
| 2079 |
% \end{macrocode} |
| 2080 |
% |
| 2081 |
% Init column count and fetch the next maxcols value (or keep the current one if |
| 2082 |
% we reached the end of the list). |
| 2083 |
% |
| 2084 |
% \begin{macrocode} |
| 2085 |
\int_zero:N \l_@@_nbvals_int |
| 2086 |
\clist_pop:NNT \l_@@_table_maxcols_clist \l_tmpa_tl { |
| 2087 |
\int_set:Nn \l_@@_table_maxcols_int { \l_tmpa_tl } |
| 2088 |
} |
| 2089 |
% \end{macrocode} |
| 2090 |
% |
| 2091 |
% Start rows with headers |
| 2092 |
% |
| 2093 |
% \begin{macrocode} |
| 2094 |
\clist_map_inline:nn { values, counts, frequencies, icc, icf, dcc, dcf } { |
| 2095 |
\tl_set:cx { l_@@_table_##1_tl } { |
| 2096 |
\exp_not:N \ensuremath { \exp_not:N \hbox { |
| 2097 |
\exp_not:c { l_@@_table_##1_name_tl } |
| 2098 |
} } |
| 2099 |
} |
| 2100 |
} |
| 2101 |
} |
| 2102 |
\cs_new_protected_nopar:Nn \@@_table_end: { |
| 2103 |
% \end{macrocode} |
| 2104 |
% |
| 2105 |
% Build-up the table preamble |
| 2106 |
% |
| 2107 |
% \begin{macrocode} |
| 2108 |
\tl_set:Nx \l_@@_table_preamble_tl { |
| 2109 |
\exp_not:n { \begin{array}[ } |
| 2110 |
\exp_not:V \l_@@_table_valign_tl |
| 2111 |
\exp_not:n { ] } |
| 2112 |
{ \exp_not:V \l_@@_table_headcoltype_tl |
| 2113 |
\prg_replicate:nn { \l_@@_nbvals_int } |
| 2114 |
{ \exp_not:V \l_@@_table_coltype_tl } } |
| 2115 |
} |
| 2116 |
% \end{macrocode} |
| 2117 |
% |
| 2118 |
% Add each row if needed. |
| 2119 |
% |
| 2120 |
% \begin{macrocode} |
| 2121 |
\seq_clear:N \l_@@_table_contents_seq |
| 2122 |
\clist_map_inline:nn { values, counts, icc, dcc, frequencies, icf, dcf } { |
| 2123 |
\bool_if:cT { l_@@_table_##1_bool } { |
| 2124 |
\seq_put_right:Nv |
| 2125 |
\l_@@_table_contents_seq |
| 2126 |
{ l_@@_table_##1_tl } |
| 2127 |
} |
| 2128 |
} |
| 2129 |
$\tl_use:N \l_@@_table_preamble_tl |
| 2130 |
\l_@@_table_preline_tl |
| 2131 |
\seq_use:Nn |
| 2132 |
\l_@@_table_contents_seq |
| 2133 |
{ \l_@@_table_newline_tl } |
| 2134 |
\\ \l_@@_table_postline_tl |
| 2135 |
\end{array}$ |
| 2136 |
} |
| 2137 |
% \end{macrocode} |
| 2138 |
% |
| 2139 |
% Counting auxiliaries |
| 2140 |
% |
| 2141 |
% \begin{macrocode} |
| 2142 |
\cs_new_protected_nopar:Nn \@@_table_count:n { |
| 2143 |
\@@_table_count:nn {} { 1 } |
| 2144 |
} |
| 2145 |
\cs_new_protected_nopar:Nn \@@_table_count:nn { |
| 2146 |
\fp_add:Nn \l_@@_total_fp { #2 } |
| 2147 |
} |
| 2148 |
% \end{macrocode} |
| 2149 |
% |
| 2150 |
% Accumulating content |
| 2151 |
% |
| 2152 |
% \begin{macrocode} |
| 2153 |
\cs_new_protected_nopar:Nn \@@_table_make:n { |
| 2154 |
\@@_table_make:nn { #1 } { 1 } |
| 2155 |
} |
| 2156 |
\cs_new_protected_nopar:Nn \@@_table_make:nn { |
| 2157 |
% \end{macrocode} |
| 2158 |
% |
| 2159 |
% Maybe close the table and create a new one |
| 2160 |
% |
| 2161 |
% \begin{macrocode} |
| 2162 |
\int_compare:nT |
| 2163 |
{ 0 < \l_@@_table_maxcols_int |
| 2164 |
= \l_@@_nbvals_int } { |
| 2165 |
\@@_table_end: |
| 2166 |
\tl_use:N \l_@@_table_sep_tl |
| 2167 |
\@@_table_start: |
| 2168 |
} |
| 2169 |
\int_incr:N \l_@@_nbvals_int |
| 2170 |
\int_incr:N \l_@@_currange_int |
| 2171 |
\fp_add:Nn \l_@@_curtotal_fp { #2 } |
| 2172 |
% \end{macrocode} |
| 2173 |
% |
| 2174 |
% Hidden or not |
| 2175 |
% |
| 2176 |
% \begin{macrocode} |
| 2177 |
\@@_set_if_shown:N \l_tmpa_bool |
| 2178 |
\tl_set:Nx \l_tmpa_tl { |
| 2179 |
\exp_not:n { & \tl_set:Nn \currentcolumn } { |
| 2180 |
\int_use:N \l_@@_currange_int |
| 2181 |
} |
| 2182 |
} |
| 2183 |
\bool_if:NTF \l_tmpa_bool { |
| 2184 |
\tl_put_right:Nn \l_tmpa_tl |
| 2185 |
{\@@_table_shown_format:n} |
| 2186 |
}{ |
| 2187 |
\tl_put_right:Nn \l_tmpa_tl |
| 2188 |
{\@@_table_hidden_format:n} |
| 2189 |
} |
| 2190 |
% \end{macrocode} |
| 2191 |
% |
| 2192 |
% Values |
| 2193 |
% |
| 2194 |
% \begin{macrocode} |
| 2195 |
\seq_put_right:Nn \l_@@_store_values_seq { #1 } |
| 2196 |
\bool_if:NT \l_@@_table_values_bool { |
| 2197 |
\tl_put_right:Nx \l_@@_table_values_tl { |
| 2198 |
\exp_not:V \l_tmpa_tl { |
| 2199 |
\exp_not:n { |
| 2200 |
\@@_table_values_format:n { #1 } |
| 2201 |
} |
| 2202 |
} |
| 2203 |
} |
| 2204 |
} |
| 2205 |
% \end{macrocode} |
| 2206 |
% |
| 2207 |
% Counts |
| 2208 |
% |
| 2209 |
% \begin{macrocode} |
| 2210 |
\seq_put_right:Nx \l_@@_store_counts_seq { \fp_eval:n {#2} } |
| 2211 |
\bool_if:NT \l_@@_table_counts_bool { |
| 2212 |
\tl_put_right:Nx \l_@@_table_counts_tl { |
| 2213 |
\exp_not:V \l_tmpa_tl { |
| 2214 |
\exp_not:n { |
| 2215 |
\@@_table_counts_format:n { |
| 2216 |
{ \@@_table_allcounts_format:n { #2 } } |
| 2217 |
} |
| 2218 |
} |
| 2219 |
} |
| 2220 |
} |
| 2221 |
} |
| 2222 |
% \end{macrocode} |
| 2223 |
% |
| 2224 |
% ICC |
| 2225 |
% |
| 2226 |
% \begin{macrocode} |
| 2227 |
\bool_if:NT \l_@@_table_icc_bool { |
| 2228 |
\tl_put_right:Nx \l_@@_table_icc_tl { |
| 2229 |
\exp_not:V \l_tmpa_tl { |
| 2230 |
\exp_not:n { \@@_table_icc_format:n } |
| 2231 |
{ |
| 2232 |
\exp_not:n{ \@@_table_allcounts_format:n } |
| 2233 |
{ \fp_use:N \l_@@_curtotal_fp } |
| 2234 |
} |
| 2235 |
} |
| 2236 |
} |
| 2237 |
} |
| 2238 |
% \end{macrocode} |
| 2239 |
% |
| 2240 |
% DCC ( = 1 - ICC + curcount ) |
| 2241 |
% |
| 2242 |
% \begin{macrocode} |
| 2243 |
\bool_if:NT \l_@@_table_dcc_bool { |
| 2244 |
\tl_put_right:Nx \l_@@_table_dcc_tl { |
| 2245 |
\exp_not:V \l_tmpa_tl { |
| 2246 |
\exp_not:n { \@@_table_dcc_format:n } |
| 2247 |
{ |
| 2248 |
\exp_not:n{ \@@_table_allcounts_format:n } |
| 2249 |
{ |
| 2250 |
\fp_eval:n { |
| 2251 |
\l_@@_total_fp |
| 2252 |
- \l_@@_curtotal_fp |
| 2253 |
+ #2 |
| 2254 |
} |
| 2255 |
} |
| 2256 |
} |
| 2257 |
} |
| 2258 |
} |
| 2259 |
} |
| 2260 |
% \end{macrocode} |
| 2261 |
% |
| 2262 |
% Frequencies (we compute them from the ICFs so that rounded freqs add up to 1) |
| 2263 |
% |
| 2264 |
% \begin{macrocode} |
| 2265 |
\fp_set:Nn \l_@@_table_curICF_fp { |
| 2266 |
round(\l_@@_curtotal_fp |
| 2267 |
/ \l_@@_total_fp, |
| 2268 |
\l_@@_table_round_int) |
| 2269 |
} |
| 2270 |
\bool_if:NT \l_@@_table_frequencies_bool { |
| 2271 |
\tl_put_right:Nx \l_@@_table_frequencies_tl { |
| 2272 |
\exp_not:V \l_tmpa_tl { |
| 2273 |
\exp_not:n { \@@_table_frequencies_format:n } |
| 2274 |
{ |
| 2275 |
\exp_not:n{ \@@_table_allfreqs_format:n } |
| 2276 |
{ |
| 2277 |
\fp_eval:n { |
| 2278 |
\l_@@_table_curICF_fp |
| 2279 |
- \l_@@_table_prevICF_fp |
| 2280 |
} |
| 2281 |
} |
| 2282 |
} |
| 2283 |
} |
| 2284 |
} |
| 2285 |
} |
| 2286 |
% \end{macrocode} |
| 2287 |
% |
| 2288 |
% ICF |
| 2289 |
% |
| 2290 |
% \begin{macrocode} |
| 2291 |
\bool_if:NT \l_@@_table_icf_bool { |
| 2292 |
\tl_put_right:Nx \l_@@_table_icf_tl { |
| 2293 |
\exp_not:V \l_tmpa_tl { |
| 2294 |
\exp_not:n { \@@_table_icf_format:n } |
| 2295 |
{ |
| 2296 |
\exp_not:n{ \@@_table_allfreqs_format:n } |
| 2297 |
{ \fp_to_decimal:N \l_@@_table_curICF_fp } |
| 2298 |
} |
| 2299 |
} |
| 2300 |
} |
| 2301 |
} |
| 2302 |
% \end{macrocode} |
| 2303 |
% |
| 2304 |
% DCF ( = 1 - ICF + curfreq = 1 - prevICF ) |
| 2305 |
% |
| 2306 |
% \begin{macrocode} |
| 2307 |
\bool_if:NT \l_@@_table_dcf_bool { |
| 2308 |
\tl_put_right:Nx \l_@@_table_dcf_tl { |
| 2309 |
\exp_not:V \l_tmpa_tl { |
| 2310 |
\exp_not:n { \@@_table_dcf_format:n } |
| 2311 |
{ |
| 2312 |
\exp_not:n{ \@@_table_allfreqs_format:n } |
| 2313 |
{ |
| 2314 |
\fp_eval:n { |
| 2315 |
1 - \l_@@_table_prevICF_fp |
| 2316 |
} |
| 2317 |
} |
| 2318 |
} |
| 2319 |
} |
| 2320 |
} |
| 2321 |
} |
| 2322 |
% \end{macrocode} |
| 2323 |
% |
| 2324 |
% Prepare for next iteration |
| 2325 |
% |
| 2326 |
% \begin{macrocode} |
| 2327 |
\fp_set_eq:NN |
| 2328 |
\l_@@_table_prevICF_fp |
| 2329 |
\l_@@_table_curICF_fp |
| 2330 |
} |
| 2331 |
% \end{macrocode} |
| 2332 |
% |
| 2333 |
% \subsection{Compute and typeset statistics graphics} |
| 2334 |
% |
| 2335 |
% \begin{macrocode} |
| 2336 |
\cs_new_protected:Nn \@@_make_forwarded_key:nnnn { |
| 2337 |
% \end{macrocode} |
| 2338 |
% |
| 2339 |
% \begin{itemize} |
| 2340 |
% \item |#1| (tl): common prefix |
| 2341 |
% \item |#2| (tl): middle |
| 2342 |
% \item |#3| (clist): replacements |
| 2343 |
% \item |#4| (tl): common suffix |
| 2344 |
% \end{itemize} |
| 2345 |
% |
| 2346 |
% \begin{macrocode} |
| 2347 |
\tl_clear:N \l_tmpa_tl |
| 2348 |
\clist_map_inline:nn {#3} { |
| 2349 |
\tl_put_right:Nx \l_tmpa_tl { |
| 2350 |
\exp_not:n {#1} |
| 2351 |
\tl_if_empty:nF {#1} { \tl_if_empty:nF {##1} {\exp_not:N /} } |
| 2352 |
\exp_not:n {##1} |
| 2353 |
\tl_if_empty:nF {#4} { \tl_if_empty:nF {##1} {\exp_not:N /} } |
| 2354 |
\exp_not:n {#4,} |
| 2355 |
} |
| 2356 |
} |
| 2357 |
\tl_set:Nx \l_tmpb_tl { |
| 2358 |
\exp_not:n {#1} |
| 2359 |
\tl_if_empty:nF {#1} { \tl_if_empty:nF {#2} {\exp_not:N /} } |
| 2360 |
\exp_not:n {#2} |
| 2361 |
\tl_if_empty:nF {#4} { \tl_if_empty:nF {#2} {\exp_not:N /} } |
| 2362 |
\exp_not:n {#4} |
| 2363 |
} |
| 2364 |
\use:x { |
| 2365 |
\exp_not:n { \@@_keys_define:nn { graph } } |
| 2366 |
{ |
| 2367 |
\exp_not:V \l_tmpb_tl \exp_not:n { .default:n = \q_no_value, } |
| 2368 |
\exp_not:V \l_tmpb_tl |
| 2369 |
\exp_not:n { .code:n = \@@_forwarded_key:nn } |
| 2370 |
{ \exp_not:V \l_tmpa_tl } |
| 2371 |
{ \exp_not:n { ##1 } } |
| 2372 |
} |
| 2373 |
} |
| 2374 |
} |
| 2375 |
\cs_new_protected:Nn \@@_forwarded_key:nn { |
| 2376 |
\quark_if_no_value:nTF { #2 } { |
| 2377 |
\@@_setup:nn { graph } { #1 } |
| 2378 |
}{ |
| 2379 |
\clist_set:Nn \l_tmpa_clist { #1,{} } |
| 2380 |
\use:x { |
| 2381 |
\exp_not:n { \@@_setup:nn { graph } } { |
| 2382 |
\clist_use:Nn \l_tmpa_clist { = {#2}, } |
| 2383 |
} |
| 2384 |
} |
| 2385 |
} |
| 2386 |
} |
| 2387 |
\cs_new_protected_nopar:Nn \@@_forward_keys:nn { |
| 2388 |
% \end{macrocode} |
| 2389 |
% |
| 2390 |
% \begin{itemize} |
| 2391 |
% \item |#1| (clist): destination prefixes |
| 2392 |
% \item |#2| (clist): keys |
| 2393 |
% \end{itemize} |
| 2394 |
% |
| 2395 |
% \begin{macrocode} |
| 2396 |
\clist_map_inline:nn {#2} { |
| 2397 |
\@@_make_forwarded_key:nnnn {} {} { #1 } { ##1 } |
| 2398 |
} |
| 2399 |
} |
| 2400 |
|
| 2401 |
\cs_new:Nn \@@_create_append_reset:nn { |
| 2402 |
% \end{macrocode} |
| 2403 |
% |
| 2404 |
% \begin{itemize} |
| 2405 |
% \item |#1| (tl): key basename |
| 2406 |
% \item |#2| (var): suffix of variable to store options into |
| 2407 |
% \end{itemize} |
| 2408 |
% |
| 2409 |
% \begin{macrocode} |
| 2410 |
\tl_new:c { l_@@_graph_#2_tl } |
| 2411 |
\@@_keys_define:nn { graph } { |
| 2412 |
#1 .value_required:n = true, |
| 2413 |
#1 .code:n = \tl_put_right:cn |
| 2414 |
{ l_@@_graph_#2_tl } |
| 2415 |
{ ##1, }, |
| 2416 |
|
| 2417 |
#1/reset .value_forbidden:n = true, |
| 2418 |
#1/reset .code:n = \tl_clear:c |
| 2419 |
{ l_@@_graph_#2_tl }, |
| 2420 |
} |
| 2421 |
} |
| 2422 |
|
| 2423 |
\cs_new:Nn \@@_DO:nn { \@@_create_append_reset:nn {#1}{options_#2} } |
| 2424 |
|
| 2425 |
\cs_new:Nn \@@_define_unit:nn { |
| 2426 |
% \end{macrocode} |
| 2427 |
% |
| 2428 |
% \begin{itemize} |
| 2429 |
% \item |#1| (tl): unit name (plural) |
| 2430 |
% \item |#2| (tl): graph type |
| 2431 |
% \end{itemize} |
| 2432 |
% |
| 2433 |
% \begin{macrocode} |
| 2434 |
\@@_DO:nn { #2/#1/axis } { #2_#1axis } |
| 2435 |
\@@_keys_define:nn { graph } { |
| 2436 |
#2/#1 .code:n = { |
| 2437 |
\tl_set:cn {l_@@_graph_#2_unit_tl} { #1 } |
| 2438 |
\quark_if_no_value:nF { ##1 } { |
| 2439 |
\@@_setup:nn { graph }{ #2/#1/label = { ##1 } } |
| 2440 |
} |
| 2441 |
}, |
| 2442 |
#2/#1 .default:n = \q_no_value, |
| 2443 |
|
| 2444 |
#2/#1/label .meta:n = { #2/#1/axis = { label = { ##1 } } }, |
| 2445 |
#2/#1/label .value_required:n = true, |
| 2446 |
|
| 2447 |
#2/#1/format .code:n = { |
| 2448 |
\cs_set_protected:cn |
| 2449 |
{ @@_graph_#2_#1_format:n } |
| 2450 |
{ ##1 } |
| 2451 |
}, |
| 2452 |
#2/#1/format .value_required:n = true, |
| 2453 |
|
| 2454 |
#2/#1/margin .tl_set:c = l_@@_graph_#2_#1_vmargin_tl, |
| 2455 |
#2/#1/margin .value_required:n = true, |
| 2456 |
} |
| 2457 |
} |
| 2458 |
|
| 2459 |
\@@_DO:nn { picture } { pic } |
| 2460 |
\@@_DO:nn { axissystem } { system } |
| 2461 |
|
| 2462 |
\@@_DO:nn { histogram/areas/style } { areas } |
| 2463 |
\@@_DO:nn { histogram/legend/options } { legend } |
| 2464 |
|
| 2465 |
\clist_map_inline:nn { histogram, cumulative, comb } { |
| 2466 |
\@@_define_unit:nn { counts } { #1 } |
| 2467 |
\@@_define_unit:nn { frequencies } { #1 } |
| 2468 |
\@@_DO:nn { #1/style } { #1 } |
| 2469 |
\@@_DO:nn { #1/values/axis } { #1_xaxis } |
| 2470 |
\@@_keys_define:nn { graph/#1 } { |
| 2471 |
values/margin .value_required:n = true, |
| 2472 |
values/margin .tl_set:c = l_@@_graph_#1_hmargin_tl, |
| 2473 |
|
| 2474 |
values/label .meta:n = { values/axis = { label = { ##1 } } }, |
| 2475 |
values/label .value_required:n = true, |
| 2476 |
|
| 2477 |
values/format .code:n = { \cs_set_protected:cn |
| 2478 |
{@@_graph_#1_values_format:n} { ##1 } |
| 2479 |
}, |
| 2480 |
values/format .value_required:n = true, |
| 2481 |
|
| 2482 |
frequencies/format/real .meta:n = { |
| 2483 |
frequencies/format = { |
| 2484 |
\num[round-mode=places,round-precision=##1]{####1} |
| 2485 |
} |
| 2486 |
}, |
| 2487 |
frequencies/format/real .default:n = 1, |
| 2488 |
|
| 2489 |
frequencies/format/percent .meta:n = { |
| 2490 |
frequencies/format = { |
| 2491 |
\SI[round-mode=places,round-precision=##1]{ |
| 2492 |
\fp_eval:n{####1*100} |
| 2493 |
}{\percent} |
| 2494 |
} |
| 2495 |
}, |
| 2496 |
frequencies/format/percent .default:n = 1, |
| 2497 |
} |
| 2498 |
\@@_make_forwarded_key:nnnn {#1/values}{}{label}{} |
| 2499 |
\clist_map_inline:nn { axis, axis/reset, label, margin, format } { |
| 2500 |
\@@_make_forwarded_key:nnnn {#1}{x}{values}{##1} |
| 2501 |
\@@_make_forwarded_key:nnnn {#1}{y}{counts, frequencies}{##1} |
| 2502 |
} |
| 2503 |
} |
| 2504 |
|
| 2505 |
\cs_undefine:N \@@_DO:nn |
| 2506 |
\cs_undefine:N \@@_define_unit:nnn |
| 2507 |
|
| 2508 |
\@@_forward_keys:nn { histogram, cumulative, comb } { |
| 2509 |
values, values/label, values/margin, values/format, |
| 2510 |
values/axis, values/axis/reset, |
| 2511 |
x/label, x/axis, x/axis/reset, x/margin, x/format, |
| 2512 |
counts, counts/label, counts/margin, counts/format, |
| 2513 |
counts/axis, counts/axis/reset, |
| 2514 |
frequencies, frequencies/label, frequencies/margin, |
| 2515 |
frequencies/format, frequencies/format/real, frequencies/format/percent, |
| 2516 |
frequencies/axis, frequencies/axis/reset, |
| 2517 |
y/label, y/axis, y/axis/reset, y/margin, y/format, |
| 2518 |
style, style/reset |
| 2519 |
} |
| 2520 |
|
| 2521 |
\@@_create_append_reset:nn { tikzinfo' } { userpreinfo } |
| 2522 |
\@@_create_append_reset:nn { tikzinfo } { userpostinfo } |
| 2523 |
|
| 2524 |
\cs_undefine:N \@@_forward_keys:nn |
| 2525 |
\cs_undefine:N \@@_make_forwarded_key:nnnn |
| 2526 |
\cs_undefine:N \@@_create_append_reset:nn |
| 2527 |
|
| 2528 |
\@@_keys_define:nn { graph } { |
| 2529 |
showonly .value_required:n = true, |
| 2530 |
showonly .code:n = \@@_setshow:n{#1}, |
| 2531 |
|
| 2532 |
height .value_required:n = true, |
| 2533 |
height .meta:n = { axissystem = { height = { #1 } } }, |
| 2534 |
|
| 2535 |
width .value_required:n = true, |
| 2536 |
width .meta:n = { axissystem = { width = { #1 } } }, |
| 2537 |
|
| 2538 |
cumulative .bool_set:N = \l_@@_graph_cumulative_bool, |
| 2539 |
cumulative .default:n = true, |
| 2540 |
|
| 2541 |
decreasing .bool_set:N = \l_@@_graph_decreasing_bool, |
| 2542 |
decreasing .default:n = true, |
| 2543 |
|
| 2544 |
histogram/areas .bool_set:N = \l_@@_graph_areas_bool, |
| 2545 |
histogram/areas .default:n = true, |
| 2546 |
|
| 2547 |
histogram/legend/label .value_required:n = true, |
| 2548 |
histogram/legend/label .meta:n = { |
| 2549 |
histogram/legend/options = {label={#1}} }, |
| 2550 |
|
| 2551 |
histogram/legend/area .value_required:n = true, |
| 2552 |
histogram/legend/area .meta:n = { |
| 2553 |
histogram/legend/h = (#1)/\width }, |
| 2554 |
|
| 2555 |
histogram/legend .value_required:n = true, |
| 2556 |
histogram/legend .code:n = { |
| 2557 |
\@@_setup:nn { graph / histogram/legend } { |
| 2558 |
#1 |
| 2559 |
} |
| 2560 |
}, |
| 2561 |
|
| 2562 |
histogram/y/autostep .value_required:n = true, |
| 2563 |
histogram/y/autostep .meta:n = { |
| 2564 |
histogram/counts/autostep = {#1}, |
| 2565 |
histogram/frequencies/autostep = {#1}, |
| 2566 |
histogram/legend/area = {#1}, |
| 2567 |
}, |
| 2568 |
} |
| 2569 |
\tl_map_inline:nn {xywh} { |
| 2570 |
\@@_keys_define:nn { graph / histogram / legend } { |
| 2571 |
#1 .value_required:n = true, |
| 2572 |
#1 .tl_set:c = {l_@@_graph_legend_#1_tl}, |
| 2573 |
} |
| 2574 |
} |
| 2575 |
\clist_map_inline:nn { counts, frequencies } { |
| 2576 |
\@@_keys_define:nn { graph/histogram/#1 } { |
| 2577 |
autostep .default:n = 1, |
| 2578 |
autostep .meta:n = { axis = { |
| 2579 |
grid = { compute~step = |
| 2580 |
\group_begin: |
| 2581 |
\tl_set:Nx \total { \fp_to_decimal:N \l_@@_total_fp } |
| 2582 |
\fp_gset:Nn \g_tmpa_fp { ##1 } |
| 2583 |
\group_end: |
| 2584 |
\tl_set:Nx \tikz@lib@dv@step { |
| 2585 |
\fp_eval:n {\g_tmpa_fp / \g_@@_graph_xstep_fp } |
| 2586 |
} |
| 2587 |
} |
| 2588 |
}}, |
| 2589 |
} |
| 2590 |
} |
| 2591 |
|
| 2592 |
\@@_setup:nn { graph }{ |
| 2593 |
width = 0.75\columnwidth, |
| 2594 |
cumulative = false, |
| 2595 |
decreasing = false, |
| 2596 |
|
| 2597 |
values/axis = { |
| 2598 |
label = \valuename, |
| 2599 |
ticks~and~grid={many, integer~minor~steps} |
| 2600 |
}, |
| 2601 |
values/margin = \xstep / 2, |
| 2602 |
values/format = \num{#1}, |
| 2603 |
|
| 2604 |
y/margin = \range/10, |
| 2605 |
|
| 2606 |
counts/format = { \num{#1} }, |
| 2607 |
counts/axis = { ticks~and~grid={ |
| 2608 |
many, int~about~strategy, integer~minor~steps*, |
| 2609 |
} }, |
| 2610 |
comb/counts/label = \countname, |
| 2611 |
cumulative/counts/label = \ccountname, |
| 2612 |
|
| 2613 |
frequencies/format/percent, |
| 2614 |
frequencies/axis = { ticks~and~grid=many }, |
| 2615 |
comb/frequencies/label = \freqname, |
| 2616 |
cumulative/frequencies/label = \cfreqname, |
| 2617 |
|
| 2618 |
histogram/y/axis/reset, |
| 2619 |
histogram/y/axis = {ticks = none}, |
| 2620 |
histogram/y/autostep = 1, |
| 2621 |
histogram/legend = { x=, y=0, w=\xstep }, |
| 2622 |
histogram/style = { |
| 2623 |
every~path/.prefix~style=fill, |
| 2624 |
semithick, black, fill=black, fill~opacity=0.1 |
| 2625 |
}, |
| 2626 |
histogram/areas, |
| 2627 |
histogram/areas/style = { auto, font=\small }, |
| 2628 |
|
| 2629 |
comb/style = { ultra~thick }, |
| 2630 |
|
| 2631 |
counts, |
| 2632 |
|
| 2633 |
picture = { |
| 2634 |
baseline = (current~bounding~box.center), |
| 2635 |
label~position = right, |
| 2636 |
}, |
| 2637 |
} |
| 2638 |
|
| 2639 |
\tl_const:Nn \c_@@_graph_savexstep_tl { |
| 2640 |
grid = { compute~step/.append = { |
| 2641 |
\cs_if_eq:NNF \tikz@lib@dv@step \relax { |
| 2642 |
\pgfkeysgetvalue |
| 2643 |
{/tikz/data~visualization/minor~steps~between~steps} |
| 2644 |
\l_tmpa_tl |
| 2645 |
\fp_gset:Nn \g_@@_graph_xstep_fp { |
| 2646 |
\tikz@lib@dv@step |
| 2647 |
/ (\fp_max:nn{0\l_tmpa_tl + 1}{1}) |
| 2648 |
} |
| 2649 |
} |
| 2650 |
}} |
| 2651 |
} |
| 2652 |
% \end{macrocode} |
| 2653 |
% |
| 2654 |
% To detect that the user didn't set |minor steps between steps| himself after |
| 2655 |
% having used |integer minor steps| (which can be a default setting), we add a |
| 2656 |
% handler to the key that sets its value but also empties |
| 2657 |
% \cs{l_@@_graph_maxminor_tl} so that we do not overwrite anything. |
| 2658 |
% |
| 2659 |
% \begin{macrocode} |
| 2660 |
\tl_new:N \l_@@_graph_maxminor_tl |
| 2661 |
\int_new:N \l_@@_graph_minorsteps_int |
| 2662 |
\fp_new:N \l_@@_graph_ims_step_fp |
| 2663 |
\fp_new:N \l_@@_graph_ims_range_fp |
| 2664 |
\fp_new:N \l_@@_graph_ims_threshold_fp |
| 2665 |
\tikzdatavisualizationset{ |
| 2666 |
integer~minor~steps/.style={ |
| 2667 |
/utils/exec = \tl_set:Nn \l_@@_graph_maxminor_tl {#1}, |
| 2668 |
minor~steps~between~steps/.code= |
| 2669 |
\tl_clear:N \l_@@_graph_maxminor_tl |
| 2670 |
\pgfkeyssetvalue |
| 2671 |
{/tikz/data~visualization/minor~steps~between~steps} |
| 2672 |
{##1} , |
| 2673 |
compute~step/.append = { |
| 2674 |
\tl_set_eq:NN \l_tmpa_tl \tikz@lib@dv@step |
| 2675 |
\tl_if_empty:NT \l_@@_graph_maxminor_tl { |
| 2676 |
\tl_set_eq:NN \l_tmpa_tl \relax |
| 2677 |
} |
| 2678 |
\tl_if_eq:NNF \l_tmpa_tl \relax { |
| 2679 |
\fp_set:Nn \l_@@_graph_ims_step_fp { \l_tmpa_tl } |
| 2680 |
\tikz@lib@[email protected]~in~range~interval() |
| 2681 |
\pgfdvinrangeinterval.get~min~and~max() |
| 2682 |
\pgfdvmathexitbyscientificformat \l_tmpa_tl \pgfdvmin |
| 2683 |
\pgfdvmathexitbyscientificformat \l_tmpb_tl \pgfdvmax |
| 2684 |
\fp_set:Nn \l_@@_graph_ims_range_fp { \l_tmpb_tl - \l_tmpa_tl } |
| 2685 |
\fp_set:Nn \l_@@_graph_ims_threshold_fp { |
| 2686 |
\fp_max:nn { |
| 2687 |
\l_@@_graph_ims_step_fp * (\l_@@_graph_maxminor_tl) |
| 2688 |
}{ |
| 2689 |
\l_@@_graph_ims_range_fp |
| 2690 |
} |
| 2691 |
} |
| 2692 |
\int_set:Nn \l_@@_graph_minorsteps_int |
| 2693 |
{ \fp_to_int:N \l_@@_graph_ims_step_fp } |
| 2694 |
\bool_while_do:nn { |
| 2695 |
\fp_compare_p:n { |
| 2696 |
\l_@@_graph_minorsteps_int * \l_@@_graph_ims_range_fp |
| 2697 |
> \l_@@_graph_ims_threshold_fp |
| 2698 |
} |
| 2699 |
}{ |
| 2700 |
\tl_map_inline:nn {{2}{5}{10}} { |
| 2701 |
\fp_compare:nF { |
| 2702 |
\l_@@_graph_minorsteps_int * \l_@@_graph_ims_range_fp |
| 2703 |
> \l_@@_graph_ims_threshold_fp * ##1 |
| 2704 |
}{ |
| 2705 |
\int_compare:nT { |
| 2706 |
\int_mod:nn{\l_@@_graph_minorsteps_int}{##1} = 0 |
| 2707 |
}{ |
| 2708 |
\int_set:Nn |
| 2709 |
\l_@@_graph_minorsteps_int |
| 2710 |
{ \l_@@_graph_minorsteps_int / ##1 } |
| 2711 |
\tl_map_break: |
| 2712 |
} |
| 2713 |
} |
| 2714 |
} |
| 2715 |
\fp_compare:nT { |
| 2716 |
\l_@@_graph_minorsteps_int * \l_@@_graph_ims_range_fp |
| 2717 |
> \l_@@_graph_ims_threshold_fp |
| 2718 |
}{ |
| 2719 |
\tl_map_inline:nn {{3}{2}{5}{\l_@@_graph_minorsteps_int}} { |
| 2720 |
\int_compare:nT { |
| 2721 |
\int_mod:nn{\l_@@_graph_minorsteps_int}{##1} = 0 |
| 2722 |
}{ |
| 2723 |
\int_set:Nn |
| 2724 |
\l_@@_graph_minorsteps_int |
| 2725 |
{ \l_@@_graph_minorsteps_int / ##1 } |
| 2726 |
\tl_map_break: |
| 2727 |
} |
| 2728 |
} |
| 2729 |
} |
| 2730 |
} |
| 2731 |
\int_compare:nNnTF \l_@@_graph_minorsteps_int > 1 { |
| 2732 |
\use:x { \exp_not:n { |
| 2733 |
\pgfkeyssetvalue |
| 2734 |
{/tikz/data~visualization/minor~steps~between~steps} |
| 2735 |
} |
| 2736 |
{ \int_eval:n {\l_@@_graph_minorsteps_int-1} } |
| 2737 |
} |
| 2738 |
}{ |
| 2739 |
\pgfkeyssetvalue |
| 2740 |
{/tikz/data~visualization/minor~steps~between~steps} |
| 2741 |
{} |
| 2742 |
} |
| 2743 |
\tl_clear:N \l_@@_graph_maxminor_tl |
| 2744 |
} |
| 2745 |
} |
| 2746 |
}, |
| 2747 |
integer~minor~steps/.default=50, |
| 2748 |
integer~minor~steps*/.style={ |
| 2749 |
compute~step/.append = { |
| 2750 |
\tl_set_eq:NN \l_tmpa_tl \tikz@lib@dv@step |
| 2751 |
\tl_if_eq:NNF \l_tmpa_tl \relax { |
| 2752 |
\fp_compare:nT { \l_tmpa_tl < 1 } { |
| 2753 |
\tl_set:Nx \tikz@lib@dv@step {1} |
| 2754 |
} |
| 2755 |
} |
| 2756 |
}, |
| 2757 |
integer~minor~steps=#1, |
| 2758 |
}, |
| 2759 |
integer~minor~steps*/.default=50, |
| 2760 |
} |
| 2761 |
% \end{macrocode} |
| 2762 |
% |
| 2763 |
% First define a lot of variables: |
| 2764 |
% |
| 2765 |
% \begin{macrocode} |
| 2766 |
\bool_new:N \l_@@_graph_allranges_bool |
| 2767 |
|
| 2768 |
\fp_new:N \l_@@_graph_curvalue_fp |
| 2769 |
\fp_new:N \l_@@_graph_curheight_fp |
| 2770 |
\fp_new:N \l_@@_graph_prevheight_fp |
| 2771 |
\fp_new:N \l_@@_graph_maxheight_fp |
| 2772 |
\fp_new:N \l_@@_graph_minvalue_fp |
| 2773 |
\fp_new:N \l_@@_graph_maxvalue_fp |
| 2774 |
\fp_new:N \g_@@_graph_xstep_fp |
| 2775 |
\int_new:N \g_@@_graph_last_int |
| 2776 |
|
| 2777 |
\tl_new:N \l_@@_graph_tikzdata_tl |
| 2778 |
\tl_new:N \l_@@_graph_tikzinfo_tl |
| 2779 |
\clist_new:N \l_@@_graph_tikzincludex_clist |
| 2780 |
\clist_new:N \l_@@_graph_tikzincludey_clist |
| 2781 |
\tl_new:N \l_@@_graph_tikzpicture_tl |
| 2782 |
% \end{macrocode} |
| 2783 |
% |
| 2784 |
% No scale for counts, divide by total for freqs |
| 2785 |
% |
| 2786 |
% \begin{macrocode} |
| 2787 |
\fp_new:N \l_@@_graph_scale_fp |
| 2788 |
\fp_new:N \l_@@_graph_counts_scale_fp |
| 2789 |
\fp_new:N \l_@@_graph_frequencies_scale_fp |
| 2790 |
\fp_set:Nn \l_@@_graph_counts_scale_fp { 1 } |
| 2791 |
|
| 2792 |
|
| 2793 |
\NewDocumentCommand \StatsGraph { +O{} +m +O{} } { |
| 2794 |
\group_begin: |
| 2795 |
\int_gincr:N \g_@@_graph_last_int |
| 2796 |
% \end{macrocode} |
| 2797 |
% |
| 2798 |
% Read saved x step, for automatic margin and histogram y step |
| 2799 |
% |
| 2800 |
% \begin{macrocode} |
| 2801 |
\tl_set:Nx \l_tmpa_tl { |
| 2802 |
\exp_not:n { g_@@_graph_xstep_ } |
| 2803 |
\int_use:N \g_@@_graph_last_int |
| 2804 |
\exp_not:n { _tl } |
| 2805 |
} |
| 2806 |
\tl_if_exist:cTF { \l_tmpa_tl } { |
| 2807 |
\fp_gset:Nn \g_@@_graph_xstep_fp |
| 2808 |
{ \tl_use:c {\l_tmpa_tl} } |
| 2809 |
}{ |
| 2810 |
\fp_gset:Nn \g_@@_graph_xstep_fp { \c_one_int } |
| 2811 |
} |
| 2812 |
% \end{macrocode} |
| 2813 |
% |
| 2814 |
% Handle optional settings |
| 2815 |
% |
| 2816 |
% \begin{macrocode} |
| 2817 |
\@@_setup:nn { graph } { #1, #3 } |
| 2818 |
% \end{macrocode} |
| 2819 |
% |
| 2820 |
% Get the data inline or from a variable |
| 2821 |
% |
| 2822 |
% \begin{macrocode} |
| 2823 |
\tl_if_single:nTF { #2 } { |
| 2824 |
% \end{macrocode} |
| 2825 |
% |
| 2826 |
% Generate meaningful error by using the non-existent variable. |
| 2827 |
% |
| 2828 |
% \begin{macrocode} |
| 2829 |
\cs_if_exist:NF #2 { #2 } |
| 2830 |
\tl_set_eq:NN \l_@@_data_tl #2 |
| 2831 |
}{ |
| 2832 |
\tl_set:Nn \l_@@_data_tl { #2 } |
| 2833 |
} |
| 2834 |
% \end{macrocode} |
| 2835 |
% |
| 2836 |
% Zero the maximum height in the graph, and setup min and max values. |
| 2837 |
% |
| 2838 |
% \begin{macrocode} |
| 2839 |
\fp_zero:N \l_@@_graph_maxheight_fp |
| 2840 |
\fp_set:Nn \l_@@_graph_minvalue_fp {inf} |
| 2841 |
\fp_set:Nn \l_@@_graph_maxvalue_fp {-inf} |
| 2842 |
% \end{macrocode} |
| 2843 |
% |
| 2844 |
% The following loop does 2 things: |
| 2845 |
% \begin{itemize} |
| 2846 |
% \item Counting the number of ranges and the total population count |
| 2847 |
% \item Detecting whether the ranges are intervals or single numbers |
| 2848 |
% \end{itemize} |
| 2849 |
% |
| 2850 |
% \begin{macrocode} |
| 2851 |
\fp_zero:N \l_@@_total_fp |
| 2852 |
\int_zero:N \l_@@_nbvals_int |
| 2853 |
\bool_set_true:N \l_@@_graph_allranges_bool |
| 2854 |
\keyval_parse:NNV |
| 2855 |
\@@_graph_prepare:n |
| 2856 |
\@@_graph_prepare:nn |
| 2857 |
\l_@@_data_tl |
| 2858 |
% \end{macrocode} |
| 2859 |
% |
| 2860 |
% The remainder is different whether we do histogram, cumulative, or comb |
| 2861 |
% |
| 2862 |
% \begin{macrocode} |
| 2863 |
\tl_clear:N \l_@@_graph_tikzdata_tl |
| 2864 |
\tl_clear:N \l_@@_graph_tikzinfo_tl |
| 2865 |
\int_zero:N \l_@@_currange_int |
| 2866 |
\bool_if:NTF \l_@@_graph_allranges_bool { |
| 2867 |
\bool_if:NTF \l_@@_graph_cumulative_bool { |
| 2868 |
% \end{macrocode} |
| 2869 |
% |
| 2870 |
% We draw a cumulative distribution function |
| 2871 |
% |
| 2872 |
% \begin{macrocode} |
| 2873 |
\@@_graph_dopicture_cumulative: |
| 2874 |
}{ |
| 2875 |
% \end{macrocode} |
| 2876 |
% |
| 2877 |
% We draw an histogram |
| 2878 |
% |
| 2879 |
% \begin{macrocode} |
| 2880 |
\@@_graph_dopicture_hist: |
| 2881 |
} |
| 2882 |
}{ |
| 2883 |
% \end{macrocode} |
| 2884 |
% |
| 2885 |
% We draw a comb graph |
| 2886 |
% |
| 2887 |
% \begin{macrocode} |
| 2888 |
\@@_graph_dopicture_comb: |
| 2889 |
} |
| 2890 |
% \end{macrocode} |
| 2891 |
% |
| 2892 |
% Write xstep info to aux file |
| 2893 |
% |
| 2894 |
% \begin{macrocode} |
| 2895 |
\iow_now:Nx \@auxout { |
| 2896 |
\exp_not:n { |
| 2897 |
\ExplSyntaxOn |
| 2898 |
\tl_gset:cn |
| 2899 |
} |
| 2900 |
{ |
| 2901 |
\exp_not:n {g_@@_graph_xstep_} |
| 2902 |
\int_use:N \g_@@_graph_last_int |
| 2903 |
\exp_not:n {_tl} |
| 2904 |
} |
| 2905 |
{ |
| 2906 |
\fp_to_decimal:N \g_@@_graph_xstep_fp |
| 2907 |
} |
| 2908 |
\exp_not:n { |
| 2909 |
\ExplSyntaxOff |
| 2910 |
} |
| 2911 |
} |
| 2912 |
\group_end: |
| 2913 |
} |
| 2914 |
% \end{macrocode} |
| 2915 |
% |
| 2916 |
% First pass |
| 2917 |
% |
| 2918 |
% \begin{macrocode} |
| 2919 |
\cs_new_protected_nopar:Nn \@@_graph_prepare:n { |
| 2920 |
\@@_graph_prepare:nn { #1 } { 1 } |
| 2921 |
} |
| 2922 |
\cs_new_protected_nopar:Nn \@@_graph_prepare:nn { |
| 2923 |
\int_incr:N \l_@@_nbvals_int |
| 2924 |
\fp_add:Nn \l_@@_total_fp { #2 } |
| 2925 |
\exp_args:Nx \tl_if_eq:nnF { \tl_head:n {#1} }{ \IN } { |
| 2926 |
\bool_set_false:N \l_@@_graph_allranges_bool |
| 2927 |
} |
| 2928 |
} |
| 2929 |
% \end{macrocode} |
| 2930 |
% |
| 2931 |
% Shared utility functions |
| 2932 |
% |
| 2933 |
% \begin{macrocode} |
| 2934 |
\cs_new_protected_nopar:Nn \@@_graph_addpoint:nnn { |
| 2935 |
\tl_put_right:Nx \l_@@_graph_tikzdata_tl { |
| 2936 |
\exp_not:N \pgfkeys { |
| 2937 |
\exp_not:n { /data~point/name = #1 } |
| 2938 |
\int_use:N \l_@@_currange_int |
| 2939 |
\exp_not:n { ,/data~point/x = } \fp_eval:n { #2 } |
| 2940 |
\exp_not:n { ,/data~point/y = } \fp_eval:n { #3 } |
| 2941 |
} |
| 2942 |
\exp_not:n { \pgfdatapoint } |
| 2943 |
} |
| 2944 |
} |
| 2945 |
\cs_new_protected_nopar:Nn \@@_graph_outlier: { |
| 2946 |
\tl_put_right:Nn \l_@@_graph_tikzdata_tl { |
| 2947 |
\pgfkeys{/data~point/outlier = true} |
| 2948 |
\pgfdatapoint |
| 2949 |
\pgfkeys{/data~point/outlier = } |
| 2950 |
} |
| 2951 |
} |
| 2952 |
\cs_new_protected_nopar:Nn \@@_graph_setup:n { |
| 2953 |
\fp_set_eq:Nc \l_@@_graph_hmargin_tl {l_@@_graph_#1_hmargin_tl} |
| 2954 |
\tl_set_eq:Nc \l_@@_graph_unit_tl { l_@@_graph_#1_unit_tl } |
| 2955 |
\tl_set_eq:Nc \l_@@_graph_vmargin_tl |
| 2956 |
{l_@@_graph_#1_ \l_@@_graph_unit_tl _vmargin_tl} |
| 2957 |
\tl_set_eq:Nc |
| 2958 |
\l_@@_graph_options_yaxis_tl |
| 2959 |
{l_@@_graph_options_#1_ \l_@@_graph_unit_tl axis_tl} |
| 2960 |
\cs_set_eq:Nc |
| 2961 |
\@@_graph_y_format:n |
| 2962 |
{@@_graph_#1_ \l_@@_graph_unit_tl _format:n} |
| 2963 |
\cs_set_eq:Nc |
| 2964 |
\@@_graph_values_format:n |
| 2965 |
{@@_graph_#1_values_format:n} |
| 2966 |
\fp_set_eq:NN |
| 2967 |
\l_@@_graph_frequencies_scale_fp |
| 2968 |
\l_@@_total_fp |
| 2969 |
\fp_set_eq:Nc |
| 2970 |
\l_@@_graph_scale_fp |
| 2971 |
{l_@@_graph_ \l_@@_graph_unit_tl _scale_fp} |
| 2972 |
} |
| 2973 |
\cs_new_protected_nopar:Nn \@@_graph_update_minmaxval:NN { |
| 2974 |
\fp_set:Nn \l_@@_graph_minvalue_fp { |
| 2975 |
min( \l_@@_graph_minvalue_fp, #1 ) |
| 2976 |
} |
| 2977 |
\fp_set:Nn \l_@@_graph_maxvalue_fp { |
| 2978 |
max( \l_@@_graph_maxvalue_fp, #2 ) |
| 2979 |
} |
| 2980 |
} |
| 2981 |
\cs_new_protected_nopar:Nn \@@_graph_update_maxheight: { |
| 2982 |
\fp_set:Nn \l_@@_graph_maxheight_fp { |
| 2983 |
max( \l_@@_graph_maxheight_fp , \l_@@_graph_curheight_fp ) |
| 2984 |
} |
| 2985 |
} |
| 2986 |
\cs_new_protected_nopar:Nn \@@_graph_handle_hmargin: { |
| 2987 |
\group_begin: |
| 2988 |
\tl_set:Nx \min { \fp_to_decimal:N \l_@@_graph_minvalue_fp } |
| 2989 |
\tl_set:Nx \max { \fp_to_decimal:N \l_@@_graph_maxvalue_fp } |
| 2990 |
\tl_set:Nx \range { |
| 2991 |
\fp_eval:n { \l_@@_graph_maxvalue_fp - \l_@@_graph_minvalue_fp } |
| 2992 |
} |
| 2993 |
\tl_set:Nx \xstep { \fp_to_decimal:N \g_@@_graph_xstep_fp } |
| 2994 |
\exp_args:NNV \fp_gset:Nn \g_tmpa_fp \l_@@_graph_hmargin_tl |
| 2995 |
\group_end: |
| 2996 |
\clist_put_right:Nx \l_@@_graph_tikzincludex_clist { |
| 2997 |
\fp_eval:n { \l_@@_graph_minvalue_fp - \g_tmpa_fp } |
| 2998 |
} |
| 2999 |
\clist_put_right:Nx \l_@@_graph_tikzincludex_clist { |
| 3000 |
\fp_eval:n { \l_@@_graph_maxvalue_fp + \g_tmpa_fp } |
| 3001 |
} |
| 3002 |
} |
| 3003 |
\cs_new_protected_nopar:Nn \@@_graph_handle_vmargin: { |
| 3004 |
\group_begin: |
| 3005 |
\tl_set:Nn \min { 0 } |
| 3006 |
\tl_set:Nx \max { \fp_to_decimal:N \l_@@_graph_maxheight_fp } |
| 3007 |
\tl_set_eq:NN \range \max |
| 3008 |
\exp_args:NNV \fp_gset:Nn \g_tmpa_fp \l_@@_graph_vmargin_tl |
| 3009 |
\group_end: |
| 3010 |
\clist_put_right:Nx \l_@@_graph_tikzincludey_clist { |
| 3011 |
\fp_eval:n { \l_@@_graph_maxheight_fp + \g_tmpa_fp } |
| 3012 |
} |
| 3013 |
} |
| 3014 |
% \end{macrocode} |
| 3015 |
% |
| 3016 |
% Second pass, histogram |
| 3017 |
% |
| 3018 |
% \begin{macrocode} |
| 3019 |
\cs_new_protected_nopar:Nn \@@_graph_dopicture_hist: { |
| 3020 |
\@@_graph_setup:n {histogram} |
| 3021 |
% \end{macrocode} |
| 3022 |
% |
| 3023 |
% Loop through the list again to fill tikz data and labels |
| 3024 |
% |
| 3025 |
% \begin{macrocode} |
| 3026 |
\keyval_parse:NNV |
| 3027 |
\@@_graph_make_hist:n |
| 3028 |
\@@_graph_make_hist:nn |
| 3029 |
\l_@@_data_tl |
| 3030 |
% \end{macrocode} |
| 3031 |
% |
| 3032 |
% Maybe add a legend |
| 3033 |
% |
| 3034 |
% \begin{macrocode} |
| 3035 |
\tl_if_empty:NF \l_@@_graph_legend_x_tl { |
| 3036 |
\group_begin: |
| 3037 |
\tl_set:Nx \min { \fp_to_decimal:N \l_@@_graph_minvalue_fp } |
| 3038 |
\tl_set:Nx \max { \fp_to_decimal:N \l_@@_graph_maxvalue_fp } |
| 3039 |
\tl_set:Nx \range { |
| 3040 |
\fp_eval:n { \l_@@_graph_maxvalue_fp - \l_@@_graph_minvalue_fp } |
| 3041 |
} |
| 3042 |
\tl_set:Nx \xstep { \fp_to_decimal:N \g_@@_graph_xstep_fp } |
| 3043 |
\exp_args:NNV \fp_gset:Nn \g_tmpa_fp \l_@@_graph_legend_x_tl |
| 3044 |
\exp_args:NNV \fp_gset:Nn \g_tmpb_fp \l_@@_graph_legend_w_tl |
| 3045 |
\group_end: |
| 3046 |
\tl_set:Nx \l_@@_graph_legend_x_tl { \fp_to_decimal:N \g_tmpa_fp } |
| 3047 |
\tl_set:Nx \l_@@_graph_legend_w_tl { \fp_to_decimal:N \g_tmpb_fp } |
| 3048 |
|
| 3049 |
\group_begin: |
| 3050 |
\tl_set:Nn \min { 0 } |
| 3051 |
\tl_set:Nx \max { \fp_to_decimal:N \l_@@_graph_maxheight_fp } |
| 3052 |
\tl_set_eq:NN \range \max |
| 3053 |
\tl_set:Nx \xstep { \fp_to_decimal:N \g_@@_graph_xstep_fp } |
| 3054 |
\tl_set_eq:NN \width \l_@@_graph_legend_w_tl |
| 3055 |
\tl_set:Nx \total { \fp_to_decimal:N \l_@@_total_fp } |
| 3056 |
\exp_args:NNV \fp_gset:Nn \g_tmpb_fp \l_@@_graph_legend_h_tl |
| 3057 |
\tl_set:Nx \height { \fp_to_decimal:N \g_tmpb_fp } |
| 3058 |
\exp_args:NNV \fp_gset:Nn \g_tmpa_fp \l_@@_graph_legend_y_tl |
| 3059 |
\group_end: |
| 3060 |
|
| 3061 |
\tl_put_right:Nx \l_@@_graph_tikzinfo_tl { |
| 3062 |
\exp_not:n { \path (visualization~cs } |
| 3063 |
\token_to_str:N : \exp_not:n { x= } |
| 3064 |
\exp_not:V \l_@@_graph_legend_x_tl |
| 3065 |
\exp_not:n { ,y= } |
| 3066 |
\fp_to_decimal:N \g_tmpa_fp |
| 3067 |
\exp_not:n { ) coordinate (LSW) (visualization~cs } |
| 3068 |
\token_to_str:N : \exp_not:n { x= } |
| 3069 |
\fp_eval:n { |
| 3070 |
\l_@@_graph_legend_x_tl + |
| 3071 |
\l_@@_graph_legend_w_tl |
| 3072 |
} |
| 3073 |
\exp_not:n { ,y= } |
| 3074 |
\fp_eval:n { \g_tmpa_fp + \g_tmpb_fp } |
| 3075 |
\exp_not:n { ) coordinate (LNE); |
| 3076 |
\node[ fit=(LSW)~(LNE), draw, inner~sep=0pt, |
| 3077 |
} |
| 3078 |
\exp_not:V \l_@@_graph_options_histogram_tl |
| 3079 |
\exp_not:N , |
| 3080 |
\exp_not:V \l_@@_graph_options_legend_tl |
| 3081 |
\exp_not:n { ] {}; } |
| 3082 |
} |
| 3083 |
} |
| 3084 |
% \end{macrocode} |
| 3085 |
% |
| 3086 |
% Create the picture itself |
| 3087 |
% |
| 3088 |
% \begin{macrocode} |
| 3089 |
\@@_graph_handle_hmargin: |
| 3090 |
\@@_graph_handle_vmargin: |
| 3091 |
\tl_set:Nx \l_@@_graph_tikzpicture_tl { |
| 3092 |
\exp_not:n { \begin{tikzpicture}[ } |
| 3093 |
\exp_not:V \l_@@_graph_options_pic_tl |
| 3094 |
\exp_not:n { ] \datavisualization |
| 3095 |
[scientific~axes = } { |
| 3096 |
\exp_not:V |
| 3097 |
\l_@@_graph_options_system_tl |
| 3098 |
} |
| 3099 |
\exp_not:n { , x~axis = } { |
| 3100 |
\exp_not:n { include~value/.list = } { |
| 3101 |
\exp_not:V \l_@@_graph_tikzincludex_clist |
| 3102 |
} |
| 3103 |
\exp_not:n { , ticks = { tick~typesetter/.code = { |
| 3104 |
$\@@_graph_values_format:n { \fp_eval:n{####1} }$ }}, } |
| 3105 |
\exp_not:V |
| 3106 |
\l_@@_graph_options_histogram_xaxis_tl |
| 3107 |
\exp_not:n { , } |
| 3108 |
\exp_not:V |
| 3109 |
\c_@@_graph_savexstep_tl |
| 3110 |
} |
| 3111 |
\exp_not:n { , y~axis = } { |
| 3112 |
\exp_not:n { include~value/.list = } { |
| 3113 |
\exp_not:V \l_@@_graph_tikzincludey_clist |
| 3114 |
} |
| 3115 |
\exp_not:n { , } |
| 3116 |
\exp_not:V |
| 3117 |
\l_@@_graph_options_yaxis_tl |
| 3118 |
} |
| 3119 |
\exp_not:n { , visualize~as~line = histogram, |
| 3120 |
histogram = } { |
| 3121 |
\exp_not:n { polygon, style = } { |
| 3122 |
\exp_not:V \l_@@_graph_options_histogram_tl |
| 3123 |
} } |
| 3124 |
\exp_not:n { ] data [set = histogram, format = TeX~code] } { |
| 3125 |
\exp_not:V \l_@@_graph_tikzdata_tl |
| 3126 |
} |
| 3127 |
\exp_not:n { info' } { |
| 3128 |
\exp_not:V \l_@@_graph_userpreinfo_tl |
| 3129 |
} |
| 3130 |
\exp_not:n { info } { |
| 3131 |
\exp_not:V \l_@@_graph_tikzinfo_tl |
| 3132 |
\exp_not:V \l_@@_graph_userpostinfo_tl |
| 3133 |
} |
| 3134 |
\exp_not:n { ; \end{tikzpicture} } |
| 3135 |
} |
| 3136 |
\tl_use:N \l_@@_graph_tikzpicture_tl |
| 3137 |
} |
| 3138 |
\cs_new_protected_nopar:Nn \@@_graph_make_hist:n { |
| 3139 |
\@@_graph_make_hist:nn { #1 } { 1 } |
| 3140 |
} |
| 3141 |
\cs_new_protected_nopar:Nn \@@_graph_make_hist:nn { |
| 3142 |
\int_incr:N \l_@@_currange_int |
| 3143 |
% \end{macrocode} |
| 3144 |
% |
| 3145 |
% Extract interval data |
| 3146 |
% |
| 3147 |
% \begin{macrocode} |
| 3148 |
\@@_parse_range:w #1 \q_stop |
| 3149 |
% \end{macrocode} |
| 3150 |
% |
| 3151 |
% Compute rectangle height |
| 3152 |
% |
| 3153 |
% \begin{macrocode} |
| 3154 |
\fp_set:Nn \l_@@_graph_curheight_fp { |
| 3155 |
(#2) / ( \l_@@_range_max_fp - |
| 3156 |
\l_@@_range_min_fp) |
| 3157 |
} |
| 3158 |
% \end{macrocode} |
| 3159 |
% |
| 3160 |
% Add margins to axes |
| 3161 |
% |
| 3162 |
% \begin{macrocode} |
| 3163 |
\@@_graph_update_minmaxval:NN \l_@@_range_min_fp \l_@@_range_max_fp |
| 3164 |
\@@_graph_update_maxheight: |
| 3165 |
% \end{macrocode} |
| 3166 |
% |
| 3167 |
% Check if we want to show this element |
| 3168 |
% |
| 3169 |
% \begin{macrocode} |
| 3170 |
\@@_set_if_shown:N \l_tmpa_bool |
| 3171 |
% \end{macrocode} |
| 3172 |
% |
| 3173 |
% Append the rectangle to the TikZ datavisualization content |
| 3174 |
% |
| 3175 |
% \begin{macrocode} |
| 3176 |
\@@_graph_addpoint:nnn { SW } |
| 3177 |
{ \l_@@_range_min_fp } |
| 3178 |
{ 0 } |
| 3179 |
\bool_if:NF \l_tmpa_bool { |
| 3180 |
% \end{macrocode} |
| 3181 |
% |
| 3182 |
% Add an outlier point to inhibit the rectangle drawing |
| 3183 |
% |
| 3184 |
% \begin{macrocode} |
| 3185 |
\@@_graph_outlier: |
| 3186 |
} |
| 3187 |
\@@_graph_addpoint:nnn { NW } |
| 3188 |
{ \l_@@_range_min_fp } |
| 3189 |
{ \l_@@_graph_curheight_fp } |
| 3190 |
\bool_if:NF \l_tmpa_bool { \@@_graph_outlier: } |
| 3191 |
\@@_graph_addpoint:nnn { NE } |
| 3192 |
{ \l_@@_range_max_fp } |
| 3193 |
{ \l_@@_graph_curheight_fp } |
| 3194 |
\bool_if:NF \l_tmpa_bool { \@@_graph_outlier: } |
| 3195 |
\@@_graph_addpoint:nnn { SE } |
| 3196 |
{ \l_@@_range_max_fp } |
| 3197 |
{ 0 } |
| 3198 |
\bool_if:NT \l_tmpa_bool { |
| 3199 |
% \end{macrocode} |
| 3200 |
% |
| 3201 |
% Maybe append a freq or count label on middle top of the rect |
| 3202 |
% |
| 3203 |
% \begin{macrocode} |
| 3204 |
\bool_if:NT \l_@@_graph_areas_bool { |
| 3205 |
\@@_graph_addlabel:nn |
| 3206 |
\@@_graph_y_format:n |
| 3207 |
{ \fp_eval:n {#2 / \l_@@_graph_scale_fp} } |
| 3208 |
} |
| 3209 |
} |
| 3210 |
\@@_graph_outlier: |
| 3211 |
} |
| 3212 |
\cs_new_protected_nopar:Nn \@@_graph_addlabel:nn { |
| 3213 |
\tl_put_right:Nx \l_@@_graph_tikzinfo_tl { |
| 3214 |
\exp_not:n { \path (NW } |
| 3215 |
\int_use:N \l_@@_currange_int |
| 3216 |
\exp_not:n { ) -- node[ } |
| 3217 |
\exp_not:V \l_@@_graph_options_areas_tl |
| 3218 |
\exp_not:N ] { |
| 3219 |
\exp_not:n { $ #1 } { #2 } \exp_not:N $ |
| 3220 |
} \exp_not:n { (NE } |
| 3221 |
\int_use:N \l_@@_currange_int |
| 3222 |
\exp_not:n { ); } |
| 3223 |
} |
| 3224 |
} |
| 3225 |
% \end{macrocode} |
| 3226 |
% |
| 3227 |
% second pass, comb |
| 3228 |
% |
| 3229 |
% \begin{macrocode} |
| 3230 |
\cs_new_protected:Nn \@@_graph_dopicture_comb: { |
| 3231 |
\@@_graph_setup:n {comb} |
| 3232 |
% \end{macrocode} |
| 3233 |
% |
| 3234 |
% Loop through the list again to fill tikz data and labels |
| 3235 |
% |
| 3236 |
% \begin{macrocode} |
| 3237 |
\keyval_parse:NNV |
| 3238 |
\@@_graph_make_comb:n |
| 3239 |
\@@_graph_make_comb:nn |
| 3240 |
\l_@@_data_tl |
| 3241 |
% \end{macrocode} |
| 3242 |
% |
| 3243 |
% Create the picture itself |
| 3244 |
% |
| 3245 |
% \begin{macrocode} |
| 3246 |
\@@_graph_handle_hmargin: |
| 3247 |
\@@_graph_handle_vmargin: |
| 3248 |
\tl_set:Nx \l_@@_graph_tikzpicture_tl { |
| 3249 |
\exp_not:n { \begin{tikzpicture}[ } |
| 3250 |
\exp_not:V \l_@@_graph_options_pic_tl |
| 3251 |
\exp_not:n { ] \datavisualization |
| 3252 |
[scientific~axes = } { |
| 3253 |
\exp_not:V |
| 3254 |
\l_@@_graph_options_system_tl |
| 3255 |
} |
| 3256 |
\exp_not:n { , x~axis = } { |
| 3257 |
\exp_not:n { include~value/.list = } { |
| 3258 |
\exp_not:V \l_@@_graph_tikzincludex_clist |
| 3259 |
} |
| 3260 |
\exp_not:n { , ticks = { tick~typesetter/.code = { |
| 3261 |
$\@@_graph_values_format:n { \fp_eval:n{####1} }$ }}, } |
| 3262 |
\exp_not:V |
| 3263 |
\l_@@_graph_options_comb_xaxis_tl |
| 3264 |
\exp_not:n { , } |
| 3265 |
\exp_not:V |
| 3266 |
\c_@@_graph_savexstep_tl |
| 3267 |
} |
| 3268 |
\exp_not:n { , y~axis = } { |
| 3269 |
\exp_not:n { include~value/.list = } { |
| 3270 |
\exp_not:V \l_@@_graph_tikzincludey_clist |
| 3271 |
} |
| 3272 |
\exp_not:n { , } |
| 3273 |
\exp_not:n { , ticks = { tick~typesetter/.code = { |
| 3274 |
$\@@_graph_y_format:n { \fp_eval:n{####1} }$ }}, } |
| 3275 |
\exp_not:V |
| 3276 |
\l_@@_graph_options_yaxis_tl |
| 3277 |
} |
| 3278 |
\exp_not:n { , visualize~as~line = bar~graph, |
| 3279 |
bar~graph = } { |
| 3280 |
\exp_not:n { style = } { |
| 3281 |
\exp_not:V \l_@@_graph_options_comb_tl |
| 3282 |
} } |
| 3283 |
\exp_not:n { ] data [set = bar~graph, format = TeX~code] } { |
| 3284 |
\exp_not:V \l_@@_graph_tikzdata_tl |
| 3285 |
} |
| 3286 |
\exp_not:n { info' } { |
| 3287 |
\exp_not:V \l_@@_graph_userpreinfo_tl |
| 3288 |
} |
| 3289 |
\exp_not:n { info } { |
| 3290 |
\exp_not:V \l_@@_graph_tikzinfo_tl |
| 3291 |
\exp_not:V \l_@@_graph_userpostinfo_tl |
| 3292 |
} |
| 3293 |
\exp_not:n { ; \end{tikzpicture} } |
| 3294 |
} |
| 3295 |
\tl_use:N \l_@@_graph_tikzpicture_tl |
| 3296 |
} |
| 3297 |
\cs_new_protected_nopar:Nn \@@_graph_make_comb:n { |
| 3298 |
\@@_graph_make_comb:nn { #1 } { 1 } |
| 3299 |
} |
| 3300 |
\cs_new_protected_nopar:Nn \@@_graph_make_comb:nn { |
| 3301 |
\int_incr:N \l_@@_currange_int |
| 3302 |
% \end{macrocode} |
| 3303 |
% |
| 3304 |
% Set value |
| 3305 |
% |
| 3306 |
% \begin{macrocode} |
| 3307 |
\fp_set:Nn \l_@@_graph_curvalue_fp { |
| 3308 |
#1 |
| 3309 |
} |
| 3310 |
% \end{macrocode} |
| 3311 |
% |
| 3312 |
% Compute height |
| 3313 |
% |
| 3314 |
% \begin{macrocode} |
| 3315 |
\fp_set:Nn \l_@@_graph_curheight_fp { |
| 3316 |
(#2) / \l_@@_graph_scale_fp |
| 3317 |
} |
| 3318 |
% \end{macrocode} |
| 3319 |
% |
| 3320 |
% Add margins to axes |
| 3321 |
% |
| 3322 |
% \begin{macrocode} |
| 3323 |
\@@_graph_update_minmaxval:NN |
| 3324 |
\l_@@_graph_curvalue_fp \l_@@_graph_curvalue_fp |
| 3325 |
\@@_graph_update_maxheight: |
| 3326 |
% \end{macrocode} |
| 3327 |
% |
| 3328 |
% Check if we want to show this element |
| 3329 |
% |
| 3330 |
% \begin{macrocode} |
| 3331 |
\@@_set_if_shown:N \l_tmpa_bool |
| 3332 |
% \end{macrocode} |
| 3333 |
% |
| 3334 |
% Append the bar to the TikZ datavisualization content |
| 3335 |
% |
| 3336 |
% \begin{macrocode} |
| 3337 |
\@@_graph_addpoint:nnn { S } |
| 3338 |
{ \l_@@_graph_curvalue_fp } |
| 3339 |
{ 0 } |
| 3340 |
\bool_if:NF \l_tmpa_bool { |
| 3341 |
% \end{macrocode} |
| 3342 |
% |
| 3343 |
% add an outlier to inhibit the bar drawing |
| 3344 |
% |
| 3345 |
% \begin{macrocode} |
| 3346 |
\@@_graph_outlier: |
| 3347 |
} |
| 3348 |
\@@_graph_addpoint:nnn { N } |
| 3349 |
{ \l_@@_graph_curvalue_fp } |
| 3350 |
{ \l_@@_graph_curheight_fp } |
| 3351 |
\@@_graph_outlier: |
| 3352 |
} |
| 3353 |
% \end{macrocode} |
| 3354 |
% |
| 3355 |
% second pass, cumulative |
| 3356 |
% |
| 3357 |
% \begin{macrocode} |
| 3358 |
\cs_new_protected_nopar:Nn \@@_graph_dopicture_cumulative: { |
| 3359 |
\@@_graph_setup:n {cumulative} |
| 3360 |
% \end{macrocode} |
| 3361 |
% |
| 3362 |
% Increasing or decreasing starting point |
| 3363 |
% |
| 3364 |
% \begin{macrocode} |
| 3365 |
\bool_if:NTF \l_@@_graph_decreasing_bool { |
| 3366 |
\fp_set_eq:NN \l_@@_curtotal_fp |
| 3367 |
\l_@@_total_fp |
| 3368 |
}{ |
| 3369 |
\fp_zero:N \l_@@_curtotal_fp |
| 3370 |
} |
| 3371 |
\fp_set:Nn \l_@@_graph_curheight_fp { |
| 3372 |
\l_@@_curtotal_fp |
| 3373 |
/ \l_@@_graph_scale_fp |
| 3374 |
} |
| 3375 |
\@@_graph_update_maxheight: |
| 3376 |
% \end{macrocode} |
| 3377 |
% |
| 3378 |
% Loop through the list again to fill tikz data and labels |
| 3379 |
% |
| 3380 |
% \begin{macrocode} |
| 3381 |
\keyval_parse:NNV |
| 3382 |
\@@_graph_make_cumulative:n |
| 3383 |
\@@_graph_make_cumulative:nn |
| 3384 |
\l_@@_data_tl |
| 3385 |
% \end{macrocode} |
| 3386 |
% |
| 3387 |
% After the last point we should be piecewise constant, which is the $N+1$-th |
| 3388 |
% item for |showonly| purposes. We call \cs{@@_graph_handle_hmargin:} even if we |
| 3389 |
% will add actual data in the margin, because that method computes the correct |
| 3390 |
% value for the margin from the options. |
| 3391 |
% |
| 3392 |
% \begin{macrocode} |
| 3393 |
\@@_graph_handle_hmargin: |
| 3394 |
\int_incr:N \l_@@_currange_int |
| 3395 |
\@@_set_if_shown:N \l_tmpa_bool |
| 3396 |
\bool_if:NF \l_tmpa_bool { \@@_graph_outlier: } |
| 3397 |
\@@_graph_addpoint:nnn { E } |
| 3398 |
{ \l_@@_graph_maxvalue_fp + \g_tmpa_fp } |
| 3399 |
{ \l_@@_graph_curheight_fp } |
| 3400 |
% \end{macrocode} |
| 3401 |
% |
| 3402 |
% Before the first point we should be piecewise constant. We stash the TikZ data |
| 3403 |
% away to prepend the first point and maybe an outlier if the segment should be |
| 3404 |
% hidden, then append the stashed data. The initial segment is numbered~$0$. |
| 3405 |
% |
| 3406 |
% \begin{macrocode} |
| 3407 |
\tl_set_eq:NN \l_tmpa_tl \l_@@_graph_tikzdata_tl |
| 3408 |
\tl_clear:N \l_@@_graph_tikzdata_tl |
| 3409 |
\int_zero:N \l_@@_currange_int |
| 3410 |
\@@_graph_addpoint:nnn { B } |
| 3411 |
{ \l_@@_graph_minvalue_fp - \g_tmpa_fp } |
| 3412 |
{ \l_@@_graph_maxheight_fp - \l_@@_graph_curheight_fp } |
| 3413 |
\@@_set_if_shown:N \l_tmpa_bool |
| 3414 |
\bool_if:NF \l_tmpa_bool { \@@_graph_outlier: } |
| 3415 |
\tl_put_right:NV \l_@@_graph_tikzdata_tl \l_tmpa_tl |
| 3416 |
% \end{macrocode} |
| 3417 |
% |
| 3418 |
% Create the picture itself |
| 3419 |
% |
| 3420 |
% \begin{macrocode} |
| 3421 |
\@@_graph_handle_vmargin: |
| 3422 |
\tl_set:Nx \l_@@_graph_tikzpicture_tl { |
| 3423 |
\exp_not:n { \begin{tikzpicture}[ } |
| 3424 |
\exp_not:V \l_@@_graph_options_pic_tl |
| 3425 |
\exp_not:n { ] \datavisualization |
| 3426 |
[scientific~axes = } { |
| 3427 |
\exp_not:V |
| 3428 |
\l_@@_graph_options_system_tl |
| 3429 |
} |
| 3430 |
\exp_not:n { , x~axis = } { |
| 3431 |
\exp_not:n { include~value/.list = } { |
| 3432 |
\exp_not:V \l_@@_graph_tikzincludex_clist |
| 3433 |
} |
| 3434 |
\exp_not:n { , ticks = { tick~typesetter/.code = { |
| 3435 |
$\@@_graph_values_format:n { \fp_eval:n{####1} }$ }}, } |
| 3436 |
\exp_not:V |
| 3437 |
\l_@@_graph_options_cumulative_xaxis_tl |
| 3438 |
\exp_not:n { , } |
| 3439 |
\exp_not:V |
| 3440 |
\c_@@_graph_savexstep_tl |
| 3441 |
} |
| 3442 |
\exp_not:n { , y~axis = } { |
| 3443 |
\exp_not:n { include~value/.list = } { |
| 3444 |
\exp_not:V \l_@@_graph_tikzincludey_clist |
| 3445 |
} |
| 3446 |
\exp_not:n { , } |
| 3447 |
\exp_not:n { , ticks = { tick~typesetter/.code = { |
| 3448 |
$\@@_graph_y_format:n { \fp_eval:n{####1} }$ }}, } |
| 3449 |
\exp_not:V |
| 3450 |
\l_@@_graph_options_yaxis_tl |
| 3451 |
} |
| 3452 |
\exp_not:n { , visualize~as~line = cumulative, |
| 3453 |
cumulative = } { |
| 3454 |
\exp_not:n { style = } { |
| 3455 |
\exp_not:V \l_@@_graph_options_cumulative_tl |
| 3456 |
} } |
| 3457 |
\exp_not:n { ] data [set = cumulative, format = TeX~code] } { |
| 3458 |
\exp_not:V \l_@@_graph_tikzdata_tl |
| 3459 |
} |
| 3460 |
\exp_not:n { info' } { |
| 3461 |
\exp_not:V \l_@@_graph_userpreinfo_tl |
| 3462 |
} |
| 3463 |
\exp_not:n { info } { |
| 3464 |
\exp_not:V \l_@@_graph_tikzinfo_tl |
| 3465 |
\exp_not:V \l_@@_graph_userpostinfo_tl |
| 3466 |
} |
| 3467 |
\exp_not:n { ; \end{tikzpicture} } |
| 3468 |
} |
| 3469 |
\tl_use:N \l_@@_graph_tikzpicture_tl |
| 3470 |
} |
| 3471 |
\cs_new_protected_nopar:Nn \@@_graph_make_cumulative:n { |
| 3472 |
\@@_graph_make_hist:nn { #1 } { 1 } |
| 3473 |
} |
| 3474 |
\cs_new_protected_nopar:Nn \@@_graph_make_cumulative:nn { |
| 3475 |
% \end{macrocode} |
| 3476 |
% |
| 3477 |
% Extract interval data |
| 3478 |
% |
| 3479 |
% \begin{macrocode} |
| 3480 |
\@@_parse_range:w #1 \q_stop |
| 3481 |
% \end{macrocode} |
| 3482 |
% |
| 3483 |
% Compute running total and new height |
| 3484 |
% |
| 3485 |
% \begin{macrocode} |
| 3486 |
\fp_set_eq:NN |
| 3487 |
\l_@@_graph_prevheight_fp |
| 3488 |
\l_@@_graph_curheight_fp |
| 3489 |
\bool_if:NTF \l_@@_graph_decreasing_bool { |
| 3490 |
\fp_sub:Nn \l_@@_curtotal_fp { #2 } |
| 3491 |
}{ |
| 3492 |
\fp_add:Nn \l_@@_curtotal_fp { #2 } |
| 3493 |
} |
| 3494 |
\fp_set:Nn \l_@@_graph_curheight_fp { |
| 3495 |
\l_@@_curtotal_fp |
| 3496 |
/ \l_@@_graph_scale_fp |
| 3497 |
} |
| 3498 |
\@@_graph_update_minmaxval:NN \l_@@_range_min_fp \l_@@_range_max_fp |
| 3499 |
\@@_graph_update_maxheight: |
| 3500 |
% \end{macrocode} |
| 3501 |
% |
| 3502 |
% Add points |
| 3503 |
% |
| 3504 |
% \begin{macrocode} |
| 3505 |
\int_incr:N \l_@@_currange_int |
| 3506 |
\@@_graph_addpoint:nnn { L } |
| 3507 |
{ \l_@@_range_min_fp } |
| 3508 |
{ \l_@@_graph_prevheight_fp } |
| 3509 |
% \end{macrocode} |
| 3510 |
% |
| 3511 |
% If we don't want to show this segment, add an outlier so that the |
| 3512 |
% line is not drawn. |
| 3513 |
% |
| 3514 |
% \begin{macrocode} |
| 3515 |
\@@_set_if_shown:N \l_tmpa_bool |
| 3516 |
\bool_if:NF \l_tmpa_bool { \@@_graph_outlier: } |
| 3517 |
\@@_graph_addpoint:nnn { R } |
| 3518 |
{ \l_@@_range_max_fp } |
| 3519 |
{ \l_@@_graph_curheight_fp } |
| 3520 |
% \end{macrocode} |
| 3521 |
% |
| 3522 |
% TODO: Median and co |
| 3523 |
% |
| 3524 |
% \begin{macrocode} |
| 3525 |
} |
| 3526 |
% \end{macrocode} |
| 3527 |
% |
| 3528 |
% \subsection{Consolitate and sort values} |
| 3529 |
% |
| 3530 |
% \begin{macrocode} |
| 3531 |
\clist_new:N \l_@@_compute_data_clist |
| 3532 |
\int_new:N \l_@@_compute_count_int |
| 3533 |
|
| 3534 |
\fp_new:N \l_@@_compute_curvalue_fp |
| 3535 |
\seq_new:N \l_@@_data_seq |
| 3536 |
|
| 3537 |
\NewDocumentCommand \StatsSortData { +O{} u{=} m +O{} } { |
| 3538 |
\group_begin: |
| 3539 |
% \end{macrocode} |
| 3540 |
% |
| 3541 |
% Handle optional settings (there are none currently) |
| 3542 |
% |\@@_setup:nn { rangedata } { #1, #5 }| |
| 3543 |
% Get the data inline or from a variable |
| 3544 |
% |
| 3545 |
% \begin{macrocode} |
| 3546 |
\tl_if_single:nTF { #3 } { |
| 3547 |
% \end{macrocode} |
| 3548 |
% |
| 3549 |
% Generate meaningful error by using the non-existent variable. |
| 3550 |
% |
| 3551 |
% \begin{macrocode} |
| 3552 |
\cs_if_exist:NF #3 { #3 } |
| 3553 |
\tl_set_eq:NN \l_@@_data_tl #3 |
| 3554 |
}{ |
| 3555 |
\tl_set:Nn \l_@@_data_tl { #3 } |
| 3556 |
} |
| 3557 |
% \end{macrocode} |
| 3558 |
% |
| 3559 |
% Sort the data according to values. |
| 3560 |
% We go through sequences because \cs{clist_sort:Nn} puts braces around the |
| 3561 |
% elements which prevents \cs{keyval_parse:NNn} to detect the equal sign. |
| 3562 |
% |
| 3563 |
% \begin{macrocode} |
| 3564 |
\seq_set_from_clist:NN \l_@@_data_seq \l_@@_data_tl |
| 3565 |
\seq_sort:Nn \l_@@_data_seq { |
| 3566 |
\seq_set_split:Nnn \l_tmpa_seq {=} { ##1 } |
| 3567 |
\seq_set_split:Nnn \l_tmpb_seq {=} { ##2 } |
| 3568 |
\fp_compare:nNnTF |
| 3569 |
{ \seq_item:Nn \l_tmpa_seq {1} } > { \seq_item:Nn \l_tmpb_seq {1} } |
| 3570 |
{ |
| 3571 |
\sort_return_swapped: |
| 3572 |
}{ |
| 3573 |
\sort_return_same: |
| 3574 |
} |
| 3575 |
} |
| 3576 |
% \end{macrocode} |
| 3577 |
% |
| 3578 |
% Append a sentinel NaN to ensure the last value is not trimmed. This value is |
| 3579 |
% particularly suitable because NaN is equal to no fp (even itself). |
| 3580 |
% |
| 3581 |
% \begin{macrocode} |
| 3582 |
\seq_put_right:Nn \l_@@_data_seq { nan = 0 } |
| 3583 |
\tl_set:Nx \l_@@_data_tl { \seq_use:Nn \l_@@_data_seq {,} } |
| 3584 |
% \end{macrocode} |
| 3585 |
% |
| 3586 |
% Build the resulting clist while grouping equal values |
| 3587 |
% |
| 3588 |
% \begin{macrocode} |
| 3589 |
\clist_clear:N \l_@@_compute_data_clist |
| 3590 |
\int_zero:N \l_@@_compute_count_int |
| 3591 |
\fp_zero:N \l_@@_compute_curvalue_fp |
| 3592 |
\keyval_parse:NNV |
| 3593 |
\@@_accumulate:n |
| 3594 |
\@@_accumulate:nn |
| 3595 |
\l_@@_data_tl |
| 3596 |
\exp_args:NNNV |
| 3597 |
\group_end: |
| 3598 |
\clist_set:Nn #2 \l_@@_compute_data_clist |
| 3599 |
} |
| 3600 |
\cs_new_protected_nopar:Nn \@@_accumulate:n { |
| 3601 |
\@@_accumulate:nn { #1 } { 1 } |
| 3602 |
} |
| 3603 |
\cs_new_protected_nopar:Nn \@@_accumulate:nn { |
| 3604 |
\fp_compare:nNnTF { #1 } = { \l_@@_compute_curvalue_fp } { |
| 3605 |
\int_add:Nn \l_@@_compute_count_int { #2 } |
| 3606 |
}{ |
| 3607 |
\int_compare:nNnT { \l_@@_compute_count_int } > { 0 } { |
| 3608 |
\clist_put_right:Nx \l_@@_compute_data_clist { |
| 3609 |
\fp_to_decimal:N \l_@@_compute_curvalue_fp |
| 3610 |
\exp_not:n { = } |
| 3611 |
\exp_not:V \l_@@_compute_count_int |
| 3612 |
} |
| 3613 |
} |
| 3614 |
\fp_set:Nn \l_@@_compute_curvalue_fp { #1 } |
| 3615 |
\int_set:Nn \l_@@_compute_count_int { #2 } |
| 3616 |
} |
| 3617 |
} |
| 3618 |
% \end{macrocode} |
| 3619 |
% |
| 3620 |
% \subsection{Count values in ranges to generate grouped counts} |
| 3621 |
% |
| 3622 |
% \begin{macrocode} |
| 3623 |
\NewDocumentCommand \StatsRangeData { +O{} u{=} m +r() +O{} } { |
| 3624 |
\group_begin: |
| 3625 |
% \end{macrocode} |
| 3626 |
% |
| 3627 |
% Handle optional settings (there are none currently) |
| 3628 |
% |\@@_setup:nn { rangedata } { #1, #5 }| |
| 3629 |
% Get the data inline or from a variable |
| 3630 |
% |
| 3631 |
% \begin{macrocode} |
| 3632 |
\tl_if_single:nTF { #3 } { |
| 3633 |
% \end{macrocode} |
| 3634 |
% |
| 3635 |
% Generate meaningful error by using the non-existent variable. |
| 3636 |
% |
| 3637 |
% \begin{macrocode} |
| 3638 |
\cs_if_exist:NF #3 { #3 } |
| 3639 |
\tl_set_eq:NN \l_@@_data_tl #3 |
| 3640 |
}{ |
| 3641 |
\tl_set:Nn \l_@@_data_tl { #3 } |
| 3642 |
} |
| 3643 |
% \end{macrocode} |
| 3644 |
% |
| 3645 |
% Loop through the ranges and count values into them |
| 3646 |
% |
| 3647 |
% \begin{macrocode} |
| 3648 |
\clist_clear:N \l_@@_compute_data_clist |
| 3649 |
\clist_map_inline:nn { #4 } { |
| 3650 |
% \end{macrocode} |
| 3651 |
% |
| 3652 |
% If not a range, bail out |
| 3653 |
% |
| 3654 |
% \begin{macrocode} |
| 3655 |
\exp_args:Nx \tl_if_eq:nnF { \tl_head:n {##1} }{ \IN } { |
| 3656 |
% \end{macrocode} |
| 3657 |
% |
| 3658 |
% TODO: error message |
| 3659 |
% |
| 3660 |
% \begin{macrocode} |
| 3661 |
\clist_map_break: |
| 3662 |
} |
| 3663 |
% \end{macrocode} |
| 3664 |
% |
| 3665 |
% Extract interval data |
| 3666 |
% |
| 3667 |
% \begin{macrocode} |
| 3668 |
\@@_parse_range_full:w ##1 \q_stop |
| 3669 |
% \end{macrocode} |
| 3670 |
% |
| 3671 |
% Loop through the point data and count matching values |
| 3672 |
% |
| 3673 |
% \begin{macrocode} |
| 3674 |
\int_zero:N \l_@@_compute_count_int |
| 3675 |
\keyval_parse:NNV |
| 3676 |
\@@_range_count:n |
| 3677 |
\@@_range_count:nn |
| 3678 |
\l_@@_data_tl |
| 3679 |
\clist_put_right:Nx \l_@@_compute_data_clist { |
| 3680 |
\exp_not:n { ##1 = } |
| 3681 |
\exp_not:V \l_@@_compute_count_int |
| 3682 |
} |
| 3683 |
} |
| 3684 |
\exp_args:NNNV |
| 3685 |
\group_end: |
| 3686 |
\clist_set:Nn #2 \l_@@_compute_data_clist |
| 3687 |
} |
| 3688 |
\cs_new_protected_nopar:Nn \@@_range_count:n { |
| 3689 |
\@@_range_count:nn { #1 } { 1 } |
| 3690 |
} |
| 3691 |
\cs_new_protected_nopar:Nn \@@_range_count:nn { |
| 3692 |
\@@_if_in_range:nT { #1 } { |
| 3693 |
\int_add:Nn \l_@@_compute_count_int { #2 } |
| 3694 |
} |
| 3695 |
} |
| 3696 |
%</package> |
| 3697 |
% \end{macrocode} |
| 3698 |
% |
| 3699 |
% \end{implementation} |