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

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

"Call-chain" diagram using xymatrix

Postby natskvi » Thu Dec 31, 2009 4:43 am

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

  1. folder
  2. .|
  3. ---> subfolder
  4. |
  5. ---> subsubfolder


The arrows can be curved or angled, I don't care.

My attempts so far culminated in the following:

  1. \begin{center}
  2. \makebox{
  3. \xymatrix@@!0@@R=2pc@@C=2pc{
  4. {\phantom{\tt{XX}}} \ar@@/_1pc/[rd] & \tt{HF\_ship\_sim} \\
  5. & {\phantom{\tt{XX}}} \ar@@/_1pc/[rd] & \tt{AddWakeField} \\
  6. & & {\phantom{\tt{XX}}} & \tt{CalcWakeFieldVelocity}
  7. }}
  8. \end{center}


Which results in
diagram.jpg
diagram.jpg (7.67 KiB) Viewed 2112 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.

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Thu Dec 31, 2009 2:20 pm

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¹
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby natskvi » Fri Jan 01, 2010 12:47 am

Here is MWE that produces the output:

  1. \documentclass[11pt]{article}
  2. \usepackage[all]{xy}
  3. \begin{document}
  4. \xymatrix@!0@R=2pc@C=2pc{
  5. {\phantom{\tt{XX}}} \ar@/_1pc/[rd] & \tt{HF\_ship\_sim} \\
  6. & {\phantom{\tt{XX}}} \ar@/_1pc/[rd] & \tt{AddWakeField} \\
  7. & & {\phantom{\tt{XX}}} & \tt{CalcWakeFieldVelocity}
  8. }
  9. \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

  1. \documentclass[11pt]{article}
  2. \usepackage[all]{xy}
  3. \begin{document}
  4. \xymatrix@!0@R=2pc@C=2pc{
  5. {\phantom{XX}} \ar@/_1pc/[rd]
  6. \save[]+<0.8cm,-0.07cm>*\txt<8pc>{\tt{HF\_ship\_sim}}\restore \\
  7. & {\phantom{XX}} \ar@/_1pc/[rd]
  8. \save[]+<0.9cm,0cm>*\txt<8pc>{\tt{AddWakeField}}\restore \\
  9. && {\phantom{XX}}
  10. \save[]+<1.4cm,0.02cm>*\txt<8pc>{\tt{CalcWakeFieldVelocity}}\restore
  11. }
  12. \end{document}


then the output looks much better
betterimage.jpg
betterimage.jpg (10.5 KiB) Viewed 2093 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

Postby natskvi » Fri Jan 01, 2010 1:28 am

I found a package, xytree

http://www.ctan.org/tex-archive/macros/latex/contrib/xytree/xytree-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

Postby natskvi » Fri Jan 01, 2010 3:43 am

(I keep answering my own questions...)

The following code does the trick:

  1. \begin{figure}[htbp]
  2. \begin{center}
  3. \centerline{
  4. \yytree[3]{
  5. \yynode[1]{\tt{HF\_ship\_sim}} \\
  6. \xyconnect[->](R,L){0,1} & \yynode[1]{\tt{AddWakeField}{\phantom{p}}} \\
  7. & \xyconnect[->](R,L){0,1} & \yynode{\tt{CalcWakeFieldVelocity}}}
  8. }
  9. \caption{Call chain for subroutine}
  10. \end{center}
  11. \end{figure}

finalversiona.jpg
finalversiona.jpg (7.66 KiB) Viewed 2093 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

  1. \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!


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 4 guests