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
70.64k stars 6.32k forks source link

Manual numbering of sequence diagrams #2543

Open LuPro opened 2 years ago

LuPro commented 2 years ago

Is your feature request related to a problem? Please describe. Autonumber on sequence diagrams is a great feature for 99% of use cases, however I'm finding myself in need of manually numbering sequence diagrams sometimes.

Describe the solution you'd like An extra section on a transition in the sequence diagram for number, eg: #1 A ->> B: Text

Describe alternatives you've considered What I really need is sequence numbering based on various algorithms, in the current specific case, sequence number for a Lamport Logical Clock (or Lamport Timestamping). Being able to select different numbering algorithms would be cool, but I feel like wouldn't really cover this; it's both way more complex to implement (at least I'd imagine it to be) and there'd never be all the algorithms implemented that someone may need.

Additional context In specific, I'm trying to recreate this graph: image

I know this isn't really the core target for a sequence diagram, but apart from the numbering issue it does (almost*) everything to a satisfactory degree, so I'd like to use it.

*It's only almost everything because I can't have simple "points" on the sequence without a looping arrow, but that's not really an issue for me right now so I don't mind.

PS: This is about the best I could manage right now using mermaid and utilizing the notes feature in the sequence diagrams, but the styling is kinda bad with how big the notes are: image

fairking commented 1 year ago

I would simply love to see something like manual numeration.

For example:

:::mermaid
sequenceDiagram;
    #1 A->>B: Enter Details
    #2 B->>C: Update Database
    opt If Notification required
        #2a C->>B: Send `notification required`
        #2b B->>A: Notify user
    end
    #3 C->>A: Return promo code
:::

as a workaround I am using the following approach:

:::mermaid
sequenceDiagram;
    A->>B: 1. Enter Details
    B->>C: 2. Update Database
    opt If Notification required
        C->>B: 2a. Send `notification required`
        B->>A: 2b. Notify user
    end
    C->>A: 3. Return promo code
:::
ZcuBa commented 1 month ago

Are you aware that https://github.com/mermaid-js/mermaid/issues/2952 - has been solved? you can use: autonumber xx to reset autonumber to count from a manual value.

e.g.

` autonumber

alt is remote User ->>+ Browser: Open https:// else is local autonumber 1 Browser ->>+ Browser: Open LocalHost after reboot end `

in which both "branches" of the sequence will re-initialize the autonumber and count from 1 you would need to go in, and do something like:

sequenceDiagram
    autonumber
    P1 -->>+ P1: 

    autonumber 1
    P2 -->>+ P2: 

    autonumber 1
    P3 -->>+ P3: 
    P1 ->>+ P2: 
    P2 -->>+ P2: 
    P2 -->>+ P2: 

    autonumber 3
    P1 -->>+ P1: