简体   繁体   中英

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM