Repository navigation
feat(robot): add BaseRobot.graph() for multi-format link graph text - #586
Merged
Merged
Conversation
Adds graph(format="dot"|"mermaid"|"mermaid_fenced", filename=None, **kwargs) alongside the existing dotfile()/showgraph() pair, following the same pattern already established in MVTB's ImageBlobs.graph() and bdsim's BlockDiagram.graph(): a single entry point returning rendered text (optionally also written to a file), with GraphViz DOT staying as the detailed/primary representation and Mermaid as a simplified alternative for Markdown/Jupyter rendering. format="dot" wraps dotfile() (writes to an in-memory stream, returns the text) rather than duplicating its logic -- RTB's DOT output has real domain-specific richness (etsbox layout, jtype arrowheads, static coloring) that doesn't map onto Mermaid 1:1, so unlike MVTB's simpler blob-hierarchy case, dotfile() stays the source of truth for "dot" rather than being inverted into a thin wrapper around graph(). format="mermaid"/"mermaid_fenced" is new: one node per link (double circle for end-effectors, hexagon for gripper links), edges labelled with joint type (R/P) and jindex for actuated joints. No dotfile() kwargs apply here -- Mermaid has no equivalent of DOT's per-edge arrowhead/colour styling. Also fixes two issues found while building this: - dotfile()'s open(filename, "w") had no encoding, same bug PR #214 flagged in 2021 against the pre-src/layout ERobot.py (dotfile() moved to BaseRobot.py since, bug survived the move) - draw_edge()'s static-joint edge styling concatenated edge_options += 'fontcolor="blue"' with no leading comma, producing invalid DOT (arrowhead="normal"fontcolor="blue") whenever static=True hit a non-joint link -- pre-existing, unrelated to this feature, just noticed while testing graph(format="dot") output.
Closed
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #586 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 142 142
Lines 13788 13869 +81
=====================================
- Misses 13788 13869 +81 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Adds
graph(format="dot"|"mermaid"|"mermaid_fenced", filename=None, **kwargs)alongside the existing
dotfile()/showgraph()pair, following the samepattern already established in MVTB's
ImageBlobs.graph()and bdsim'sBlockDiagram.graph(): a single entry point returning rendered text(optionally also written to a file), with GraphViz DOT staying as the
detailed/primary representation and Mermaid as a simplified alternative for
Markdown/Jupyter rendering.
format="dot"wrapsdotfile()(writes to an in-memory stream, returnsthe text) rather than duplicating its logic -- RTB's DOT output has real
domain-specific richness (
etsboxlayout,jtypearrowheads,staticcoloring) that doesn't map onto Mermaid 1:1, so unlike MVTB's simpler
blob-hierarchy case,
dotfile()stays the source of truth for"dot"rather than being inverted into a thin wrapper around
graph().format="mermaid"/"mermaid_fenced"is new: one node per link (doublecircle for end-effectors, hexagon for gripper links), edges labelled with
joint type (R/P) and jindex for actuated joints.
Also fixes
dotfile()'sopen(filename, "w")had noencoding, the same bug PRuse utf-8 #214 flagged in 2021 against the pre-
src/-layoutERobot.py(
dotfile()moved toBaseRobot.pysince, bug survived the move).Fixes use utf-8 #214.
draw_edge()'s static-joint edge styling concatenatededge_options += 'fontcolor="blue"'with no leading comma, producinginvalid DOT (
arrowhead="normal"fontcolor="blue") wheneverstatic=Truehit a non-joint link -- pre-existing, unrelated to this feature, just
noticed while testing
graph(format="dot")output.Test plan
test_graph_dot_matches_dotfile,test_graph_dot_kwargs_forwarded,test_graph_mermaid,test_graph_mermaid_fenced,test_graph_multiple_end_effectors,test_graph_writes_to_filename,test_graph_bad_format_raises