-
Notifications
You must be signed in to change notification settings - Fork 556
Description
Is your feature request related to a problem? Please describe.
My program has a REST API and returns data in JSON. I'd like to also return the state diagram rendered using transitions get_graph().draw(). Currently, the get_graph().draw() method firstly writes the rendered state diagram to local filesystem, from where I read it, base64 encode it and return it in response to a GET request.
Describe the solution you'd like
Render the diagram but don't write it to disk, instead return the stream, or better still directly base64 encode it, thus eliminating the two-step procedure of first writing a file and then reading that file for encoding and returning in the API.
Additional context
Add any other context or screenshots about the feature request here.
Current implementation is as follows; it works but note the two steps: first create the file , then read it and base64 encode it. It would be great if the file were not written to the filesystem but directly returned by the draw() method.
@property
def state_diagram(self):
filename = uuid.uuid4().hex
self._sm.get_graph(show_roi=True).draw(filename, prog='dot')
with open(filename, mode='rb') as f:
content = f.read()
d = {'name' : self.name,
'filename' : self.name + '_state_diagram.png',
'mimetype' : 'image/png',
'encoding' : 'base64',
'value' : b64encode(content).decode()}
os.remove(filename)
return d