@@ -1430,6 +1430,7 @@ def get_list_of_text_dimensions(
14301430def tree_to_mermaid (
14311431 tree : T ,
14321432 title : str = "" ,
1433+ theme : Optional [str ] = None ,
14331434 rankdir : str = "TB" ,
14341435 line_shape : str = "basis" ,
14351436 node_colour : str = "" ,
@@ -1447,6 +1448,7 @@ def tree_to_mermaid(
14471448
14481449 Parameters for customizations that apply to entire flowchart include:
14491450 - Title, `title`
1451+ - Theme, `theme`
14501452 - Layout direction, `rankdir`
14511453 - Line shape or curvature, `line_shape`
14521454 - Fill colour of nodes, `node_colour`
@@ -1465,6 +1467,13 @@ def tree_to_mermaid(
14651467
14661468 **Accepted Parameter Values**
14671469
1470+ Possible theme:
1471+ - default
1472+ - neutral: great for black and white documents
1473+ - dark: great for dark-mode
1474+ - forest: shades of geen
1475+ - base: theme that can be modified, use it for customizations
1476+
14681477 Possible rankdir:
14691478 - `TB`: top-to-bottom
14701479 - `BT`: bottom-to-top
@@ -1546,6 +1555,7 @@ def tree_to_mermaid(
15461555 >>> graph = tree_to_mermaid(
15471556 ... root,
15481557 ... title="Mermaid Diagram",
1558+ ... theme="forest",
15491559 ... node_shape_attr="node_shape",
15501560 ... edge_label="edge_label",
15511561 ... edge_arrow_attr="edge_arrow",
@@ -1556,7 +1566,7 @@ def tree_to_mermaid(
15561566 ---
15571567 title: Mermaid Diagram
15581568 ---
1559- %%{ init: { 'flowchart': { 'curve': 'basis' } } }%%
1569+ %%{ init: { 'flowchart': { 'curve': 'basis' }, 'theme': 'forest' } }%%
15601570 flowchart TB
15611571 0{"a"} ==>|Child 1| 0-0("b")
15621572 0-0 --> 0-0-0("d"):::class0-0-0
@@ -1593,12 +1603,15 @@ def tree_to_mermaid(
15931603 """
15941604 from bigtree .tree .helper import clone_tree
15951605
1606+ themes = constants .MermaidConstants .THEMES
15961607 rankdirs = constants .MermaidConstants .RANK_DIR
15971608 line_shapes = constants .MermaidConstants .LINE_SHAPES
15981609 node_shapes = constants .MermaidConstants .NODE_SHAPES
15991610 edge_arrows = constants .MermaidConstants .EDGE_ARROWS
16001611
16011612 # Assertions
1613+ if theme :
1614+ assertions .assert_str_in_list ("theme" , theme , themes )
16021615 assertions .assert_str_in_list ("rankdir" , rankdir , rankdirs )
16031616 assertions .assert_key_in_dict ("node_shape" , node_shape , node_shapes )
16041617 assertions .assert_str_in_list ("line_shape" , line_shape , line_shapes )
@@ -1609,8 +1622,9 @@ def tree_to_mermaid(
16091622 style_template = "classDef {style_name} {style}"
16101623
16111624 # Content
1625+ theme_mermaid = f", 'theme': '{ theme } '" if theme else ""
16121626 title = f"---\n title: { title } \n ---\n " if title else ""
1613- line_style = f"%%{{ init: {{ 'flowchart': {{ 'curve': '{ line_shape } ' }} }} }}%%"
1627+ line_style = f"%%{{ init: {{ 'flowchart': {{ 'curve': '{ line_shape } ' }}{ theme_mermaid } }} }}%%"
16141628 styles = []
16151629 flows = []
16161630
0 commit comments