mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
68.69k stars 6.07k forks source link

Cannot add behaviors to parent composite states #5522

Open emmby opened 1 month ago

emmby commented 1 month ago

Description

You can add a UML-style behavior ("trigger [guard] / action()") to state nodes in diagrams, but you cannot add a behavior to a parent node.

stateDiagram
    Parent: Parent
    Parent: enter [guard] / action()
    [*] --> Parent
    state Parent {
        Child: Child
        Child: trigger [guard] / action()
        [*] --> Child
        Child --> [*]
    }

Steps to reproduce

See description

Screenshots

Screenshot 2024-05-14 at 6 53 05 PM

Code Sample

No response

Setup

Suggested Solutions

No response

Additional Context

Proposed documentation about adding behaviors to state machines: https://github.com/mermaid-js/mermaid/pull/5512

igorwessel commented 1 month ago

@sidharthv96 I would like to try working on this issue if support is desired, but first I want to understand if it makes sense to have a new shape or modify the current cluster shape to support multiple descriptions.

https://github.com/mermaid-js/mermaid/blob/d6ccd93cf207a30bbd45edf39fd29afdbb87b05e/packages/mermaid/src/dagre-wrapper/clusters.js#L132

I noticed that there is this specific shape for the state with description, could we possibly reuse some of the code from there?

https://github.com/mermaid-js/mermaid/blob/d6ccd93cf207a30bbd45edf39fd29afdbb87b05e/packages/mermaid/src/diagrams/state/shapes.js#L73

sidharthv96 commented 1 month ago

Help is always welcome 😇

State diagram is currently undergoing major rework on the rendering part, by @knsv and @ashishjain0512. So it might be a good idea to wait till that's done, or check with them if their refactoring will interfere with the work you're planning.

igorwessel commented 1 month ago

State diagram is currently undergoing major rework on the rendering part, by @knsv and @ashishjain0512. So it might be a > good idea to wait till that's done, or check with them if their refactoring will interfere with the work you're planning.

Ohh thanks! I'll take a look and understand, but I believe it's also better to wait :)