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.:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With