参数化节点圆形扇形阴影

参数化节点圆形扇形阴影

我想在 foreach 中参数化节点创建。创建过程已在以下位置解决: 切掉部分径向阴影作为节点形状的扇形

我认为 foreach 中的替换存在识别问题,但除此之外,为什么第一个节点会得到预期的内容,即内容(\monname)和阴影(rad1)?

有人知道解决办法吗?

\documentclass[margin=100pt]{standalone}
\usepackage{tikz}     
\makeatletter
   % from https://tex.stackexchange.com/a/127045/121799
   \tikzset{use path/.code=\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}}
\makeatother
\usetikzlibrary{calc,shapes.geometric,backgrounds,fadings}

\tikzset{my radial shader/.code args={#1 with radius #2}
                            {\pgfmathsetmacro{\rone}{0.6*#2}
                             \pgfmathsetmacro{\rtwo}{0.8*#2}
                             \typeout{#1:\rone,#2}
                             \pgfdeclareradialshading{#1}%shading name
                                                     {\pgfpoint{0}{0}}%center point pgfman301a,p.1083
                                                     {rgb(0pt)=(1.00,0.00,0.00); %color specification
                                                      rgb(\rone pt)=(0.60,1.00,0.00);
                                                      rgb(\rtwo pt)=(0.30,1.60,1.00);
                                                      rgb(#2)=(0.00,0.30,1.50) %extent of the circle
                                                     }%end color specification
                            }%end .code args
}%end tikzset

\begin{document}  
\begin{tikzpicture}
\tikzset{shape circlesec/.style={
        draw,
        line width=1.1pt,
        shape=circular sector,
        circular sector angle=30,
        shape border uses incircle,
        anchor=sector center,%to get a circle!
        minimum size = 6.6cm,%
    } 
}

\foreach \monname / \nodename / \borderrotate in {jan/"\jan"/90,feb/"\feb"/0,maerz/"\maerz"/-165} {%
   \node [save path=\nodename, %this line must create "\jan","\feb" etc.
   %\typeout{monname:\monname, nodename: \nodename}%doesn't work
   %    \node [save path=\jan,
          style=shape circlesec,
          shape border rotate=\borderrotate,
   %      shape border rotate=-165,
         ]%
      (\monname) at (0,0) {\monname};%\nodename error undef ctrl seq
   %  (jan) at (0,0) {};%semicolon before \begin{scope} error
   %
   \begin{scope}[on background layer]
      \path    let \p1=($(\monname.arc center)-(\monname.sector center)$),
   %  \path    let \p1=($(jan.arc center)-(jan.sector center)$),
                   \n1={veclen(\y1,\x1)} in 
         [my radial shader={rad1 with radius \n1}];%rad1==param1, \n1 param2 (radius \node \monat)

      \clip[use path=\nodename];               
   %  \clip[use path=\jan];               
      \pgfuseshading{rad1};
   \end{scope}
}%end foreach
\end{tikzpicture} 
\end{document}

不会分配阴影

答案1

您的代码中存在扩展问题。基本上,您无法以您尝试的方式将路径存储在宏中。我建议采用另一种方法,而不是解决这些问题

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\tikzset{shade radial/.code={%
        \tikzset{%
          color four radial/.cd,% I know "four color radial" sounds better but cfr should be acknowledged here
          #1,
          cfradial
        }},
color four radial/.cd,  
shade radial color/.code n args={2}{\colorlet{cfradialcolor#1}{#2}},
shade radial color={1}{black},
shade radial color={2}{black},
shade radial color={3}{white},
shade radial color={4}{white},
cfradial/.style={/tikz/path picture={
\xdef\radius{\radius}
\pgfmathsetmacro{\rone}{0.6*\radius}
\pgfmathsetmacro{\rtwo}{0.8*\radius}
\pgfdeclareradialshading[cfradialcolor1,cfradialcolor2,cfradialcolor3,cfradialcolor4]{cfradial}%shading name see pgfmanual 3.01a, p. 1083
                            {\centerpoint}%center point 
                            {color(0pt)=(cfradialcolor1); %color specifications
                             color(\rone pt)=(cfradialcolor2);
                             color(\rtwo pt)=(cfradialcolor3);
                             color(\radius)=(cfradialcolor4) %
                            }
\typeout{\radius,\rone,\rtwo}
\pgfuseshading{cfradial}
}}}
\definecolor{clr1}{rgb}{1.00,0.00,0.00}
\definecolor{clr2}{rgb}{0.60,1.00,0.00}
\definecolor{clr3}{rgb}{0.30,1.60,1.00}
\definecolor{clr4}{rgb}{0.00,0.30,1.50}

\begin{document}  
\begin{tikzpicture}
\tikzset{shape circlesec/.style={
        draw,
        line width=0.1pt,
        inner xsep=0pt,
        inner ysep=0pt,
    } 
}
\foreach \monname/\borderrotate in {jan/90,feb/0,maerz/-165} {%
\node [shape=circular sector, 
       style=shape circlesec,
       inner sep=0cm,
       shade radial={
        shade radial color={1}{clr1},
        shade radial color={2}{clr2},
        shade radial color={3}{clr3},
        shade radial color={4}{clr4}
        },
       circular sector angle=30,
       shape border uses incircle,
       shape border rotate=\borderrotate,
       anchor=sector center,inner sep=-2mm,%
       minimum size = 6.6cm,
       font=\sffamily
      ] 
   (\monname) at (0,0) {\monname};}
\end{tikzpicture} 
\end{document}

在此处输入图片描述

相关内容