Skip to content

feat: Add layout options to mermaid renderer#288

Merged
aborgna-q merged 2 commits intomainfrom
ab/mermaid-layout
Apr 13, 2026
Merged

feat: Add layout options to mermaid renderer#288
aborgna-q merged 2 commits intomainfrom
ab/mermaid-layout

Conversation

@aborgna-q
Copy link
Copy Markdown
Collaborator

@aborgna-q aborgna-q commented Apr 13, 2026

Gives some basic control over mermaid's layout option:
https://mermaid.js.org/intro/syntax-reference.html#selecting-layout-algorithms

Changes the default to use elk, to work around this bug: mermaid-js/mermaid#7609.

This is mostly noticeable on larger graphs, where elk produces a tighter node layout:

Before:

graph LR
    subgraph 0 ["(0) Module"]
        direction LR
        subgraph 1 ["(1) [**FuncDefn: #quot;__main__.foo#quot;**]"]
            direction LR
            style 1 stroke:#832561,stroke-width:3px
            2["(2) Input"]
            3["(3) Output"]
            subgraph 4 ["(4) CFG"]
                direction LR
                subgraph 5 ["(5) DataflowBlock"]
                    direction LR
                    6["(6) Input"]
                    7["(7) Output"]
                    8["(8) LoadConstant"]
                    9["(9) const:custom:u64(0)"]
                    10["(10) Tag"]
                    6--"0:1<br>bool"-->7
                    6--"1:2<br>bool"-->7
                    8--"0:3<br>int(6)"-->7
                    9--"0:0<br>int(6)"-->8
                    10--"0:0<br>Unit"-->7
                end
                11["(11) ExitBlock"]
                subgraph 12 ["(12) DataflowBlock"]
                    direction LR
                    13["(13) Input"]
                    14["(14) Output"]
                    15["(15) tket.bool.read"]
                    13--"0:0<br>bool"-->15
                    13--"1:1<br>bool"-->14
                    13--"2:2<br>int(6)"-->14
                    15--"0:0<br>Bool"-->14
                end
                subgraph 16 ["(16) DataflowBlock"]
                    direction LR
                    17["(17) Input"]
                    18["(18) Output"]
                    19["(19) tket.bool.read"]
                    17--"0:1<br>bool"-->18
                    17--"0:0<br>bool"-->19
                    17--"1:2<br>int(6)"-->18
                    19--"0:0<br>Bool"-->18
                end
                subgraph 20 ["(20) DataflowBlock"]
                    direction LR
                    21["(21) Input"]
                    22["(22) Output"]
                    23["(23) tket.bool.read"]
                    21--"0:0<br>bool"-->23
                    21--"1:1<br>int(6)"-->22
                    23--"0:0<br>Bool"-->22
                end
                subgraph 24 ["(24) DataflowBlock"]
                    direction LR
                    25["(25) Input"]
                    26["(26) Output"]
                    27["(27) LoadConstant"]
                    28["(28) const:custom:u64(1)"]
                    29["(29) arithmetic.int.iadd"]
                    30["(30) Tag"]
                    25--"0:1<br>bool"-->26
                    25--"1:0<br>int(6)"-->29
                    27--"0:1<br>int(6)"-->29
                    28--"0:0<br>int(6)"-->27
                    29--"0:2<br>int(6)"-->26
                    30--"0:0<br>Unit"-->26
                end
                subgraph 31 ["(31) DataflowBlock"]
                    direction LR
                    32["(32) Input"]
                    33["(33) Output"]
                    34["(34) LoadConstant"]
                    35["(35) const:custom:u64(2)"]
                    36["(36) arithmetic.int.iadd"]
                    37["(37) Tag"]
                    32--"0:1<br>bool"-->33
                    32--"1:0<br>int(6)"-->36
                    34--"0:1<br>int(6)"-->36
                    35--"0:0<br>int(6)"-->34
                    36--"0:2<br>int(6)"-->33
                    37--"0:0<br>Unit"-->33
                end
                subgraph 38 ["(38) DataflowBlock"]
                    direction LR
                    39["(39) Input"]
                    40["(40) Output"]
                    41["(41) LoadConstant"]
                    42["(42) const:custom:u64(5)"]
                    43["(43) arithmetic.int.ilt_s"]
                    44["(44) tket.bool.make_opaque"]
                    45["(45) Tag"]
                    39--"0:2<br>bool"-->40
                    39--"1:3<br>int(6)"-->40
                    39--"1:0<br>int(6)"-->43
                    41--"0:1<br>int(6)"-->43
                    42--"0:0<br>int(6)"-->41
                    43--"0:0<br>Bool"-->44
                    44--"0:1<br>bool"-->40
                    45--"0:0<br>Unit"-->40
                end
                subgraph 46 ["(46) DataflowBlock"]
                    direction LR
                    47["(47) Input"]
                    48["(48) Output"]
                    49["(49) LoadConstant"]
                    50["(50) const:custom:u64(2)"]
                    51["(51) arithmetic.int.imul"]
                    52["(52) Tag"]
                    47--"0:0<br>int(6)"-->51
                    49--"0:1<br>int(6)"-->51
                    50--"0:0<br>int(6)"-->49
                    51--"0:1<br>int(6)"-->48
                    52--"0:0<br>Unit"-->48
                end
                subgraph 53 ["(53) DataflowBlock"]
                    direction LR
                    54["(54) Input"]
                    55["(55) Output"]
                    56["(56) LoadConstant"]
                    57["(57) const:custom:u64(3)"]
                    58["(58) arithmetic.int.imul"]
                    59["(59) Tag"]
                    54--"0:0<br>int(6)"-->58
                    56--"0:1<br>int(6)"-->58
                    57--"0:0<br>int(6)"-->56
                    58--"0:1<br>int(6)"-->55
                    59--"0:0<br>Unit"-->55
                end
                subgraph 60 ["(60) DataflowBlock"]
                    direction LR
                    61["(61) Input"]
                    62["(62) Output"]
                    63["(63) Tag"]
                    61--"0:1<br>int(6)"-->62
                    63--"0:0<br>Unit"-->62
                end
                5-."0:0".->12
                12-."0:0".->20
                12-."1:0".->16
                16-."0:0".->24
                16-."1:0".->31
                20-."0:0".->46
                20-."1:0".->53
                24-."0:0".->38
                31-."0:0".->38
                38-."0:0".->12
                46-."0:0".->60
                53-."0:0".->60
                60-."0:0".->11
            end
            2--"0:0<br>bool"-->4
            2--"1:1<br>bool"-->4
            4--"0:0<br>int(6)"-->3
        end
    end
Loading

After:
Mermaid Diagram Apr 13 2026

(github markdown does not support elk, and falls back to the default kernel instead)

@aborgna-q aborgna-q requested a review from ss2165 April 13, 2026 09:26
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 13, 2026

Merging this PR will degrade performance by 21.34%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 49 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
check_convexity_sparse_LineConvexChecker<PortGraph>[10000] 24.1 µs 18.4 µs +31.28%
check_convexity_sparse_LineConvexChecker<PortGraph>[100] 2.4 µs 3 µs -21.34%

Comparing ab/mermaid-layout (dd1f85f) with main (d3852e9)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.12%. Comparing base (d3852e9) to head (dd1f85f).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/render/mermaid/layout.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #288      +/-   ##
==========================================
+ Coverage   83.06%   83.12%   +0.06%     
==========================================
  Files          30       31       +1     
  Lines        7670     7704      +34     
  Branches     7670     7704      +34     
==========================================
+ Hits         6371     6404      +33     
- Misses       1199     1200       +1     
  Partials      100      100              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/render/mermaid/layout.rs
@aborgna-q aborgna-q added this pull request to the merge queue Apr 13, 2026
Merged via the queue into main with commit c1ea274 Apr 13, 2026
12 of 13 checks passed
@aborgna-q aborgna-q deleted the ab/mermaid-layout branch April 13, 2026 09:50
@hugrbot hugrbot mentioned this pull request Apr 13, 2026
github-merge-queue bot pushed a commit that referenced this pull request Apr 13, 2026
## 🤖 New release

* `portgraph`: 0.16.0 -> 0.16.1 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.16.1](v0.16.0...v0.16.1)
- 2026-04-13

### New Features

- Add layout options to mermaid renderer
([#288](#288))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants