feat: Add configuration settings to mermaid render - #3207
feat: Add configuration settings to mermaid render#3207nicolaassolini-qntm wants to merge 12 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3207 +/- ##
==========================================
+ Coverage 81.45% 81.54% +0.09%
==========================================
Files 243 243
Lines 47061 47449 +388
Branches 40702 41090 +388
==========================================
+ Hits 38334 38693 +359
- Misses 6725 6754 +29
Partials 2002 2002
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| /// Return the mermaid representation of the underlying hierarchical graph | ||
| /// using the provided rendering configuration. | ||
| /// | ||
| /// This method allows customizing the appearance of node labels and other | ||
| /// elements in the mermaid diagram. | ||
| fn mermaid_string_with_config(&self, config: RenderStringConfig) -> String { | ||
| self.mermaid_string_with_formatter(self.mermaid_format().with_render_string_config(config)) | ||
| } | ||
|
|
There was a problem hiding this comment.
Not sure if a method like this may be useful
| @@ -2,7 +2,7 @@ | |||
|
|
|||
There was a problem hiding this comment.
Most of the Op here contains types, not sure for which one should I change the rendering, since the information about the type is in the edge and the name is self explicable
|
|
||
| fn render_str(&self, _config: RenderStringConfig) -> String { | ||
| self.name().to_string() | ||
| } |
There was a problem hiding this comment.
Is it fine? should I render the types of the Type row?
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable string-rendering pathway for HUGR operations and types, and wires that configuration into Mermaid (and partially into dot) graph rendering so callers can control whether node/edge labels include qualified names, extension versions, and type arguments.
Changes:
- Add
RenderStringConfigand newrender_str(...)APIs across ops/types to support configurable string rendering. - Update Mermaid rendering to use
render_str(...)for node and edge labels, and exposemermaid_string_with_config(...)for callers. - Update/add tests and snapshots to reflect the new rendering behavior.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| hugr-persistent/src/trait_impls.rs | Propagates Mermaid render-string configuration into persistent HUGR view config. |
| hugr-core/src/types/type_row.rs | Extends TypeRowLike with config-driven render_str(...) and implements it for rows. |
| hugr-core/src/types/type_param.rs | Adds config-driven Term::render_str(...) and tests for nested/composite term rendering. |
| hugr-core/src/types/poly_func.rs | Adds config-driven PolyFuncTypeBase::render_str(...) and a propagation test. |
| hugr-core/src/types/custom.rs | Changes CustomType Display formatting for type arguments. |
| hugr-core/src/types.rs | Adds Type::render_str(...) convenience wrapper. |
| hugr-core/src/ops/sum.rs | Adds render_str(...) for Tag op under the new rendering trait. |
| hugr-core/src/ops/module.rs | Adds render_str(...) implementations for module-related ops (Module, FuncDefn, etc.). |
| hugr-core/src/ops/dataflow.rs | Adds render_str(...) to DataflowOpTrait and forwards through OpTrait. |
| hugr-core/src/ops/custom.rs | Implements config-driven rendering for extension and opaque ops, including version/type-arg handling and tests. |
| hugr-core/src/ops/controlflow.rs | Adds render_str(...) implementations for controlflow ops and blocks. |
| hugr-core/src/ops/constant.rs | Adds render_str(...) implementation for constants. |
| hugr-core/src/ops.rs | Introduces RenderStringConfig and adds render_str(...) requirement to OpTrait. |
| hugr-core/src/hugr/views/render.rs | Wires RenderStringConfig into Mermaid node/edge label rendering; adds formatter option + test. |
| hugr-core/src/hugr/views.rs | Adds mermaid_string_with_config(...) to expose configurable Mermaid rendering. |
| hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__mmd_dfg.snap | Updates Mermaid snapshot output to match new default label rendering. |
| hugr-core/src/hugr/views/snapshots/hugr_core__hugr__views__tests__dot_dfg.snap | Updates dot snapshot output to match new default node label rendering. |
| hugr-core/src/hugr/views/root_checked/snapshots/hugr_core__hugr__views__root_checked__dfg__test__map_io_cycle_3qb.snap | Updates root-checked Mermaid snapshot output for new node labels. |
| hugr-core/src/hugr/views/root_checked/snapshots/hugr_core__hugr__views__root_checked__dfg__test__map_io_cx_gate.snap | Updates root-checked Mermaid snapshot output for new node labels. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| impl Display for CustomType { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!(f, "{}", self.id)?; | ||
| if !self.args.is_empty() { | ||
| write!(f, "(")?; | ||
| write!(f, "<")?; | ||
| crate::utils::display_list(&self.args, f)?; | ||
| write!(f, ")")?; | ||
| write!(f, ">")?; | ||
| } |
There was a problem hiding this comment.
I changed it for consistency, but we can change it back
| /// Return the mermaid representation of the underlying hierarchical graph | ||
| /// using the provided rendering configuration. | ||
| /// | ||
| /// This method allows customizing the appearance of node labels and other | ||
| /// elements in the mermaid diagram. | ||
| fn mermaid_string_with_config(&self, config: RenderStringConfig) -> String { | ||
| self.mermaid_string_with_formatter(self.mermaid_format().with_render_string_config(config)) | ||
| } |
There was a problem hiding this comment.
Is dot_string() used for real in rust?
closes #3001
by updating the mermaid rendering.
This PR allows you to decide when to print the qualified name, extension version and type arguments of nodes and edges during mermaid rendering.