Skip to content

Commit a773fd5

Browse files
Merge pull request #24 from ouhammmourachid/add-click-flowchart
add click functionnality to flowchart
2 parents 8e4cc79 + 29f84b2 commit a773fd5

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ local_settings.py
8989

9090
.env
9191
db.sqlite3
92-
/local/
92+
/local/
93+
.vscode

mermaid/flowchart/node.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,28 @@ class NodeShape:
2626
'double-circle': NodeShape('(((', ')))'),
2727
}
2828

29+
HREF_TYPES: dict[str, str] = {
30+
'blank': '_blank',
31+
'self': '_self',
32+
'parent': '_parent',
33+
'top': '_top'
34+
}
35+
2936

3037
class Node:
3138
def __init__(self,
3239
id_: str,
3340
content: str = '',
3441
shape: str = 'normal',
35-
sub_nodes: list['Node'] = None) -> None:
42+
sub_nodes: list['Node'] = None,
43+
href: str = None,
44+
href_type: str = 'blank') -> None:
3645

3746
self.id_: str = text_to_snake_case(id_)
3847
self.content: str = content if content else id_
3948
self.shape: NodeShape = NODE_SHAPES[shape]
49+
self.href: str = href if href is not None else '#'
50+
self.href_type: str = HREF_TYPES[href_type]
4051
self.sub_nodes: list[
4152
'Node'] = sub_nodes if sub_nodes is not None else []
4253

@@ -51,4 +62,9 @@ def __str__(self) -> str:
5162
string = ''.join([
5263
self.id_, self.shape.start, f'"{self.content}"', self.shape.end
5364
])
65+
if self.href != '#':
66+
string = ''.join([
67+
string, '\n',
68+
f'click {self.id_} "{self.href}" {self.href_type}'
69+
])
5470
return string

mermaid/tests/test_flowchart.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ def test_string_repr_for_node_with_sub_nodes(self):
3838
end"""
3939
self.assertEqual(expect_string, str(node))
4040

41+
def test_string_node_with_href_type_deafult(self):
42+
node: Node = Node('Node Name', href='www.github.com')
43+
expect_string: str = """node_name["Node Name"]
44+
click node_name "www.github.com" _blank"""
45+
46+
self.assertEqual(expect_string, str(node))
47+
48+
def test_string_node_without_href_type_deafult(self):
49+
node: Node = Node('Node Name', href='www.github.com', href_type='top')
50+
expect_string: str = """node_name["Node Name"]
51+
click node_name "www.github.com" _top"""
52+
53+
self.assertEqual(expect_string, str(node))
54+
4155

4256
class TestLink(unittest.TestCase):
4357
def setUp(self) -> None:

0 commit comments

Comments
 (0)