2.7.2. Sequence Diagram

sphinxcontrib-seqdiag is a Sphinx extension for embedding sequence diagrams. You can embed sequence diagrams with the .. seqdiag:: directive.

PyPI Package

https://pypi.org/project/sphinxcontrib-seqdiag/

Documentation

http://blockdiag.com/en/seqdiag/sphinxcontrib.html

Git Repository

https://github.com/blockdiag/sphinxcontrib-seqdiag

Sphinx extension for embedding sequence diagrams using seqdiag.

Features
  1. Generate sequence-diagram from dot like text (basic feature).

  2. Multilingualism for node-label (utf-8 only).

Directive Body Diagram

.. seqdiag::

For more details, see sphinxcontrib-seqdiag in the extension demonstration and the README.rst in the extension Git repository.

The example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
.. seqdiag::
   :align: center

   seqdiag {
       # define order of elements
       # seqdiag sorts elements by order they appear
       browser; database; webserver;

       browser  -> webserver [label = "GET /index.html"];
       browser <-- webserver;
       browser  -> webserver [label = "POST /blog/comment"];
                   webserver  -> database [label = "INSERT comment"];
                   webserver <-- database;
       browser <-- webserver;
   }
Which gives
blockdiag browser database webserver GET /index.html POST /blog/comment INSERT comment

Description Table

the example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
.. seqdiag::
   :align: center
   :desctable:

   seqdiag {
       A -> B -> C;
       A [description = "browsers in each client"];
       B [description = "web server"];
       C [description = "database server"];
   }
which gives
blockdiag A B C

Name

Description

A

browsers in each client

B

web server

C

database server

Include Diagram

the example
1
2
3
4
.. seqdiag:: seqdiag/example.diag
   :caption: Style attributes to diagram and edges (Sequence Diagram example)
   :align: center
   :height: 480
which gives
blockdiag browser webserver Apache works! 1. GET /index.html 2. 3. misformatted 4. failed browser Separator line

Figure 2.47 Style attributes to diagram and edges (Sequence Diagram example)

which needs

The example above comes from the original Sample diagrams web page and processed the following file content:

Listing 2.6 Sequence Diagram example file (seqdiag/example.diag)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
seqdiag {
    // Set edge metrix.
    edge_length = 300;  // default value is 192
    span_height = 80;  // default value is 40

    // Set fontsize.
    default_fontsize = 16;  // default value is 11

    // Do not show activity line
    activation = none;

    // Numbering edges automaticaly
    autonumber = True;

    // Change note color
    default_note_color = lightgreen;

    browser  -> webserver [label = "GET \n/index.html"];
    browser <-- webserver [note = "Apache works!"];

    // Separator
    === Separator line ===

    // color of edge
    browser -> webserver [label = "misformatted", color = red];

    // failed edge
    browser -> webserver [label = "failed browser", failed];
}