0

I'm trying to draw the following dataflow diagram in tikz:

enter image description here

Here is what I got so far:

\documentclass[10pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\usepackage{tikz} \usetikzlibrary{decorations.markings,positioning,petri}

\begin{document} \begin{tikzpicture}[thick, node distance=2cm, on grid, every transition/.style={fill=black,minimum width=.1cm, minimum height=0.9cm}, every label/.style={black!75}] node distance=2cm, on grid, every transition/.style={fill=black,minimum width=.1cm, minimum height=0.9cm}, every label/.style={black!75}] \node[place, label=above:$n_1$] (n1) {+}; \node[place, right=of n1, label=above:$n_2$] (n2) {$\times 2$}; \node[place, right=of n2, label=above:$n_3$] (n3) {+}; \node[place, below=of n2, label=above:$n_4$] (n4) {+1}; \node[place, right=of n3, label=above:$n_5$] (n5) {$\Delta(0)$}; \node[right of=n5] (x) {X}; \node[below of=n5] (y) {Y}; \node[left of=n1] (i) {Input};

\draw[->] (n1) edge (n2.west); \draw[->] (n2) edge (n3.west); \draw[->, to path={-| (\tikztotarget)}] (n4) edge (n3.south); \draw[->] (n3) edge (n5.west); \draw[->] (n5) edge (x); \draw[->] (n4) edge (y); \draw[->] (i) edge (n1.west); \draw[->, to path={|- (\tikztotarget)}] (i) edge (n4.west); \end{tikzpicture} \end{document}

As you can see, drawing the nodes work fine but I'm having trouble getting the edges right. I want the edges to be angled and also there to be dots so it's clear where the flow branches.

I updated my code with edge drawing commands. I still cannot get the feedback edge right nor do I get dots where the edges branches.

1 Answers1

2

Try the following:

%\documentclass[10pt,a4paper]{article}
\documentclass[border=3.141592mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                decorations.markings,
                positioning,
                shadows, }

\begin{document} \begin{tikzpicture}[ node distance = 7mm and 11mm, start chain = A going right, C/.style = {circle, minimum size=11mm, inner sep=1pt, outer sep=0pt, draw, semithick, fill=gray!30}, dot/.style = {circle, fill, inner sep=2pt, outer sep = 0pt, node contents={}}, every label/.style = {font=\small\sffamily}, every path/.style = {-Straight Barb} ] \coordinate[label=above right:input] (in); \node (d1) [dot, right=of in]; \begin{scope}[nodes = {C, on chain=A, join=by ->}] \node (n1) [C, right=of d1] {+}; % A-1 \node (n2) [C] {$\times 2$}; \node (n3) [C] {+}; \node (n4) [C] {$\Delta(0)$}; % A-4 \end{scope} \node (d2) [dot, right=of A-4]; \coordinate[right=of d2, label=above left:X] (x); % \node (A-5) [C, below=of A-2] {+1}; \node (d3) [dot, at={(A-5 -| A-3)}]; \coordinate[right=of d3, label=above left:Y] (y); % \draw (d2) |- ([yshift=7mm] A-1.north) edge (A-1) (in) to (A-1) (d3) edge (A-3) (A-4) edge (x) (A-5) edge (y); \draw (d1) |- (A-5); \end{tikzpicture} \end{document}

enter image description here

Edit: Ar adding labels the chain had to be handled different as above: it should be add to C nodes style. Doing this, macro join had to be interrupted because it should not connect last Cnode in code with others. In this case thescope` is not needed anymore.

\documentclass[border=3.141592mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                chains,
                positioning}
\makeatletter
\tikzset{suspend join/.code={\def\tikz@after@path{}}}
\makeatother

\begin{document} \begin{tikzpicture}[ node distance = 7mm and 11mm, start chain = going right, C/.style = {circle, minimum size=11mm, inner sep=1pt, outer sep=0pt, draw, semithick, fill=gray!30, drop shadow, on chain, join= by ->}, dot/.style = {circle, fill, inner sep=2pt, outer sep = 0pt, node contents={}}, every label/.style = {label distance=5pt, inner sep=1pt, font=\small\sffamily, fill=white}, every path/.style = {-Straight Barb} ] \coordinate[label=above right:input] (in); \node (d1) [dot, right=of in]; \node (n1) [C,label=$n_1$, right=of d1] {+};
\node (n2) [C,label=$n_2$] {$\times 2$}; \node (n3) [C,label=$n_3$] {+}; \node (n4) [C,label=$n_4$] {$\Delta(0)$}; \node (d2) [dot, on chain]; \coordinate[on chain, label=above left:X] (x); \node (n5) [C, suspend join, below=of n2, label=$n_5$] {+1}; \node (d3) [dot, at={(n5 -| n3)}]; \coordinate[right=of d3, label=above left:Y] (y); % \scoped[on background layer] \draw (d2) |- ([yshift=7mm] n1.north) edge (n1) (in) to (n1) (d3) edge (n3) (n4) edge (x) (n5) edge (y); \draw (d1) |- (n5); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517