# Add bars and annotations when using pgf-umlsd

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}


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.

-
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

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

% message between threads
% Example:
\newcommand{\mess}[4][0]{
\stepcounter{seqlevel}
\path
(#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
\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 messages 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}
\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

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}

% Example:
\renewcommand{\mess}[5][0]{
\stepcounter{seqlevel}
\path
(#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
\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}


-
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