Skip to content

fix: Add truncation options for node and edge labels in rendering#2885

Merged
nicolaassolini-qntm merged 6 commits intomainfrom
na/2879-bug-hugrrender_dot
Feb 19, 2026
Merged

fix: Add truncation options for node and edge labels in rendering#2885
nicolaassolini-qntm merged 6 commits intomainfrom
na/2879-bug-hugrrender_dot

Conversation

@nicolaassolini-qntm
Copy link
Copy Markdown
Contributor

@nicolaassolini-qntm nicolaassolini-qntm commented Feb 18, 2026

This PR fixes the bug pointed out in #2879

  • Added new options to RenderConfig in hugr/hugr/render.py to control truncation of edge and node labels (truncate_edge_labels, max_edge_label_length, truncate_node_labels, max_node_label_length, truncate_metadata, max_metadata_length).
  • Implemented smart truncation of node labels in _viz_node, applying the new configuration to ensure node labels do not exceed the specified length.
  • Implemented smart truncation of edge labels in _viz_link, using a new _smart_truncate function that preserves important tokens and balances brackets, and switched edge label rendering to use xlabel for better display.

@nicolaassolini-qntm nicolaassolini-qntm marked this pull request as ready for review February 18, 2026 16:30
@nicolaassolini-qntm nicolaassolini-qntm requested a review from a team as a code owner February 18, 2026 16:30
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.81%. Comparing base (1c61f39) to head (fe11473).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
hugr-py/src/hugr/hugr/render.py 92.50% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2885   +/-   ##
=======================================
  Coverage   83.80%   83.81%           
=======================================
  Files         267      267           
  Lines       53622    53660   +38     
  Branches    47748    47748           
=======================================
+ Hits        44940    44975   +35     
- Misses       6272     6275    +3     
  Partials     2410     2410           
Flag Coverage Δ
python 88.49% <92.85%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@nicolaassolini-qntm nicolaassolini-qntm changed the title feat: Add truncation options for node and edge labels in rendering fix: Add truncation options for node and edge labels in rendering Feb 19, 2026
Comment on lines +88 to +99
#: If true truncate long type names on edges to `max_edge_label_length` characters
truncate_edge_labels: bool = True
#: Max length for edge labels (if truncation is enabled).
max_edge_label_length: int = 24
#: If true truncate node labels to `max_node_label_length` characters.
truncate_node_labels: bool = True
#: Max length for node labels (if truncation is enabled).
max_node_label_length: int = 24
#: If true truncate the metadata display to `max_metadata_length` characters.
truncate_metadata: bool = True
#: Max length for metadata display (if truncation is enabled).
max_metadata_length: int = 20
Copy link
Copy Markdown
Collaborator

@aborgna-q aborgna-q Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a truncate_* set to false means that the max_*_length is ignored.

So someone writing

RenderConfig(max_node_label_length = 42)

may get confused on why it doesn't work.

It may be simpler to just have a single field,

max_metadata_length: int | None = 20

where None means don't truncate.

@nicolaassolini-qntm nicolaassolini-qntm added this pull request to the merge queue Feb 19, 2026
Merged via the queue into main with commit 25c625d Feb 19, 2026
29 checks passed
@nicolaassolini-qntm nicolaassolini-qntm deleted the na/2879-bug-hugrrender_dot branch February 19, 2026 17:47
github-merge-queue bot pushed a commit that referenced this pull request Feb 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.15.4](hugr-py-v0.15.3...hugr-py-v0.15.4)
(2026-02-20)


### Features

* **hugr-py:** Define typed Metadata protocol
([#2765](#2765))
([4390230](4390230))


### Bug Fixes

* Add truncation options for node and edge labels in rendering
([#2885](#2885))
([25c625d](25c625d))
* used_extensions should include transitive requirements
([#2891](#2891))
([18e78e4](18e78e4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Agustín Borgna <[email protected]>
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.

[Bug]: [hugr-py] Hugr.render_dot() can make dot files that graphviz can't process

2 participants