Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.


feat(flow): add dump to jpg
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Oct 11, 2019
1 parent 8ca5ef0 commit 2fb0f4f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
28 changes: 26 additions & 2 deletions gnes/flow/
Expand Up @@ -139,6 +139,12 @@ def from_yaml(orchestration: str) -> 'Flow':

def to_mermaid(self, left_right: bool = True):
Output the mermaid graph for visualization
:param left_right: render the flow in left-to-right manner, otherwise top-down manner.
mermaid_graph = OrderedDict()
for k in self._service_nodes.keys():
mermaid_graph[k] = []
Expand Down Expand Up @@ -166,10 +172,28 @@ def to_mermaid(self, left_right: bool = True):
['graph %s' % ('LR' if left_right else 'TD')] + [ss for s in mermaid_graph.values() for ss in
s] + style + class_def)
'copy-paste the output and visualize it with:')
return mermaid_str

def to_jpg(self, path: str = 'flow.jpg', left_right: bool = True):
Rendering the current flow as a jpg image, this will call :py:meth:`to_mermaid` and it needs internet connection
:param path: the file path of the image
:param left_right: render the flow in left-to-right manner, otherwise top-down manner.
import base64
from urllib.request import Request, urlopen
mermaid_str = self.to_mermaid(left_right)
encoded_str = base64.b64encode(bytes(mermaid_str, 'utf-8')).decode('utf-8')
print('' % encoded_str)'saving jpg...')
req = Request('' % encoded_str, headers={'User-Agent': 'Mozilla/5.0'})
with open(path, 'wb') as fp:

def train(self, bytes_gen: Iterator[bytes] = None, **kwargs):
"""Do training on the current flow
Expand Down
1 change: 1 addition & 0 deletions tests/
Expand Up @@ -113,6 +113,7 @@ def test_flow5(self):

def _test_index_flow(self, backend):
for k in [self.indexer1_bin, self.indexer2_bin, self.encoder_bin]:
Expand Down

0 comments on commit 2fb0f4f

Please sign in to comment.