Skip to content

Commit

Permalink
add click functionnality to flowchart
Browse files Browse the repository at this point in the history
  • Loading branch information
ouhammmourachid committed Nov 2, 2023
1 parent 8e4cc79 commit 29f84b2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ local_settings.py

.env
db.sqlite3
/local/
/local/
.vscode
18 changes: 17 additions & 1 deletion mermaid/flowchart/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,28 @@ class NodeShape:
'double-circle': NodeShape('(((', ')))'),
}

HREF_TYPES: dict[str, str] = {
'blank': '_blank',
'self': '_self',
'parent': '_parent',
'top': '_top'
}


class Node:
def __init__(self,
id_: str,
content: str = '',
shape: str = 'normal',
sub_nodes: list['Node'] = None) -> None:
sub_nodes: list['Node'] = None,
href: str = None,
href_type: str = 'blank') -> None:

self.id_: str = text_to_snake_case(id_)
self.content: str = content if content else id_
self.shape: NodeShape = NODE_SHAPES[shape]
self.href: str = href if href is not None else '#'
self.href_type: str = HREF_TYPES[href_type]
self.sub_nodes: list[
'Node'] = sub_nodes if sub_nodes is not None else []

Expand All @@ -51,4 +62,9 @@ def __str__(self) -> str:
string = ''.join([
self.id_, self.shape.start, f'"{self.content}"', self.shape.end
])
if self.href != '#':
string = ''.join([
string, '\n',
f'click {self.id_} "{self.href}" {self.href_type}'
])
return string
14 changes: 14 additions & 0 deletions mermaid/tests/test_flowchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def test_string_repr_for_node_with_sub_nodes(self):
end"""
self.assertEqual(expect_string, str(node))

def test_string_node_with_href_type_deafult(self):
node: Node = Node('Node Name', href='www.github.com')
expect_string: str = """node_name["Node Name"]
click node_name "www.github.com" _blank"""

self.assertEqual(expect_string, str(node))

def test_string_node_without_href_type_deafult(self):
node: Node = Node('Node Name', href='www.github.com', href_type='top')
expect_string: str = """node_name["Node Name"]
click node_name "www.github.com" _top"""

self.assertEqual(expect_string, str(node))


class TestLink(unittest.TestCase):
def setUp(self) -> None:
Expand Down

0 comments on commit 29f84b2

Please sign in to comment.