如何让箭头附着到图形绘制布局中矩形分割的外部?

如何让箭头附着到图形绘制布局中矩形分割的外部?

我正在尝试使用较新的(pgf > 3.0)绘图布局来绘制类图,但我似乎无法弄清楚如何将箭头附加到矩形分割的轮廓上。我在以下文档中阅读了有关矩形分割的锚点的信息https://www.ctan.org/pkg/pgf,但我不知道如何使用它们。

基本上,在下面的例子中,箭头应该附着在矩形分割的外部。我不知道为什么它们附着在中间的“两个”框上。有什么想法吗?

例子

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows,shapes.multipart}
\usegdlibrary{layered}
\begin{document}

\tikzset{object/.style={draw, rectangle split, rectangle split parts=3,
    rounded corners, rectangle split part align={center,left,left}},
    align=left}
\def \properties {\nodepart{two}}
\def \methods {\nodepart{three}}

\begin{tikzpicture} [layered layout, >=latex]

\node(obj)[object] {
obj
\properties
+property: class
\methods
method(inputs): outputs};

\node(foo)[object] {
foo
\properties
ids: cell array\\
xyz: Nx3 array
\methods
compute():\\
plot(): handle
};

\node(bar)[object] {
bar
\properties
ids: cell array\\
xyz: Nx3 array
\methods
compute():\\
plot(): handle
};

\graph[use existing nodes]
{
(obj) -> (foo);
(foo) -> [>=open diamond] (bar);
};

\end{tikzpicture}
\end{document}

答案1

Forest 不绘制图形,但它会自动排列树中的节点,并且用于指定内容的语法可以(几乎)像您希望的那样紧凑。

object tree保留了用于指定节点内容的大部分当前语法:

\begin{forest}
  object tree
  [obj \properties +property: class \methods method(inputs): outputs
    [foo \properties ids: cell array\\
    xyz: Nx3 array \methods compute():\\
    plot(): handle
      [bar \properties ids: cell array\\
      xyz: Nx3 array \methods compute():\\
      plot(): handle, edge+=-open diamond
      ]
    ]
  ]
\end{forest}

object tree auto使用|作为分隔符将各个节点的内容分割为垂直分割节点的三个部分:

\begin{forest}
  object tree auto
  [obj | +property: class | method(inputs): outputs
    [foo | ids: cell array\\
    xyz: Nx3 array | compute():\\
    plot(): handle
      [bar | ids: cell array\\
      xyz: Nx3 array | compute():\\
      plot(): handle, edge+=-open diamond
      ]
    ]
  ]
\end{forest}

两种情况下的输出相同:

类图作为森林树?

完整代码:

\documentclass[border=5pt]{standalone}
% ateb: https://tex.stackexchange.com/a/704954/ addaswyd o gwestiwn Nick: https://tex.stackexchange.com/q/233419/
\usepackage{forest}
\usetikzlibrary{arrows,shapes.multipart}
\tikzset{object/.style={draw,  rectangle split, rectangle split parts=3,
    rounded corners, rectangle split part align={center,left,left}},
    align=left}
\def \properties {\nodepart{two}}
\def \methods {\nodepart{three}}

\forestset{%
  object tree/.style={%
    for tree={object,edge+={-latex},l sep*=1.5}
  },
  object tree auto/.style={
    object tree,
    before typesetting nodes={%
      for tree={%
        temptoksb=,
        split option={content}{|}{content',temptoksa,temptoksb},
        content+={\properties},
        content+/.register=temptoksa,
        content+={\methods},
        content+/.register=temptoksb,
      },
    },
  },
}
\begin{document}

\begin{forest}
  object tree
  [obj \properties +property: class \methods method(inputs): outputs
    [foo \properties ids: cell array\\
    xyz: Nx3 array \methods compute():\\
    plot(): handle
      [bar \properties ids: cell array\\
      xyz: Nx3 array \methods compute():\\
      plot(): handle, edge+=-open diamond
      ]
    ]
  ]
\end{forest}
\begin{forest}
  object tree auto
  [obj | +property: class | method(inputs): outputs
    [foo | ids: cell array\\
    xyz: Nx3 array | compute():\\
    plot(): handle
      [bar | ids: cell array\\
      xyz: Nx3 array | compute():\\
      plot(): handle, edge+=-open diamond
      ]
    ]
  ]
\end{forest}

\end{document}

相关内容