Graphics, Figures & Tables"Call-chain" diagram using xymatrix

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
natskvi
Posts: 7
Joined: Wed Dec 09, 2009 11:59 pm

"Call-chain" diagram using xymatrix

Post by natskvi »

I am trying to produce a simple call-chain diagram (similar to a filesystem diagram) that looks like

Code: Select all

folder
.|
  ---> subfolder
        |
         ---> subsubfolder
The arrows can be curved or angled, I don't care.

My attempts so far culminated in the following:

Code: Select all

\begin{center}
\makebox{
\xymatrix@@!0@@R=2pc@@C=2pc{
    {\phantom{\tt{XX}}} \ar@@/_1pc/[rd] & \tt{HF\_ship\_sim} \\
    & {\phantom{\tt{XX}}} \ar@@/_1pc/[rd] & \tt{AddWakeField} \\
    & & {\phantom{\tt{XX}}} & \tt{CalcWakeFieldVelocity}
}}
\end{center}
Which results in
diagram.jpg
diagram.jpg (7.67 KiB) Viewed 3929 times
There is clearly a major horizontal alignment problem, and a minor vertical alignment problem. What is a better way to do it? I found the dirtree package, but it doesn't allow to display arrows.

Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

"Call-chain" diagram using xymatrix

Post by localghost »

Provide a minimal working example (MWE) that produces the output as shown in the picture. Attach the according log file. And please upload attachments to the forum server.


Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
natskvi
Posts: 7
Joined: Wed Dec 09, 2009 11:59 pm

"Call-chain" diagram using xymatrix

Post by natskvi »

Here is MWE that produces the output:

Code: Select all

\documentclass[11pt]{article}
\usepackage[all]{xy}
\begin{document} 
\xymatrix@!0@R=2pc@C=2pc{
{\phantom{\tt{XX}}} \ar@/_1pc/[rd] & \tt{HF\_ship\_sim} \\
& {\phantom{\tt{XX}}} \ar@/_1pc/[rd] & \tt{AddWakeField} \\
& & {\phantom{\tt{XX}}} & \tt{CalcWakeFieldVelocity}
}
\end{document
Basically, I guess it's a usage issue (knowing how to use XY-Pic package). The problem is that arrows are drawn from the middle of the bottom of the "from" entry, which is why I use \phantom{XX} entries for the source and destination of the arrows as "placeholders" for the actual text stored in the subsequent entry on the same row, and shifted to the left, except it's not quite working...

If I incorporate the text lines in the diagram not as separate entries but rather between \save and \restore and tweak their position via +<x,y> as follows

Code: Select all

\documentclass[11pt]{article}
\usepackage[all]{xy}
\begin{document} 
\xymatrix@!0@R=2pc@C=2pc{
    {\phantom{XX}} \ar@/_1pc/[rd]
        \save[]+<0.8cm,-0.07cm>*\txt<8pc>{\tt{HF\_ship\_sim}}\restore \\
    & {\phantom{XX}} \ar@/_1pc/[rd]
        \save[]+<0.9cm,0cm>*\txt<8pc>{\tt{AddWakeField}}\restore \\
    && {\phantom{XX}}
        \save[]+<1.4cm,0.02cm>*\txt<8pc>{\tt{CalcWakeFieldVelocity}}\restore
}
\end{document}
then the output looks much better
betterimage.jpg
betterimage.jpg (10.5 KiB) Viewed 3910 times
except that it cannot be centered as a figure, because apparently the text between the \save and \restore is not taken into account when computing the dimensions of the enclosing box for purposes of centering.
natskvi
Posts: 7
Joined: Wed Dec 09, 2009 11:59 pm

"Call-chain" diagram using xymatrix

Post by natskvi »

I found a package, xytree

http://www.ctan.org/tex-archive/macros/ ... doc-en.pdf

that can also draw the kind of hierarchical trees that I need. I hope it supports arrows and curved lines.
natskvi
Posts: 7
Joined: Wed Dec 09, 2009 11:59 pm

"Call-chain" diagram using xymatrix

Post by natskvi »

(I keep answering my own questions...)

The following code does the trick:

Code: Select all

\begin{figure}[htbp]
  \begin{center}
    \centerline{
        \yytree[3]{
        \yynode[1]{\tt{HF\_ship\_sim}} \\
        \xyconnect[->](R,L){0,1} & \yynode[1]{\tt{AddWakeField}{\phantom{p}}} \\
        & \xyconnect[->](R,L){0,1} & \yynode{\tt{CalcWakeFieldVelocity}}}
    }
    \caption{Call chain for subroutine}
  \end{center}
\end{figure}
finalversiona.jpg
finalversiona.jpg (7.66 KiB) Viewed 3910 times
yytree macro doesn't draw arrows, but we can place an arrow directly on top of the horizontal portion of the broken line using the command

Code: Select all

\xyconnect[->](R,L){0,1}
Also note that {\phantom{p}} is necessary for consistent vertical alignment of the second entry because it doesn't have any letter (such as g, j, p, q, y) that extends below the baseline.

Happy New Year!
Post Reply