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).

Todo

activate “Sequence Diagram” extension.

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:

   .. include:: seqdiag-directive-body-example.rsti

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:

   .. include:: seqdiag-description-table-example.rsti

Include Diagram

the example
1
2
3
4
.. seqdiag:: seq.diag
   :caption: Style attributes to diagram and edges (Sequence Diagram example)
   :align: center
   :height: 640
:which gives:

   .. seqdiag:: seq.diag
      :caption: Style attributes to diagram and edges (Sequence Diagram example)
      :align: center
      :height: 640
which needs

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

Listing 2.3 Sequence Diagram example file (seq.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];
}