如何调整轮图中的文本大小并使用数据工具应用适当的过滤?

如何调整轮图中的文本大小并使用数据工具应用适当的过滤?

wheelchart我对于与 的结合非常满意datatool,但有三个问题困扰着我:

  1. 我想增加外圈文字的字体大小(PlanProduction)。这样看起来应该更容易阅读。

在此处输入图片描述

  1. 我想过滤某些活动(列category)。这很好用,但我还想有一个版本没有过滤器。这是左侧的第一个轮图。它可以工作,但代码有错误——因为(据我所知)datatool想要在[]数据库中过滤一些值。当从列中过滤值时,它可以正常工作category

在此处输入图片描述

  1. 我想去掉被过滤掉的活动的空白区域。换句话说,轮盘图应该缩小,并且没有空白区域(就像第一个轮盘图没有过滤器时那样)。

这意味着“数据管理员”的轮图会非常小,因为它只有四个环: 在此处输入图片描述

这是我的 MWE:

\documentclass[border=0,dvipsnames]{standalone}
\usepackage{fontspec}
\setmainfont{TeX Gyre Heros}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.markings}

\usepackage{datatool}
\usepackage{etoolbox}
\colorlet{stages}{Blue}
\colorlet{service}{Magenta}
\colorlet{datasteward}{Green}
\colorlet{consulting}{Cyan}
\colorlet{project}{Orange}
\colorlet{natInf}{Purple}


% counter for having slightly different colors for the categories
\newcounter{rpdmCategoryService}\setcounter{rpdmCategoryService}{100}
\newcounter{rpdmCategoryDatasteward}\setcounter{rpdmCategoryDatasteward}{100}
\newcounter{rpdmCategoryConsulting}\setcounter{rpdmCategoryConsulting}{100}
\newcounter{rpdmCategoryProject}\setcounter{rpdmCategoryProject}{100}
\newcounter{rpdmCategoryNFDI}\setcounter{rpdmCategoryNFDI}{100}

%counting the amount of items/activitys to adjust radius of the outer stages
\newcounter{rpdmStagesRadius}
\setcounter{rpdmStagesRadius}{0}

\usepackage{xstring}
\DeclareRobustCommand{\rpdmCheckCategory}[1]{%
\IfEqCase{#1}{%
{service}{\addtocounter{rpdmCategoryService}{-5}\def\rpdmSliceColor{service!\therpdmCategoryService}}
{datasteward}{\addtocounter{rpdmCategoryDatasteward}{-5}\def\rpdmSliceColor{datasteward!\therpdmCategoryDatasteward}}
{consulting}{\addtocounter{rpdmCategoryConsulting}{-5}\def\rpdmSliceColor{consulting!\therpdmCategoryConsulting}}
{project}{\addtocounter{rpdmCategoryProject}{-5}\def\rpdmSliceColor{project!\therpdmCategoryProject}}
{natInf}{\addtocounter{rpdmCategoryNFDI}{-5}\def\rpdmSliceColor{natInf!\therpdmCategoryNFDI}}
}[\def\rpdmSliceColor{red}]
}

\usepackage{wheelchart}

\begin{filecontents}[overwrite]{activities.csv}
category,startangle,totalangle,name,begin,end
datasteward,-90,180,project1,2014,2024
service,0,90,project2,2019,
datasteward,-90,180,project3,2019,
natInf,40,280,project4,2020,
natInf,40,280,project5,2020,
natInf,40,280,project6,2020,
service,0,90,project7,2021,
service,0,90,project8,2021,
project,90,270,project9,2021,2024
service,0,90,project10,2023,
service,0,90,project11,2021,
natInf,40,280,project12,2021,
natInf,40,280,project13,2021,
datasteward,-90,180,project14,2019,2023
datasteward,-90,180,project15,2023,
project,90,270,project16,2023,
project,-60,270,project17,2020,2023
project,90,270,project18,2022,
consulting,90,120,project19,2022,
consulting,90,120,project20,2022,
consulting,90,120,project21,2023,
project,0,240,project22,2023,
project,0,240,project23,2023,
\end{filecontents}
\DTLloaddb{activities}{activities.csv}
% RDM stages
\gdef\rdmStages{%
20/stages/Plan,
20/stages/Production,
20/stages/Analysis,
20/stages/Storage,
20/stages/Access,
20/stages/Re-use%
}

% läuft wieder....
\NewDocumentCommand{\RDMstages}{}{%
  \wheelchart[
%explode{1}=1,
value          =1,
gap            =.1,
data           =,
radius         ={2+\therpdmStagesRadius}{4+\therpdmStagesRadius},
arc data       =~\WCvarC~,
arc data dir   ={\WCmidangle<180?1:-1},
arc data pos   =0.5,
arc data style ={text color=white},
slices arrow   ={.5}{0},
]{\rdmStages}}

\NewDocumentCommand{\RDMactivityCircle}{som}{%
\setcounter{rpdmCategoryService}{100}
\setcounter{rpdmCategoryDatasteward}{100}
\setcounter{rpdmCategoryConsulting}{100}
\setcounter{rpdmCategoryProject}{100}
\setcounter{rpdmCategoryNFDI}{100}
\begin{tikzpicture}
  \DTLsort{begin,startangle}{activities}%
  \DTLforeach%
  [%
  %For the starred version there should be no filtering
   \IfBooleanTF{#1}{}{\DTLisinlist{\WCcategory}{#3}}% FIX THIS
  ]%
  {activities}{%
\WCcategory =category,%
\WCstart    =startangle,%
\WCend      =totalangle,%
\WCname     =name,%
\WCsince    =begin,%
\WCtil      =end%
}{%
\wheelchart[
for loop start = {\rpdmCheckCategory{\WCcategory}},
for loop end = {\setcounter{rpdmStagesRadius}{\dtlrownum}},
  data=,
  arc data={\WCname},
  arc data dir={\WCmidangle<180?1:-1},
  arc data pos=0.5,
  arc data style={text color=white},
  gap radius=0.05,
  radius={1+\dtlrownum}{2+\dtlrownum},
  slices style={\rpdmSliceColor},
  slices end arc={1}{0},
  slices start arc={1}{0},
  start angle=\WCstart,
  total angle={\WCend}
]{1}}
\RDMstages
\IfValueT{#2}{%
\node[align=center,font=\bfseries, yshift=2em] (title)
    at (current bounding box.north)
    {\Huge #2};}
\end{tikzpicture}}

\begin{document}
\RDMactivityCircle*{} % FIX THIS
\RDMactivityCircle[Projects]{project}
\RDMactivityCircle[Consulting]{consulting}
\RDMactivityCircle[National Infrastructures]{natInf}
\RDMactivityCircle[Services and Infrastructures]{service}
\RDMactivityCircle[Data Stewards]{datasteward}
\end{document}

答案1

包裹轮图(我写的)加载了包,tikz因此\usepackage{tikz}被删除。

外圈文字的字体大小可以通过|\huge|键改变arc data。此 MWE 中不需要~周围的文字。\WCvarC

对于 的真正分支\IfBooleanTF\boolean{true}已添加。

不使用 ,而是在命令开始时将\dtlrownum计数器rpdmStagesRadius设置为。此计数器在命令的第四个参数中增加。然后不再使用该键。0\RDMactivityCircle\wheelchart\DTLforeachfor loop end

对于这个 MWE,\usetikzlibrary{decorations.markings}\usepackage{etoolbox}是不必要的,因此它们被删除。

命令\rdmStages包含在命令 中\RDMstages。这里,stages不需要每次都使用 来重复。而且由于使用了 ,因此不需要slices style=stages多次重复。然后用 替换。20value=1\WCvarC\WCvarA

该密钥yshift=2em被替换为above

在此处输入图片描述

\documentclass[border=6pt,dvipsnames]{standalone}
\usepackage{fontspec}
\setmainfont{TeX Gyre Heros}
\usepackage{wheelchart}
\usetikzlibrary{decorations.text}
\usepackage{datatool}
\colorlet{stages}{Blue}
\colorlet{service}{Magenta}
\colorlet{datasteward}{Green}
\colorlet{consulting}{Cyan}
\colorlet{project}{Orange}
\colorlet{natInf}{Purple}
%counter for having slightly different colors for the categories
\newcounter{rpdmCategoryService}\setcounter{rpdmCategoryService}{100}
\newcounter{rpdmCategoryDatasteward}\setcounter{rpdmCategoryDatasteward}{100}
\newcounter{rpdmCategoryConsulting}\setcounter{rpdmCategoryConsulting}{100}
\newcounter{rpdmCategoryProject}\setcounter{rpdmCategoryProject}{100}
\newcounter{rpdmCategoryNFDI}\setcounter{rpdmCategoryNFDI}{100}
%counting the amount of items/activities to adjust radius of the outer stages
\newcounter{rpdmStagesRadius}
\setcounter{rpdmStagesRadius}{0}
\usepackage{xstring}
\DeclareRobustCommand{\rpdmCheckCategory}[1]{%
\IfEqCase{#1}{%
{service}{\addtocounter{rpdmCategoryService}{-5}\def\rpdmSliceColor{service!\therpdmCategoryService}}
{datasteward}{\addtocounter{rpdmCategoryDatasteward}{-5}\def\rpdmSliceColor{datasteward!\therpdmCategoryDatasteward}}
{consulting}{\addtocounter{rpdmCategoryConsulting}{-5}\def\rpdmSliceColor{consulting!\therpdmCategoryConsulting}}
{project}{\addtocounter{rpdmCategoryProject}{-5}\def\rpdmSliceColor{project!\therpdmCategoryProject}}
{natInf}{\addtocounter{rpdmCategoryNFDI}{-5}\def\rpdmSliceColor{natInf!\therpdmCategoryNFDI}}
}[\def\rpdmSliceColor{red}]
}
\begin{filecontents}[overwrite]{activities.csv}
category,startangle,totalangle,name,begin,end
datasteward,-90,180,project1,2014,2024
service,0,90,project2,2019,
datasteward,-90,180,project3,2019,
natInf,40,280,project4,2020,
natInf,40,280,project5,2020,
natInf,40,280,project6,2020,
service,0,90,project7,2021,
service,0,90,project8,2021,
project,90,270,project9,2021,2024
service,0,90,project10,2023,
service,0,90,project11,2021,
natInf,40,280,project12,2021,
natInf,40,280,project13,2021,
datasteward,-90,180,project14,2019,2023
datasteward,-90,180,project15,2023,
project,90,270,project16,2023,
project,-60,270,project17,2020,2023
project,90,270,project18,2022,
consulting,90,120,project19,2022,
consulting,90,120,project20,2022,
consulting,90,120,project21,2023,
project,0,240,project22,2023,
project,0,240,project23,2023,
\end{filecontents}
\DTLloaddb{activities}{activities.csv}
%RDM stages
\NewDocumentCommand{\RDMstages}{}{%
  \wheelchart[
    arc data=|\huge|\WCvarA,
    arc data dir={\WCmidangle<180?1:-1},
    arc data pos=0.5,
    arc data style={text color=white},
    data=,
    gap=.1,
    radius={2+\therpdmStagesRadius}{4+\therpdmStagesRadius},
    slices arrow={.5}{0},
    slices style=stages,
    value=1
  ]{Plan,Production,Analysis,Storage,Access,Re-use}%
}
\NewDocumentCommand{\RDMactivityCircle}{som}{%
  \setcounter{rpdmCategoryService}{100}
  \setcounter{rpdmCategoryDatasteward}{100}
  \setcounter{rpdmCategoryConsulting}{100}
  \setcounter{rpdmCategoryProject}{100}
  \setcounter{rpdmCategoryNFDI}{100}
  \setcounter{rpdmStagesRadius}{0}
  \begin{tikzpicture}
  \DTLsort{begin,startangle}{activities}%
  \DTLforeach%
    [%
      %For the starred version there should be no filtering
      \IfBooleanTF{#1}{\boolean{true}}{\DTLisinlist{\WCcategory}{#3}}
    ]%
    {activities}%
    {%
      \WCcategory=category,%
      \WCstart=startangle,%
      \WCend=totalangle,%
      \WCname=name,%
      \WCsince=begin,%
      \WCtil=end%
    }%
    {%
      \addtocounter{rpdmStagesRadius}{1}%
      \wheelchart[
        arc data=\WCname,
        arc data dir={\WCmidangle<180?1:-1},
        arc data pos=0.5,
        arc data style={text color=white},
        before slices=\rpdmCheckCategory{\WCcategory},
        data=,
        gap radius=0.05,
        radius={1+\therpdmStagesRadius}{2+\therpdmStagesRadius},
        slices end arc={1}{0},
        slices start arc={1}{0},
        slices style=\rpdmSliceColor,
        start angle=\WCstart,
        total angle=\WCend
      ]{1}%
    }%
  \RDMstages%
  \IfValueT{#2}{\node[align=center,font=\bfseries,above] at (current bounding box.north) {\Huge #2};}%
  \end{tikzpicture}%
}
\begin{document}
\RDMactivityCircle*{}
\RDMactivityCircle[Projects]{project}
\RDMactivityCircle[Consulting]{consulting}
\RDMactivityCircle[National Infrastructures]{natInf}
\RDMactivityCircle[Services and Infrastructures]{service}
\RDMactivityCircle[Data Stewards]{datasteward}
\end{document}

相关内容