summaryrefslogtreecommitdiff
path: root/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.tex
blob: fadc0a0b71045413ac132703f3690bc231a9ac0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
% LTeX: language=en

\documentclass[a4paper,english]{article}

\usepackage{xcharter-otf}
\usepackage[left=4cm]{geometry}
\usepackage{xspace}
\usepackage[svgnames]{xcolor}
\usepackage{multicol}
\usepackage{hologo}
\usepackage{listings}
\usepackage{showexpl} % examples
\usepackage{mflogo}
\usepackage{babel}
\usepackage{tikz}
\usepackage{url}
\usepackage{tikz}
\usepackage{luamplib}
\usepackage{siunitx}
\usepackage{accsupp}
\usepackage{pdflscape}
\usepackage{fancyvrb,xparse,xargs}
\usepackage[colorlinks]{hyperref}
\setmonofont{FiraCode-Regular}[
BoldFont=FiraCode-Bold,
Contextuals=Alternate, % Activate the calt feature
Scale=MatchLowercase
]
\usepackage{biblatex}
\usepackage{imakeidx}
\makeindex[title=Index, columns=2]
\usepackage[verbatim]{lstfiracode} % Activate ligatures in verbatim
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings,breakable}
\addbibresource{ctan.bib}
\newcommand\package[1]{\href{https://ctan.org/pkg/#1}{#1}}
\newcommand{\ctan}{\textsc{ctan}}
\newtcolorbox{colourband}[1][]{%
arc=0pt,outer arc=0pt,enhanced, breakable, spread sidewards, left*=0pt, right*=0pt, boxrule=0pt, colback=LightSteelBlue!10, #1}


\definecolor{hellgelb}{rgb}{1,1,0.85}
\definecolor{colKeys}{rgb}{0,0,1}
\definecolor{colIdentifier}{rgb}{0,0,0}
\definecolor{colComments}{rgb}{0.3,0.7,0.3}
\definecolor{colString}{rgb}{0,0.5,0}
\definecolor{mpcode}{rgb}{0.5,0.1,0.1}

\lstset{%
  language=metapost,%
  float=hbp,%
  basicstyle=\ttfamily, %
  identifierstyle=\color{DarkSlateGrey}, %
  keywordstyle=\color{DarkBlue}\itshape, %
  stringstyle=\color{Green}, %
  commentstyle=\color{LightSlateGrey}\itshape, %
  columns=flexible, %
  tabsize=4, %
  extendedchars=true, %
  showspaces=false, %
  showstringspaces=false, %
  numbers=left,
  numbersep=1em,
  numberstyle=\tiny\color{gray}, %
  breaklines=true, %
  breakautoindent=true,
  captionpos=b,
  xleftmargin=0em,
  sensitive=true,
  morekeywords=[10]{},
  keywordstyle=[10]\color{Salmon},
  morekeywords=[7]{draw_axis, 
  draw_grad, 
  draw_legends, 
  draw_line, 
  set_axis_color, 
  set_axis_legends, 
  set_kiviat_unit, 
  set_lattice_color, 
  set_lattice_grid,  set_line_mark, 
  set_line_mark_scale, 
  set_line_mark_type, 
  filldraw_line, 
  set_axis,},
  keywordstyle=[7]\color{FireBrick},
  morekeywords=[8]{},
  keywordstyle=[8]\color{Sienna},
  morekeywords=[9]{},
  keywordstyle=[9]\color{Olive}
}
\lstset{explpreset={pos=t,wide=false,rframe={},preset=\centering}}
\lstdefinestyle{syntax}{backgroundcolor=\color{blue!15},numbers=none,xleftmargin=0pt,xrightmargin=0pt,
  frame=single}
\lstdefinestyle{code}{backgroundcolor=\color{red!15},%numbers=left,
  xleftmargin=0pt,xrightmargin=0pt,
  frame=single}

\newtcblisting{mpcode}{
  arc=0pt,outer arc=0pt,
  colback=mpcode!3,
  breakable,
  boxsep=0pt,left=2pt,right=2pt,top=0pt,bottom=0pt, bottomtitle =
  3pt, toptitle=3pt,
  boxrule=0pt,bottomrule=0.pt,toprule=0.pt, toprule at break =
  0pt, bottomrule at break = 0pt,
  listing only,boxsep=0pt,listing
  options={breaklines}
}


\newtcblisting{commandshell}{colback=black,colupper=white,colframe=black,
  arc=0pt,
  listing only,boxsep=0pt,listing
  options={style=tcblatex,language=sh},
  every listing line={\BeginAccSupp{ActualText={}}\textcolor{red}{\small\ttfamily\bfseries user \$> }}\EndAccSupp{}}

\makeatletter
\tcbset{%
    listing metapost/.code={%
        \def\tcbuselistingtext@input{\begin{mplibcode}
        background:=(.988,.976,.976); input \jobname.listing;
        \end{mplibcode}}%
    }
}
\makeatother
\newtcblisting[auto counter,]{ExempleMP}[1][]{%
  arc=0pt,outer arc=0pt,
  colback=FireBrick!3,
  colframe=FireBrick,
  breakable,fontupper=\small,
  boxsep=0pt,left=2pt,right=2pt,top=0pt,bottom=2pt, bottomtitle =
  3pt, toptitle=3pt, lefttitle=5pt,
  boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
  0pt, bottomrule at break = 0pt,
  listing side text,
  listing metapost,
  title={\bfseries\sffamily Exemple~\thetcbcounter},
  listing options={breaklines},#1
}


\newcommand\mpkiviat{\texttt{mpkiviat}\xspace}
\newcommand\fichier[1]{\texttt{#1}}
\newcommand\variableGDD[1]{\texttt{\color{Sienna}#1}}
\newcommand\typeMP[1]{\texttt{\color{Tomato}#1}}
\newcommand\typeGDD[1]{\texttt{\color{Sienna}#1}}
\newcommand\foncGDD[1]{\texttt{\color{Sienna}#1}}

\newenvironment{Note}{
  \noindent\textbf{Note~---~}}
  {}



% 
\colorlet{code}{blue!80!black}
\newcommand\cmd{\texttt}
\newcommand\code[1]{\texorpdfstring{\texttt{\color{code}#1}}{#1}}
\newcommand*\cs[1]{\code{\textbackslash #1}}
\newcommand*\macro{\par\bigskip\noindent\hspace{-30pt}%
    \SaveVerb[aftersave={%
     \UseVerb{Vitem}%
    }%
    ]{Vitem}%
 %   \bigskip
}
\newcommand\vitem[1][]{\SaveVerb[%
    aftersave={\item[\textnormal{\UseVerb[#1]{vsave}}]}]{vsave}}
\newcommand*\textme[1]{\textcolor{black}{\rmfamily\textit{#1}}}
\newcommand*\meta[1]{% % meta
  \textme{\ensuremath{\langle}#1\ensuremath{\rangle}}%
}
\newcommand*\optstar{% % optional star
  \meta{\ensuremath{*}}\xspace
}
\DefineShortVerb{\|}
\setlength{\fboxsep}{2pt}
\fvset{%
    codes={\catcode`\«\active \catcode`\×\active },
    defineactive={\makefancyog\makefancytimes},
    formatcom=\color{FireBrick},
    frame=single
}
% rendre «...» équivalent à \meta{...}
{\catcode`\«\active
  \newcommandx\makefancyog[0][addprefix=\global]{%
    \def«##1»{\meta{##1}}}}
% rendre × équivalent à \optstar
{\catcode`\×\active
  \newcommandx\makefancytimes[0][addprefix=\global]{%
    \def×{\optstar{}}}}
 
\NewDocumentEnvironment{Macro}{ov}{%
\Verb+#2+
}{%
}
\newcommand{\return}[1]{~$\rightarrow$~#1}
\newcommand{\indication}[1]{\hfill(\itshape #1)}

\newcommand{\R}{\mathbf{R}}

\begin{document}
%% === Page de garde ===================================================
\thispagestyle{empty}
\begin{tikzpicture}[remember picture, overlay]
 \node[below right, shift={(-4pt,4pt)}] at (current page.north west) {%
   \includegraphics{fond.pdf}%
 };
\end{tikzpicture}%

\noindent
{\Huge \bfseries \mpkiviat}\\
{\large Package \MP{} to draw Kiviat diagrams}\\[1cm]
\parbox{0.6\textwidth}{
\includegraphics[scale=0.86]{test-2.pdf}
}\hfill
\parbox{0.4\textwidth}{\Large\raggedleft
   \textbf{Contributors}\\
   Maxime \textsc{Chupin}\\
   \url{notezik@gmail.com}
}
\vfill
\begin{center}
Version 0.1, 22th of may 2024\\
\url{https://gitlab.gutenberg-asso.fr/mchupin/mpkiviat}
\end{center}
%% == Page de garde ====================================================
\newpage

\begin{abstract}
  This \hologo{METAPOST} package allows to draw Kiviat diagram (or radar chart,
  web chart, spider chart, etc.).
\end{abstract}

\tableofcontents


\section{Introduction}

\mpkiviat is a package to draw Kiviat diagram (web chart, spider chart, spider
graph, spider web chart, star chart, star plot, cobweb chart, irregular polygon,or
polar chart) with \MP~\cite{ctan-metapost}.

\section{Installation}

\mpkiviat is on \ctan{} and can also be installed via the package manager of
your distribution.

\begin{center}
  \url{https://www.ctan.org/pkg/mpkiviat}
\end{center}


\subsection{With \TeX live under Linux or macOS}

To install \mpkiviat with \TeX Live, you will have to create the directory
\lstinline+texmf+  in your \lstinline+home+. 

\begin{commandshell}
mkdir ~/texmf
\end{commandshell}

Then, you will have to place the \lstinline+mpkiviat.mp+ file in 
\begin{center}
  \lstinline+~/texmf/metapost/mpkiviat/+
\end{center}


Once this is done, \mpkiviat will be loaded with the classic \MP{}
input code
\begin{mpcode}
input mpkiviat
\end{mpcode}

\subsection{With Mik\TeX{} and Windows}

These two systems are unknown to the author of \mpkiviat, so we
refer you to the Mik\TeX documentation concerning the addition of local packages:
\begin{center}
  \url{http://docs.miktex.org/manual/localadditions.html}
\end{center}



\subsection{Dependencies}


\mpkiviat depends, of course on \MP~\cite{ctan-metapost}, as well as the
packages and---if \mpkiviat is not used with
\hologo{LuaLaTeX}~\cite{ctan-lualatex-doc,ctan-luatex} and the
\package{luamplib} or \package{minim-mp}~\cite{ctan-luamplib,ctan-minim-mp} 
packages---the \package{latexmp}~\cite{ctan-latexmp} package. 


\section{Axis and lattice}

\begin{colourband}
  \macro|set_axis(«list of axis names»)|
\medskip

  The \meta{list of axis names} is a list delimited by commas with the names of
  the different axis as \typeMP{string} (e.g.
  \lstinline+"Légumes","Fruits","Produits laitiers"+).
  \index{set_axis@\lstinline+set_axis+}
\end{colourband}

The command to draw the Kiviat background is the following:


\begin{colourband}
  \macro|draw_axis|
  \index{draw_axis@\lstinline+draw_axis+}
\end{colourband}

The combinaison of these two commands produces, for example:
\begin{ExempleMP}[sidebyside=false]
input mpkiviat;
beginfig(1);
set_axis("Légumes","Viande","Lait","Pain","Poissons");
draw_axis;
endfig;
\end{ExempleMP}

By default, legend of each axis are written, but you can avoid that using the
following command:

\begin{colourband}
  \macro|set_axis_legends(«boolean»)|
  \medskip 

  \begin{description}
    \item[\meta{boolean}:] \typeMP{true} or \typeMP{false} 
  \end{description}
  \index{set_axis_legends@\lstinline+set_axis_legends+}
\end{colourband}


Default value for each axis is 10, and there is 10 steps for the lattice. You
can redefine that with the following command that \emph{should be set before the
drawing command} :
\begin{colourband}
  \macro|set_lattice_grid(«unit»,«max»)|
\medskip

  \begin{description}
    \item[\meta{unit}:] (\typeMP{numeric}) is the interval between two lines of the lattice;
    \item[\meta{max}:] (\typeMP{numeric}) is the maximum value for each axis.  
  \end{description}
  \index{set_lattice_grid@\lstinline+set_lattice_grid+}
\end{colourband}

You can print the graduations for the lattice with the following command:
\begin{colourband}
  \macro|draw_grad(«prefix»,«suffix»,«axis number»)|
\medskip

\begin{description}
  \item[\meta{prefix}:] (\typeMP{string}) is a string to add before each graduation;
  \item[\meta{suffix}:] (\typeMP{suffix}) is a string to add after each graduation;
  \item[\meta{axis number}:] (\typeMP{numeric}) is an integer to choose the axis
  used for printing the graduations.   
\end{description}
\index{draw_grad@\lstinline+draw_grad+}
\end{colourband}

\mpkiviat defines a unit that can be modified to scale the entire graph with the
following command (that must be used before the command \lstinline+set_axis+).

\begin{colourband}
  \macro|set_kiviat_unit(«unit»)|
\medskip

\begin{description}
  \item[\meta{unit}:] (\typeMP{string}, default \SI{0.3}{cm}) is the unit to
  draw the graph.   
\end{description}
\index{set_kiviat_unit@\lstinline+set_kiviat_unit+}
\end{colourband}

One can set colors for the axis and the lattice with the two following commands. 


\begin{colourband}
  \macro|set_axis_color(«color»)|
\medskip

  \begin{description}
    \item[\meta{color}:] (\typeMP{color}) is the color for drawing the axis arrows.  
  \end{description}
  \index{set_axis_color@\lstinline+set_axis_color+}
\end{colourband}


\begin{colourband}
  \macro|set_lattice_color(«color»)|
\medskip

  \begin{description}
    \item[\meta{color}:] (\typeMP{color}) is the color for drawing the lattice.  
  \end{description}
  \index{set_lattice_color@\lstinline+set_lattice_color+}
\end{colourband}



The following example illustrates some of the previous commands. 

\begin{ExempleMP}[sidebyside=false]
input mpkiviat;
beginfig(1);
set_kiviat_unit(0.4cm);
set_axis("Légumes","Viande","Lait","Pain","Poissons");
set_axis_color((0.7,0.1,0.1));
set_lattice_color((0.5,0.5,0.9));
set_lattice_grid(100,600);
draw_axis;
draw_grad("","~€",3);
endfig;
\end{ExempleMP}


\section{Add lines}

Once you have drawn the background, you can add lines for your Kiviat diagram. 
The basic command to do that is the following:

\begin{colourband}
  \macro|draw_line(«list of values»)(«color»)|
\medskip

  \begin{description}
    \item[\meta{list of value}:] (list of \typeMP{string}) values for the
    different axis of the Kiviat diagram (e.g. \lstinline+"9","2","3"+). The
    values must match the settings of the lattice. 
    \item[\meta{color}:] (\typeMP{color}) is the color for drawing the line.  
  \end{description}
  \index{draw_line@\lstinline+draw_line+}
\end{colourband}

You can also draw and fill a Kiviat line with the following command:

\begin{colourband}
  \macro|filldraw_line(«list of values»)(«color»)|
\medskip

  \begin{description}
    \item[\meta{list of value}:] (list of \typeMP{string}) values for the
    different axis of the Kiviat diagram (e.g. \lstinline+"9","2","3"+). The
    values must match the settings of the lattice. 
    \item[\meta{color}:] (\typeMP{color}) is the color for drawing the line. The
    filling color is transparent\footnote{Thanks to Anthony Phan \MP{} code : \url{http://www-math.univ-poitiers.fr/~phan/metalpha.html}.}
  \end{description}
  \index{filldraw_line@\lstinline+filldraw_line+}
\end{colourband}

By default, there is mark on a Kiviat line. You can remove marks with the
following command, setting the booelan argument to \lstinline+false+. 



\begin{colourband}
  \macro|set_line_mark(«boolean»)|
\medskip


\begin{description}
  \item[\meta{boolean}:] \typeMP{true} or \typeMP{false} 
\end{description}
  \index{set_line_mark@\lstinline+set_line_mark+}
\end{colourband}

You can also choose the type of mark. \mpkiviat provides three types :
\lstinline+"square"+, by default, \lstinline+"circle"+ and \lstinline+"custom"+.
To choose one of them, you have to use the following command: 
\begin{colourband}
  \macro|set_line_mark_type(«type»)|
\medskip


\begin{description}
  \item[\meta{type}:] (\typeMP{string})  \lstinline+"square"+, by default,
  \lstinline+"circle"+ and \lstinline+"custom"+. 
\end{description}
  \index{set_line_mark_type@\lstinline+set_line_mark_type+}
\end{colourband}

If you choose \lstinline+custom+, you will have to define a macro
\lstinline+line_mark_custom+ that take a \typeMP{pair} as argument and that
define a cycled path shifted around the \typeMP{pair}. For instance, the
\lstinline+line_mark_square+ command is defined as:
\begin{mpcode}
def line_mark_square(expr p)=
  (((-1,-1)--(1,-1)--(1,1)--(-1,1)--cycle scaled _line_mark_scale) shifted p)
enddef;
\end{mpcode}

You can adjust the size of the marks using the following scaling macro:
\begin{colourband}
  \macro|set_line_mark_scale(«scaling factor»)|
\medskip


\begin{description}
  \item[\meta{scaling factor}:] is a \typeMP{numeric} that is, by default, 1. 
\end{description}
  \index{set_line_mark_scale@\lstinline+set_line_mark_scale+}
\end{colourband}

Here is an example that illustrates some of the previous commands. 

\begin{ExempleMP}[sidebyside=false]
input mpkiviat;
beginfig(1);
set_lattice_grid(100,500);
set_kiviat_unit(0.4cm);
set_axis("McCabe","LOC","Live Variables","Halstead N","Variablenspanne");
draw_axis;

filldraw_line(400,300,380,200,250)(red);
set_line_mark_type("circle");
filldraw_line(300,320,180,400,150)(blue);
set_line_mark_type("square");
set_line_mark_scale(2);
filldraw_line(100,420,280,200,50)(green);
endfig;
\end{ExempleMP}

\section{Legends}

\mpkiviat provides the following command to add legends to a Kiviat diagram:

\begin{colourband}
  \macro|draw_legends.«place»(«list of names»)|
\medskip


\begin{description}
  \item[\meta{place}:] is one of the standard \MP{} suffixes :
  empty, \lstinline+lft+, \lstinline+rt+, \lstinline+top+,
  \lstinline+bot+, \lstinline+ulft+, \lstinline+urt+, \lstinline+llft+ and
  \lstinline+lrt+. The legend is placed at the given place of the bounding box
  of the complete Kiviat diagram (without the legend). If it is empty, the
  default place is \lstinline+rt+. 
  \item[\meta{list of names}:] is the list of \typeMP{string} of names for the
  different lines in the order of the construction.   
\end{description}
  \index{draw_legends@\lstinline+draw_legends+}
\end{colourband}

\begin{ExempleMP}[sidebyside=false]
input mpkiviat;
beginfig(1);
set_lattice_grid(100,500);
set_kiviat_unit(0.4cm);
set_axis("McCabe","LOC","Live Variables","Halstead N","Variablenspanne");
draw_axis;

filldraw_line(400,300,380,200,250)(red);
set_line_mark_type("circle");
filldraw_line(300,320,180,400,150)(blue);
set_line_mark_type("square");
set_line_mark_scale(2);
filldraw_line(100,420,280,200,50)(green);
draw_legends.lrt("Première", "Deuxième", "Troisième");
endfig;
\end{ExempleMP}

\printbibliography
\printindex

\end{document}