Skip to content

Commit

Permalink
Merge pull request #25 from ouhammmourachid/add-click-flowchart
Browse files Browse the repository at this point in the history
add erionattion feature to the flowchart class
  • Loading branch information
ouhammmourachid authored Nov 2, 2023
2 parents a773fd5 + 22ec712 commit fc01ac5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ local_settings.py
.env
db.sqlite3
/local/
.vscode
.vscode/
6 changes: 4 additions & 2 deletions mermaid/flowchart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ class FlowChart(Graph):
def __init__(self,
title: str,
nodes: list[Node] = None,
links: list[Link] = None) -> None:
links: list[Link] = None,
orientation: str = 'TB') -> None:
super().__init__(title, '')
self.orientation: str = orientation
self.nodes: list[Node] = nodes if nodes is not None else []
self.links: list[Link] = links if links is not None else []
self._build_script()

def _build_script(self) -> None:
super()._build_script()
script: str = '\nflowchart'
script: str = f'\nflowchart {self.orientation}'
for node in self.nodes:
script += f'\n\t{node}'
for link in self.links:
Expand Down
27 changes: 25 additions & 2 deletions mermaid/tests/test_flowchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_str_link_with_no_default_value(self):


class TestFlowChart(unittest.TestCase):
def test_make_flowchart_script(self):
def test_make_flowchart_script_with_default_orientation(self):

nodes = [Node('First Node'), Node('Second Node'), Node('Third Node')]
links = [
Expand All @@ -96,7 +96,30 @@ def test_make_flowchart_script(self):
expect_script: str = f"""---
title: simple flowchart
---
flowchart
flowchart TB
\t{nodes[0]}
\t{nodes[1]}
\t{nodes[2]}
\t{links[0]}
\t{links[1]}
"""
self.assertEqual(expect_script, flowchart.script)

def test_make_flowchart_script_without_default_orientation(self):

nodes = [Node('First Node'), Node('Second Node'), Node('Third Node')]
links = [
Link(nodes[0], nodes[1], head_left='cross'),
Link(nodes[1], nodes[2], head_right='bullet')
]
flowchart: FlowChart = FlowChart('simple flowchart',
nodes,
links,
orientation='LR')
expect_script: str = f"""---
title: simple flowchart
---
flowchart LR
\t{nodes[0]}
\t{nodes[1]}
\t{nodes[2]}
Expand Down

0 comments on commit fc01ac5

Please sign in to comment.