Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using pgf-umlsd to draw a messaging diagram. At the moment, it looks like this:

\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows, arrows.new}
\usepackage[underline=false]{pgf-umlsd}
\begin{document}

\begin{figure}[H]
    \centering
    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \mess[1]{c}{A}{s}
        \mess[1]{s}{B}{c}
        \mess[1]{c}{A}{s}
        \mess[1]{s}{B}{c}
        \mess[1]{c}{...}{s}
        \mess[1]{s}{...}{c}
        \stepcounter{seqlevel}
        \mess[1]{s}{C}{c}

    \end{sequencediagram}
    \caption{Client-Server messaging}
\end{figure}
\end{document}

enter image description here

I wonder how to do the following based on what I have:

  1. Add vertical bar on the line below Server to cover the distance between an incoming arrow and an outgoing one.

  2. To the right of each bar, add text annotation to describe what the server does between receiving a particular message and sending out another.

  3. Add 3 vertical dots right above message C to denote that more exchanges of messages A and B occur before Server sends C.

I looked through the manual of pgf-umlsd, but didn't find any example of such drawing.

share|improve this question
    
Your code does not compile as it is. Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Claudio Fiandrino Jan 20 at 8:36
    
@ClaudioFiandrino, thanks for the reminder. I have amended the code to show the complete example. –  Skyork Jan 20 at 15:21
add comment

1 Answer 1

up vote 1 down vote accepted

All you need is in pgf-umlsd.sty code. Next is \mess declaration in v0.7.

% message between threads
% Example:
% \mess[delay]{sender}{message content}{receiver}
\newcommand{\mess}[4][0]{
  \stepcounter{seqlevel}
  \path
  (#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
  \addtocounter{seqlevel}{#1}
  \path
  (#4)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess to) {};
  \draw[->,>=angle 60] (mess from) -- (mess to) node[midway, above]
  {#3};

  \node (#3 from) at (mess from) {};
  \node (#3 to) at (mess to) {};
}

This command draws an arrow (with a possible label (parameter #3) and certain delay (optional parameter #1)) between to threads (parameter #2 and parameter #4). Finally, and that's good for you, it declares to nodes (#3 from) at message's origin and (#3 to) at message`s end.

This means that after \mess[1]{c}{A}{s} you can use nodes A from and A to to add some comments with:

\node[left=0mm of A from] {First message};         
\node[right=0mm of A to] {First message received}; 

Be careful because if you use the same comment/label for two or more messages only the last message can be referenced with nodes. In your example, all comments must be added just after the message.

Same nodes can be used to draw a line between messages arrivals and departures.

The solution for your last problem was to place dots with the help of previous (C from) and (C to) nodes.

The complete code looks like this

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgf-umlsd}
\usetikzlibrary{shadows,positioning}
\begin{document}

    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \mess[1]{c}{A}{s}
        \node[left=0mm of A from] {First message};         
        \node[right=0mm of A to] {First message received}; 
        \mess[1]{s}{B}{c}
        \node[right=0mm of B from] {Ack to First message}; 
        \draw[line width=3pt] (A to) -- (B from);
        \mess[1]{c}{A}{s}
        \node[right=0mm of A to] {Something else happens here}; 
        \mess[1]{s}{B}{c}
        \mess[1]{c}{...}{s}
        \mess[1]{s}{...}{c}
        \stepcounter{seqlevel}
        \mess[1]{s}{C}{c}
        \path(C from) -- (C to) node[midway, above=1cm]
  {\vdots};

    \end{sequencediagram}
\end{document}

And the result is

enter image description here

Update

If you want to change the font (or any other parameter) for comments added via \node, just add it in node options, i.e., \node[right=0mm of A to, font=\small\ttfamily] {Something else happens here};.

But if you need to change font options for message content you need to change \mess command declaration. In next code, I've added a fifth parameter to \mess which will be used to set node options for message content. My example shows how to do it with explicit options, but you can declare some style and use it there. As you can see, even with no changes, you need to include an empty fifth parameter in every \mess command.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgf-umlsd}
\usetikzlibrary{shadows,positioning}

% message between threads
% Example:
% \mess[delay]{sender}{message content}{receiver}
\renewcommand{\mess}[5][0]{
  \stepcounter{seqlevel}
  \path
  (#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
  \addtocounter{seqlevel}{#1}
  \path
  (#4)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess to) {};
  \draw[->,>=angle 60] (mess from) -- (mess to) node[midway, above,#5]
  {#3};

  \node (#3 from) at (mess from) {};
  \node (#3 to) at (mess to) {};
}

\begin{document}

    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \mess[1]{c}{A}{s}{font=\Large, text=red}
        \node[left=0mm of A from] {First message};         
        \node[right=0mm of A to] {First message received}; 
        \mess[1]{s}{B}{c}{}
        \node[right=0mm of B from] {Ack to First message}; 
        \draw[line width=3pt] (A to) -- (B from);
        \mess[1]{c}{A}{s}{font=\itshape, draw=blue}
        \node[right=0mm of A to, font=\small\ttfamily] {Something else happens here}; 
        \mess[1]{s}{B}{c}{}
        \mess[1]{c}{...}{s}{}
        \mess[1]{s}{...}{c}{}
        \stepcounter{seqlevel}
        \mess[1]{s}{C}{c}{}
        \path(C from) -- (C to) node[midway, above=\unitfactor]
  {\vdots};

    \end{sequencediagram}
\end{document}

enter image description here

share|improve this answer
    
thanks a lot for the detailed explanation! A quick follow-up question: how can I configure the font size of annotation? Is this done via tikz rather than pgf-umlsd? –  Skyork Jan 21 at 3:27
1  
@Skyork Glad to help you. Please, look at updated answer. –  Ignasi Jan 21 at 8:08
    
that's more than what I asked for. Thanks a lot! –  Skyork Jan 21 at 18:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.