Skip to content

feat(robot): add BaseRobot.graph() for multi-format link graph text - #586

Merged
petercorke merged 1 commit into
mainfrom
feat/dotfile-graph
Aug 10, 2026
Merged

petercorke merged 1 commit into
mainfrom
feat/dotfile-graph

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

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.

Also fixes

  • dotfile()'s open(filename, "w") had no encoding, the same bug PR
    use utf-8 #214 flagged in 2021 against the pre-src/-layout ERobot.py
    (dotfile() moved to BaseRobot.py since, bug survived the move).
    Fixes use utf-8 #214.
  • 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.

Test plan

  • New tests: 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
  • Full local suite green

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.
@petercorke petercorke mentioned this pull request Aug 9, 2026
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (6994fad) to head (fca095c).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/roboticstoolbox/robot/BaseRobot.py 0.00% 46 Missing ⚠️
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.
📢 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.

@petercorke
petercorke merged commit a1326de into main Aug 10, 2026
18 checks passed
@petercorke
petercorke deleted the feat/dotfile-graph branch October 22, 2026 04:37
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.

1 participant