I'm making a network diagram with shaped arrows that go the whole length of the path, rather than just being a line with an arrow on the end.
Because the bend
option is so easy to use, I chose to do this with arrows, rather than decorations.
The code below works for me. I could use it as-is, but there are a couple of things that seem kind of hackish.
1) Using a global length to store the original path length by using a preaction
decoration seems like a hack, albeit somewhat clever. Is there a better (cleaner, less hackish) way of getting the original path length?
2) The bounding box for the arrow (as defined by the convex hull in the arrow definition) isn't right for the bent arrow. Is there any way to fix this? I tried using \pgfusepath{use as bounding box}
, but that's not available in the drawing code (as specified in the manual).
\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}
\usetikzlibrary{decorations}
\newlength{\mypathlength}
\pgfdeclaredecoration{stashlength}{final}{
\state{final}{
\setlength{\mypathlength}{\pgfdecoratedpathlength}
\global\mypathlength=\mypathlength}}
\pgfdeclarearrow{
name = foo,
parameters = {%
\the\pgfarrowlength
},
setup code = {%
% The different end values:
\pgfarrowssettipend{.25\pgfarrowlength}
\pgfarrowssetlineend{-.25\pgfarrowlength}
\pgfarrowssetvisualbackend{-.5\pgfarrowlength}
\pgfarrowssetbackend{-.75\pgfarrowlength}
% The hull
\pgfarrowshullpoint{.25\pgfarrowlength}{0pt}%
\pgfarrowsupperhullpoint{-.75\pgfarrowlength}{.5\pgfarrowlength}%
\pgfarrowsupperhullpoint{-\mypathlength}{-.5\pgfarrowlength}% doesn't create the right bounding box
% Saves: Only the length:
\pgfarrowssavethe\pgfarrowlength
},
drawing code = {%
\pgfpathmoveto{\pgfqpoint{.25\pgfarrowlength}{0pt}}
\pgfpathlineto{\pgfpoint{-\mypathlength-.25\pgfarrowlength}{.5\pgfarrowlength}}
\pgfpathlineto{\pgfpoint{-\mypathlength}{0pt}}
\pgfpathlineto{\pgfpoint{-\mypathlength-.25\pgfarrowlength}{-.5\pgfarrowlength}}
\pgfpathclose
%\pgfusepath{use as bounding box} %won't work as described in the manual (page 1019) -- would try to add arrows recursively
\pgfusepathqstroke
},
defaults = {%
length = 4cm
},
}
\begin{document}
\begin{tikzpicture}
%comment the next line out to see bounding box problems
\node at (0,2) {Used to save space for arrow};
\draw [-{foo[bend]},preaction={decorate,decoration=stashlength}] (0,0) to [bend right] (8,0);
%\draw[-{foo[length=15pt]},preaction={decorate,decoration=stashlength}] (0,0) -- (8,0);
\end{tikzpicture}
\end{document}