如何强制边缘在 GraphViz 中弯曲?

Keo*_*oon 4 graph-theory graphviz

我一直在尝试在 Graphviz 中做我认为很简单的事情,如下所示:

在此处输入图片说明

我正在尝试用 Graphviz 做类似的事情,这就是它现在的样子:

在此处输入图片说明

如何在 GraphViz 中强制边缘弯曲?

到目前为止,这是我的代码:

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]
}
Run Code Online (Sandbox Code Playgroud)

Hot*_*hke 5

图形可视化

我还建议通过添加:w到边缘来使用 graphviz 的指南针功能:

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]
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但是,graphviz 不提供调整dot - graphviz version 2.40.1 (20161225.0304)(afaik)的默认端口位置的可能性。在你的情况下,我认为这就是你想要做的。

免费但非开源的 gui 工具yEd支持:

在此处输入图片说明

PSTricks 和 pst 节点

如果你不介意使用 LaTeX 世界中的东西,这里有一个使用 pstricks 和包 pst-node 的解决方案:

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]
}
Run Code Online (Sandbox Code Playgroud)

将此文档编译为 pdf$ pdflatex -shell-escape <filename>为您提供

在此处输入图片说明

提克兹

最后,一个tikz解决方案

% ! 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}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明