Skip to content

Instantly share code, notes, and snippets.

@haitaoyao
Created October 18, 2016 08:56
Show Gist options
  • Save haitaoyao/84cecd77489382454abc469d0f5cd89a to your computer and use it in GitHub Desktop.
Save haitaoyao/84cecd77489382454abc469d0f5cd89a to your computer and use it in GitHub Desktop.
generate svg sequence diagram with seqdiag
def generate_svg_sequence_diagram(text):
"""
:param text:
:return:
"""
tree = parser.parse_string(text)
_, filename = tempfile.mkstemp(suffix='.svg')
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw("SVG", diagram, filename=filename)
draw.draw()
draw.save()
with open(filename) as f:
svg_content = f.read()
os.remove(filename)
return svg_content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment