From bc71ec3b9d78d568e53a103c858b43fd284b44d4 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 23 May 2024 03:01:29 +0000 Subject: CTAN sync 202405230301 --- graphics/metapost/contrib/macros/mpkiviat/LICENSE | 11 + .../metapost/contrib/macros/mpkiviat/README.md | 18 + .../metapost/contrib/macros/mpkiviat/doc/ctan.bib | 72 +++ .../metapost/contrib/macros/mpkiviat/doc/fond.pdf | Bin 0 -> 1309 bytes .../contrib/macros/mpkiviat/doc/mpkiviat-doc.pdf | Bin 0 -> 108472 bytes .../contrib/macros/mpkiviat/doc/mpkiviat-doc.tex | 571 +++++++++++++++++++++ .../contrib/macros/mpkiviat/doc/test-2.pdf | Bin 0 -> 3530 bytes .../contrib/macros/mpkiviat/metapost/mpkiviat.mp | 318 ++++++++++++ 8 files changed, 990 insertions(+) create mode 100644 graphics/metapost/contrib/macros/mpkiviat/LICENSE create mode 100644 graphics/metapost/contrib/macros/mpkiviat/README.md create mode 100644 graphics/metapost/contrib/macros/mpkiviat/doc/ctan.bib create mode 100644 graphics/metapost/contrib/macros/mpkiviat/doc/fond.pdf create mode 100644 graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.pdf create mode 100644 graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.tex create mode 100644 graphics/metapost/contrib/macros/mpkiviat/doc/test-2.pdf create mode 100644 graphics/metapost/contrib/macros/mpkiviat/metapost/mpkiviat.mp (limited to 'graphics') diff --git a/graphics/metapost/contrib/macros/mpkiviat/LICENSE b/graphics/metapost/contrib/macros/mpkiviat/LICENSE new file mode 100644 index 0000000000..130ede1e51 --- /dev/null +++ b/graphics/metapost/contrib/macros/mpkiviat/LICENSE @@ -0,0 +1,11 @@ + +This work may be distributed and/or modified under the +conditions of the LaTeX Project Public License, either version 1.3c +of this license or (at your option) any later version. +The latest version of this license is in + http://www.latex-project.org/lppl.txt +and version 1.3c or later is part of all distributions of LaTeX +version 2005/12/01 or later. + +This work has the LPPL maintenance status “maintained”. + diff --git a/graphics/metapost/contrib/macros/mpkiviat/README.md b/graphics/metapost/contrib/macros/mpkiviat/README.md new file mode 100644 index 0000000000..eb9666947d --- /dev/null +++ b/graphics/metapost/contrib/macros/mpkiviat/README.md @@ -0,0 +1,18 @@ +# MPkiviat + +This package allows you to Kiviat diagrams. + +_This package is in beta version, do not hesitate to report bugs, as well as +requests for improvement_. + +## Documentation + +* [English documentation](doc/mpkiviat-doc-en.pdf) + +## Contact + +Maxime Chupin, `notezik(at)gmail.com` + +## Licenses + +This projet is under LATEX Project Public License 1.3c. \ No newline at end of file diff --git a/graphics/metapost/contrib/macros/mpkiviat/doc/ctan.bib b/graphics/metapost/contrib/macros/mpkiviat/doc/ctan.bib new file mode 100644 index 0000000000..546a180815 --- /dev/null +++ b/graphics/metapost/contrib/macros/mpkiviat/doc/ctan.bib @@ -0,0 +1,72 @@ + +@manual{ctan-latexmp, + title = {The \texttt{latexMP} package}, + subtitle = {Interface for \LaTeX{}-based typesetting in MetaPost}, + author = {Jens-Uwe Morawski}, + date = {2020-06-21}, + version = {1.2.1}, + license = {pd}, + mirror = {https://mirror.ctan.org/graphics/metapost/contrib/macros/latexmp}, + url = {https://ctan.org/pkg/latexmp}, + annotation = {The MetaPost package latexMP implements a user-friendly + interface to access \LaTeX{}-based typesetting capabilities in + MetaPost. The text to be typeset is given as string. This + allows even dynamic text elements, for example counters, to be + used in labels. Compared to other implementations it is much + more flexible, since it can be used as direct replacement for + , and much faster, compared for example to the + solution provided by .}, +} + +@manual{ctan-minim-mp, + title = {The \texttt{minim-mp} package}, + subtitle = {Low-level mplib integration for LuaTeX}, + author = {Esger Renkema}, + date = {2024-04-06}, + version = {2024/1.6}, + license = {eupl}, + mirror = {https://mirror.ctan.org/macros/luatex/generic/minim-mp}, + url = {https://ctan.org/pkg/minim-mp}, +} +@manual{ctan-lualatex-doc, + title = {The \texttt{lualatex-doc} package}, + subtitle = {A guide to use of \LaTeX{} with LuaTeX}, + author = {Manuel Pégourié-Gonnard}, + date = {2023-12-07}, + version = {}, + license = {fdl}, + mirror = {https://mirror.ctan.org/obsolete/info/luatex/lualatex-doc}, + url = {https://ctan.org/pkg/lualatex-doc}, +} + +@manual{ctan-luatex, + title = {The \texttt{luatex} package}, + subtitle = {The LuaTeX engine}, + author = {{The LuaTeX Team}}, + date = {2021-12-09}, + license = {gpl2+}, + url = {https://ctan.org/pkg/luatex}, +} +@manual{ctan-metapost, + title = {The \texttt{metapost} package}, + subtitle = {A development of Metafont for creating graphics}, + author = {{The MetaPost Team} and John Hobby}, + date = {2021-08-26}, + license = {lgpl}, + url = {https://ctan.org/pkg/metapost}, + annotation = {MetaPost uses a language based on that of + to produce precise + technical illustrations. Its output is scalable PostScript or + SVG, rather than the bitmaps Metafont creates.}, +} + +@manual{ctan-luamplib, + title = {The \texttt{luamplib} package}, + subtitle = {Use LuaTeX’s built-in MetaPost interpreter}, + author = {Hans Hagen and Taco Hoekwater and Élie Roux and Manuel Pégourié-Gonnard and Philipp Gesang and Dohyun Kim}, + date = {2024-05-10}, + version = {2.30.0}, + license = {gpl2}, + mirror = {https://mirror.ctan.org/macros/luatex/generic/luamplib}, + url = {https://ctan.org/pkg/luamplib}, +} diff --git a/graphics/metapost/contrib/macros/mpkiviat/doc/fond.pdf b/graphics/metapost/contrib/macros/mpkiviat/doc/fond.pdf new file mode 100644 index 0000000000..22218152cc Binary files /dev/null and b/graphics/metapost/contrib/macros/mpkiviat/doc/fond.pdf differ diff --git a/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.pdf b/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.pdf new file mode 100644 index 0000000000..259f2c2846 Binary files /dev/null and b/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.pdf differ diff --git a/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.tex b/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.tex new file mode 100644 index 0000000000..fadc0a0b71 --- /dev/null +++ b/graphics/metapost/contrib/macros/mpkiviat/doc/mpkiviat-doc.tex @@ -0,0 +1,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} diff --git a/graphics/metapost/contrib/macros/mpkiviat/doc/test-2.pdf b/graphics/metapost/contrib/macros/mpkiviat/doc/test-2.pdf new file mode 100644 index 0000000000..7b6dec4a9a Binary files /dev/null and b/graphics/metapost/contrib/macros/mpkiviat/doc/test-2.pdf differ diff --git a/graphics/metapost/contrib/macros/mpkiviat/metapost/mpkiviat.mp b/graphics/metapost/contrib/macros/mpkiviat/metapost/mpkiviat.mp new file mode 100644 index 0000000000..135a071df1 --- /dev/null +++ b/graphics/metapost/contrib/macros/mpkiviat/metapost/mpkiviat.mp @@ -0,0 +1,318 @@ +% mpkiviat.mp v0.1 +% @Author: Maxime Chupin +% @Date: 22 may 2024 +% @License: LATEX Project Public License 1.3c. + +if not known mplib: input latexmp fi; +pair _axis[]; + +numeric _axis_number; +numeric _kiviat_unit; + +numeric _lattice_unit,_lattice_max,_value_max,_unit_value; +_lattice_unit := 1; +_lattice_max :=10; +_value_max := 10; +_unit_value := 1; +_kiviat_unit:=0.3cm; + + +pair _kiviat_lines[][]; +path _kiviat_path[]; +color _kiviat_lines_color[]; +numeric _line_nbr; +_line_nbr:=0; + +def set_lattice_grid(expr u,m)= + save _nbr; + _nbr := (m/u); + _value_max := m; + _unit_value := u; + _lattice_max := floor(_nbr); +enddef; + + +string _axis_names[]; + +color _kiviat_lattice_color, _kiviat_axis_color; +_kiviat_axis_color:= black; +_kiviat_lattice_color:= 0.8*white; + +vardef set_axis_color(expr c)= + _kiviat_axis_color:= c; +enddef; + +def set_kiviat_unit(expr u)= + _kiviat_unit:=u; +enddef; + +vardef set_lattice_color(expr c)= + _kiviat_lattice_color:= c; +enddef; + +vardef set_axis(text t)= + _line_nbr:=0; + save _st,_i; + _axis_number:=0; + for _st=t: + _axis_number:= _axis_number+1; + _axis_names[_axis_number]:=_st; + endfor + for i:=1 upto _axis_number: + _axis[i]:=(cosd(i/_axis_number*360)*_lattice_max*_kiviat_unit,sind(i/_axis_number*360)*_lattice_max*_kiviat_unit); + endfor +enddef; + + + + + +boolean _legend; +_legend:=true; + +% function to determine the point of the bb that intersect the line +% determined by the angle of the corresponding axis +vardef _pointbb (expr p, a)= + save _bb,_d,_point; + path _bb,_d; + pair _point; + _bb := bbox p; + _d := (0,0)--(3000*cosd(a),3000*sind(a)); + _point := _bb intersectionpoint _d; + _point +enddef; + +% set legends true/false +vardef set_axis_legends(expr b)= + _legend:=b; +enddef; + +def draw_axis = + save _plabel; + picture _plabel; + for i:=_lattice_unit step _lattice_unit until _lattice_max : + draw for j:=1 upto _axis_number: (i/_lattice_max)*_axis[j]--endfor cycle withcolor + _kiviat_lattice_color; + endfor + for i:=1 upto _axis_number: + drawarrow (0,0)--1.2*_axis[i] withcolor _kiviat_axis_color; + endfor + if(_legend): + for i:=1 upto _axis_number: + _plabel := image(label(textext(_axis_names[i]),origin)); % passage + % par image et label pour centrer la bbox + draw _plabel + shifted (1.2*_axis[i]+labeloffset*(cosd(angle _axis[i]),sind(angle + _axis[i]))+_pointbb(_plabel,angle _axis[i])) ; + endfor; + fi +enddef; + +def draw_grad(expr p,s)(expr j)= + for i:=1 upto _lattice_max: + unfill bbox (textext(p&decimal(i*_unit_value)&s) shifted (i/_lattice_max*_axis[j])); + draw textext(p&decimal(i*_unit_value)&s) shifted (i/_lattice_max*_axis[j]); + endfor +enddef; + + + +vardef _build_line(text t)= + save _values,_i; + _line_nbr:=_line_nbr+1; + _i:=0; + for _values=t: + _i:=_i+1; + _kiviat_lines[_line_nbr][_i]:=(_values/_value_max)*_axis[_i]; + if(_i=1): + _kiviat_path[_line_nbr]:=_kiviat_lines[_line_nbr][_i]; + else: + _kiviat_path[_line_nbr]:=_kiviat_path[_line_nbr]--_kiviat_lines[_line_nbr][_i]; + fi + endfor + _kiviat_path[_line_nbr]:=_kiviat_path[_line_nbr]--cycle; +enddef; + + +boolean _line_mark_b; +_line_mark_b:=true; +numeric _line_mark_scale; +_line_mark_scale:=1; + +def set_line_mark_scale(expr n)= + _line_mark_scale:=n; +enddef; + +def set_line_mark(expr b)= + _line_mark_b:=b; +enddef; + +def line_mark_square(expr p)= + ((((-1,-1)--(1,-1)--(1,1)--(-1,1)--cycle) scaled _line_mark_scale) shifted p) +enddef; + +def line_mark_circle(expr p)= + ((fullcircle scaled 2.5 scaled _line_mark_scale) shifted p) +enddef; + +string _mark_type; +_mark_type := "square"; +string _save_type[]; +boolean _save_mark_b[]; +numeric _save_scale[]; + +def set_line_mark_type(expr s)= + _mark_type:=s; +enddef; + +def _mark_line(expr c)= + _save_type[_line_nbr]:=_mark_type; + _save_scale[_line_nbr]:=_line_mark_scale; + for i:=1 upto _axis_number: + fill + if(_mark_type="square"): + line_mark_square + elseif(_mark_type="circle"): + line_mark_circle + elseif(_mark_type="custom"): + line_mark_custom + fi + (_kiviat_lines[_line_nbr][i]) withcolor c; + endfor; +enddef; + +vardef draw_line(text t)(expr c)= + _build_line(t); + _kiviat_lines_color[_line_nbr]:=c; + draw _kiviat_path[_line_nbr] withcolor c; + _save_mark_b[_line_nbr]:=_line_mark_b; + if(_line_mark_b): + _mark_line(c); + fi; +enddef; + + +vardef filldraw_line(text t)(expr c)= + _build_line(t); + _kiviat_lines_color[_line_nbr]:=c; + alphafill(_kiviat_path[_line_nbr],c,0.1); + draw _kiviat_path[_line_nbr] withcolor c; + _save_mark_b[_line_nbr]:=_line_mark_b; + if(_line_mark_b): + _mark_line(c); + fi; +enddef; + +vardef _anchor@# (expr p)= + if(str @# = "top"): + (1/2*(urcorner p)+1/2*(ulcorner p)) + elseif(str @# = "bot"): + (1/2*(lrcorner p)+1/2*(llcorner p)) + elseif(str @# = "lft"): + (1/2*(llcorner p)+1/2*(ulcorner p)) + elseif(str @# = "rt" ): + (1/2*(lrcorner p)+1/2*(urcorner p)) + elseif(str @# = "urt"): + (urcorner p) + elseif(str @# = "ulft"): + (ulcorner p) + elseif(str @# = "lrt"): + (lrcorner p) + elseif(str @# = "llft"): + (llcorner p) + elseif(str @# = "c"): + (1/4*(lrcorner p)+1/4*(urcorner p)+1/4*(llcorner p)+1/4*(ulcorner p)) + else: + (1/4*(lrcorner p)+1/4*(urcorner p)+1/4*(llcorner p)+1/4*(ulcorner p)) + fi + +enddef; + +vardef draw_legends@# (text l) = + save _mypic,i,_s_scale; + _s_scale := _line_mark_scale; + picture _mypic; + _mypic = image( + i:=0; + for s=l: + i:=i+1; + draw ((0,0)--(0.7*_kiviat_unit,0)) shifted (0,i*(_kiviat_unit)) withcolor + _kiviat_lines_color[i]; + if(_save_mark_b[i]): + _line_mark_scale:=_save_scale[i]; + fill + if(_save_type[i]="square"): + line_mark_square + elseif(_save_type[i]="circle"): + line_mark_circle + elseif(_save_type[i]="custom"): + line_mark_custom + fi + (0.5[(0,0),(0.7*_kiviat_unit,0)] )shifted (0,i*(_kiviat_unit)) + withcolor _kiviat_lines_color[i]; + fi + label.rt(textext(s),(0.7*_kiviat_unit,0) shifted (0,i*(_kiviat_unit))); + endfor + draw bbox currentpicture; + _line_mark_scale := _s_scale ; + ); + draw _mypic + if(str @# = "top"): + shifted (_anchor.top(currentpicture)-_anchor.bot(_mypic)) + elseif(str @# = "bot"): + shifted (_anchor.bot(currentpicture)-_anchor.top(_mypic)) + elseif(str @# = "lft"): + shifted (_anchor.lft(currentpicture)-_anchor.rt(_mypic)) + elseif(str @# = "rt" ): + shifted (_anchor.rt(currentpicture)-_anchor.lft(_mypic)) + elseif(str @# = "urt"): + shifted (_anchor.urt(currentpicture)-_anchor.ulft(_mypic)) + elseif(str @# = "ulft"): + shifted (_anchor.ulft(currentpicture)-_anchor.urt(_mypic)) + elseif(str @# = "lrt"): + shifted (_anchor.lrt(currentpicture)-_anchor.llft(_mypic)) + elseif(str @# = "llft"): + shifted (_anchor.llft(currentpicture)-_anchor.lrt(_mypic)) + else: + shifted (_anchor.rt(currentpicture)-_anchor.lft(_mypic)) + fi + ; +enddef; +% transparency Phan : http://www-math.univ-poitiers.fr/~phan/metalpha.html +% revisité par Jean-Michel Sarlat +color _tc; +numeric _ta; +picture _ap; + +def _AlphaFill expr c = + _ap := nullpicture; + _AlphaPicture(currentpicture,c); + addto currentpicture also _ap; +enddef; + +vardef _AlphaPicture(expr p,c) = + save p_; picture p_; + p_ := nullpicture; + addto p_ contour c withcolor _ta[background,_tc]; + for p__ within p: + if (not clipped p__) and (not bounded p__): + addto p_ also p__ withcolor + _ta[(redpart p__,greenpart p__,bluepart p__), _tc]; + else: + begingroup save _ap; + picture _ap; _ap = nullpicture; + _AlphaPicture(p__,pathpart p__); + addto p_ also _ap; + endgroup; + fi + endfor; + clip p_ to c; + addto _ap also p_; +enddef; + +vardef alphafill(expr p,c,a) = + _tc := c; _ta := a; + _AlphaFill p +enddef; + +endinput; \ No newline at end of file -- cgit v1.2.3