Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add click functionnality to flowchart #24

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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