fix: Add truncation options for node and edge labels in rendering#2885
Merged
nicolaassolini-qntm merged 6 commits intomainfrom Feb 19, 2026
Merged
fix: Add truncation options for node and edge labels in rendering#2885nicolaassolini-qntm merged 6 commits intomainfrom
nicolaassolini-qntm merged 6 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
aborgna-q
reviewed
Feb 19, 2026
hugr-py/src/hugr/hugr/render.py
Outdated
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 |
Collaborator
There was a problem hiding this comment.
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.
aborgna-q
approved these changes
Feb 19, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the bug pointed out in #2879
RenderConfiginhugr/hugr/render.pyto 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)._viz_node, applying the new configuration to ensure node labels do not exceed the specified length._viz_link, using a new_smart_truncatefunction that preserves important tokens and balances brackets, and switched edge label rendering to usexlabelfor better display.