I'd like to achieve the following effect in a TikZ picture when drawing a straight edge from one node to another. How can I achieve this tapering effect? Notice what happens when an edge exists from A to B and also from B to A (but I suspect this will come for free). This image comes from:
www.win.tue.nl/~dholten/papers/directed_edges_chi.pdf
From "Wedged/tapering paths in TikZ", I was able to hack up something that looked decent, but I was curious if anyone could up with something better.
In particular, I'd like the direction of the tapering reversed. Or at least an API that would allow me to set the direction. Some people might want thick edges at the head and tapered edges at the tail. In the example I provide, I want the thick edge at the head, but the implementation is reversed, so I have to reverse all my edges. It would also be nice if you could specify edges as you do with the \path command:
\path (A) edge [tapered tail] (B);
\path (B) edge [tapered head] (C);
\path (A) edge [tapered tail, <-] (B); % effectively: tapered head
Here is the example:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}
% Need to reverse this!
\pgfdeclaredecoration{triangle}{start}{
\state{start}[width=0.99\pgfdecoratedinputsegmentremainingdistance,next state=up from center]
{\pgfpathlineto{\pgfpointorigin}}
\state{up from center}[next state=do nothing]
{
\pgfpathlineto{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{\pgfdecorationsegmentamplitude}}
\pgfpathlineto{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{-\pgfdecorationsegmentamplitude}}
\pgfpathlineto{\pgfpointdecoratedpathfirst}
}
\state{do nothing}[width=\pgfdecorationsegmentlength,next state=do nothing]{
\pgfpathlineto{\pgfpointdecoratedinputsegmentfirst}
\pgfpathmoveto{\pgfpointdecoratedinputsegmentlast}
}
}
\tikzset{
triangle path/.style={decoration={triangle,amplitude=#1}, decorate},
triangle path/.default=1ex}
\colorlet{mygray}{gray!50}
\pgfdeclarelayer{bg} % declare background layer
\pgfsetlayers{bg,main} % set the order of the layers (main is the standard layer)
\begin{tikzpicture}
\begin{scope}[circle]
\node[draw=gray,fill=mygray] at (0,0) {};
\node[draw=gray,fill=mygray] at (1,2) {};
\node[draw=gray,fill=mygray] at (.3,2.5) {};
\node[draw=gray,fill=mygray] at (0,-2) {};
\node[draw=gray,fill=mygray] at (-3,1) {};
\node[draw=gray,fill=mygray] at (3,1.5) {};
\end{scope}
\begin{pgfonlayer}{bg}
\begin{scope}[color=gray, opacity=.8]
\draw [fill=black!70, triangle path=.7ex] (1,2) -- (0,0);
\draw [fill=black!70, triangle path=.7ex] (.3,2.5) -- (0,0);
\draw [fill=black!70, triangle path=.7ex] (0,-2) -- (0,0);
\draw [fill=black!70, triangle path=.7ex] (0,0) -- (0,-2);
\draw [fill=black!70, triangle path=.7ex] (3,1.5) -- (-3,1);
\end{scope}
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
The resulting image doesn't have quite the same polished look, perhaps its just because I don't have enough edges. Any improvements?
Best Answer
I used a
to path
that just draws a triangle.Simple use is
edge[tapered line=<dir>]
where<dir>
is one of>
,<
orx
and specifies the direction of the triangle(s).You can use the styles of the
/tikz/tapered line/
tree to specify more (widths, style and opacity). These settings can also be used ad hoc on the edge, e.g.It is possible to use either coordinates or nodes. When no anchor is given the
.center
one will used.The same interface can be used with decorations, only the actual path is just
(\tikztostart) -- (\tikztotarget)
that is decorated.Both possible paths (to and from) are enclosed in a scope with a
transparency group
that renders both the drawn line and the filled area better. The following picture shows this:The line going from left to right does not use the transparency group and shows the overlapping of line and area.
On that note, I think a line that is tapered in both directions, an opacity of 50ā% shall be used. Otherwise you will see that one is above the other.
One could these 50ā% in combination with a darker or lighter color or another
transparency group
(only lighter).Iām open for (graphical) ideas for x-tapered lines. One could clip the halves. One could draw both parts in two different paths: one for the inner lines and one for the outer lines. ā¦
Code
Output