2

I want to parameterize node creation in a foreach. The creation prozess was solved in: Cut part of radialshading out as node shape circular sector

I think the substitution in the foreach has a recognition problem, but otherwise, why get the first node what is expected, i.e. content (\monname) and the shading(rad1)?

Knows anyone a solution?

\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}

Shading will not be assigned

2

There are expansion issues in your code. Basically you cannot store the path in a macro in the way you try to do that. Rather than addressing these issues, I'd propose going another way

\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}

enter image description here

  • The node now is fully parameterizable, thank you. – gizeh Jan 11 at 19:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.