How to force the edge to bend in GraphViz?

Viewed 2361

I had been trying to do what I thought was a simple thing in Graphviz, something like this:

enter image description here

And I am trying to do something similar with Graphviz, this is how it looks right now:

enter image description here

How can I force the edge to bend in GraphViz?

This is my code so far:

digraph {
  graph [rankdir = LR]
  node [shape=box]
  X1;X2;a[label='X1*X2'];Y
  {X1,X2,a}->Y[arrowsize=0.5]

  X1->X2[constraint=false dir=both arrowsize=0.5] 
  X2->a[constraint=false dir=both arrowsize=0.5] 
  a->X1[constraint=false dir=both arrowsize=0.5]
}
1 Answers

GraphViz

I would have also suggested to use the compass functionality of graphviz by adding :w to the edges:

digraph {
  graph [rankdir = LR]
  node [shape=box]
  X1;X2;a[label="X1*X2"];Y
  {X1,X2,a}->Y[arrowsize=0.5]

  X1:w->X2:w[constraint=false dir=both arrowsize=0.5] 
  X2:w->a:w[constraint=false dir=both arrowsize=0.5] 
  a:w->X1:w[constraint=false dir=both arrowsize=0.5]
}

enter image description here

However, graphviz does not provide a possibility to adjust the default port locations for dot - graphviz version 2.40.1 (20161225.0304) (afaik). And in your case I think this is what you want to do.

yEd

The free, but not open-source, gui tool yEd supports this:

enter image description here

PSTricks & pst-node

If you do not mind to use something from the LaTeX world, here is a solution using pstricks and the package pst-node:

% ! TEX program = pdflatex -shell-escape
\documentclass{standalone}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}
\usepackage{pst-node}

\begin{document}
\begin{pspicture}
    \psset{linewidth=.3pt}
    \rput(0,3){\rnode{A}{\psframebox{\makebox[1.1cm]{$X_1$}}}}
    \rput(0,2){\rnode{B}{\psframebox{\makebox[1.1cm]{$X_2$}}}}
    \rput(0,1){\rnode{C}{\psframebox{\makebox[1.1cm]{$X_1*X_2$}}}}
    \rput(2,2){\rnode{D}{\psframebox{\makebox[1.1cm]{$Y$}}}}

    \psset{angleA=0, angleB=180, arm=0}
    \ncdiag[offsetB=+3pt]{->}{A}{D}
    \ncdiag[offsetB=+0pt]{->}{B}{D}
    \ncdiag[offsetB=-3pt]{->}{C}{D}

    \psset{offset=3pt, angle=180, linearc=.25, armB=12pt}
    \ncangle{<->}{A}{B}
    \ncangle{<->}{B}{C}
    \ncangle[linearc=.3333, armB=18pt]{<->}{C}{A}
\end{pspicture}
\end{document}

Compiling this document to pdf with $ pdflatex -shell-escape <filename> gives you

enter image description here

Tikz

Finally, a tikz solution

\documentclass[tikz]{standalone}
\tikzset{>=stealth} % nicer default arrow tip
\begin{document}
\begin{tikzpicture}[every node/.style={rectangle,draw,minimum width=1.5cm}]

    \node (a) at (0,2) {$X_1$};
    \node (b) at (0,1) {$X_2$};
    \node (c) at (0,0) {$X_1*X_2$};
    \node (d) at (2.5,1) {$Y$};

    \tikzset{every edge/.append style={->}}
    \path (a.east) edge ([yshift=+3pt]d.west);
    \path (b.east) edge ([yshift=+0pt]d.west);
    \path (c.east) edge ([yshift=-3pt]d.west);

    \tikzset{out=-180,in=180,every edge/.append style={<->,looseness=1.5}}
    \path ([yshift=-3pt]a.west) edge ([yshift=+3pt]b.west);
    \path ([yshift=-3pt]b.west) edge ([yshift=+3pt]c.west);
    \path ([yshift=+3pt]a.west) edge ([yshift=-3pt]c.west);

\end{tikzpicture}
\end{document}

enter image description here

Related