Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate uml sequence diagrams with python or perl

I have some text which I will process to generate a uml sequence diagram image. I can process the text in python or perl into a format of an existing 'text to uml' tools but I'm trying to eliminate that extra step and give the image output directly from the python/perl script.

Are there any python or perl packages/modules I can use?

like image 252
none Avatar asked Oct 30 '12 09:10

none


2 Answers

There are many Python alternatives.

If you want to generate images from scratch, you may want to consider PIL (Python Imaging Library), the "de facto" image library for Python.

However, for sequence diagrams in particular, the blockdiag diagram images generator library (that uses PIL as well) includes a sequence diagram generator called seqdiag. For example, here's how to define & produce a simple but complete sequence diagram, including the diagram definition:

from seqdiag import parser, builder, drawer

diagram_definition = u"""
   seqdiag {
      browser  -> webserver [label = "GET /index.html"];
      browser <- webserver;
   }
"""
tree = parser.parse_string(diagram_definition)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('PNG', diagram, filename="diagram.png")
draw.draw()
draw.save()

See http://blockdiag.com/en/seqdiag/examples.html for some more example (sequence) diagram definitions and styling options.

like image 189
Petri Avatar answered Oct 06 '22 01:10

Petri


There are several perl modules which do this in Perl, see UML::State.

From the synopsis:

use UML::State;

my $diagram = UML::State->new(
  $node_array,
  $start_list,
  $accept_list,
  $edges
);

# You may change these defaults (doing so may even work):
$UML::State::ROW_SPACING = 75;  # all numbers are in pixels
$UML::State::LEFT_MARGIN = 20;
$UML::State::WIDTH       = 800;
$UML::State::HEIGHT      = 800;

print $diagram->draw(); 

CPAN is your friend.:)

like image 21
Daniel Gratzer Avatar answered Oct 06 '22 00:10

Daniel Gratzer