I'm trying to override the color key within a pic but not within the enclosing scope (That is the path/draw/fill instruction).
My objective is to be able to set the colour for a path and have this affect the pic as well. That is the pic might have a custom shading and I would like this shading to adopt the paths colour as a tint. One should, however, still be allowed to override the local colour for the pic.
The example shows how I think it should be coded based upon the documentation but the filter is not working as I'd expected. Within the example I create a local name space /tikz/example
as originally the 'color' style was clobbering the /tikz/color
key. Filtering also needs a family to work with.
My understanding of filtering is that one ought to create/register the filter, in this case tikz/example
, and then activate it when necessary i.e. before and after pic actions
is executed.
The output I expect to see is the backround block in white with a blue line, overlaid by the three smaller blocks each shaded in blue, red and green.
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\tikzset{
basis/.initial=1em,
block/.is family,
/tikz/pic actions/.install key filter=block,
block/.pic={
\draw[block/.activate family, pic actions, block/.deactivate family]
let \n{basis}={\pgfkeysvalueof{/tikz/basis}} in
(-\n{basis},-\n{basis}) rectangle (\n{basis},\n{basis});
},
block/.cd,
colour/.style={/tikz/top color =#1!50!white,
/tikz/bottom color=#1!50!black},
}
\begin{document}
\begin{tikzpicture}
\draw[color=blue]
( 0, 0) pic {block}
(-1,-1) pic[color=green] {block}
rectangle
(1,1) pic[color=red] {block};
\end{tikzpicture}
\end{document}