terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
16.22k stars 401 forks source link

Undeclared actor within sequence_diagram group causes weird problems #1557

Open murphyke opened 11 months ago

murphyke commented 11 months ago

This applies to d2 0.6.0 and whatever previous version I was on.

To reproduce, I'm going to add one line involving an undefined actor (mary) to the d2lang example for sequence diagram groups:

shape: sequence_diagram

# Predefine actors

alice
bob

shower thoughts: {
  alice -> bob: A physicist is an atom's way of knowing about atoms.
  alice -> bob: Today is the first day of the rest of your life.
}

life advice: {
  bob -> alice: If all else fails, lower your standards.
  alice -> mary: It’s rubbish, nothing but a gnib gnab.   # <-- add this
}

There is no error, but life advice changes from a group to an actor, and the new line results in alice pointing to a span. This is very confusing. Here is the rendering:

d2-problem
bo-ku-ra commented 11 months ago

sure, the d2 is cool looking. however, mermaid's sequenceDiagram is easy to write and understand.

sequenceDiagram
    autonumber

    actor alice
    actor bob

    alice ->> bob: A physicist is an atom's way of knowing about
    Note left of bob: shower thoughts

    alice ->> bob: Today is the first day of the rest of your life.
    Note left of bob: shower thoughts

    bob ->> alice: If all else fails, lower your standards.
    Note right of alice: life advice

    alice ->> mary: It’s rubbish, nothing but a gnib gnab.
    Note left of mary: life advice
sequenceDiagram
    autonumber

    actor alice
    actor bob

    alice ->> bob: A physicist is an atom's way of knowing about
    Note left of bob: shower thoughts

    alice ->> bob: Today is the first day of the rest of your life.
    Note left of bob: shower thoughts

    bob ->> alice: If all else fails, lower your standards.
    Note right of alice: life advice

    alice ->> mary: It’s rubbish, nothing but a gnib gnab.
    Note left of mary: life advice
shape: sequence_diagram
# Predefine actors
alice
bob
mary # <-- add this

shower thoughts: {
  alice -> bob: A physicist is an atom's way of knowing about atoms.
  alice -> bob: Today is the first day of the rest of your life.
}

life advice: {
  bob -> alice: If all else fails, lower your standards.
  alice -> mary: It’s rubbish, nothing but a gnib gnab.
}

https://play.d2lang.com/?l=&script=ZJBBSgQxEEX3OcWHWbiZmQM0IricnQv3UulUdwp7UpqqdmhkwGt4PU8iyazE3SfhP96vbjDA-H3lMvJLEporncMOT5UTT1IYNLpWC20lh6gxnKlu2OH-cAClBM9iIVjWC1d41nXObgM-A9A7ODwgahzwiLe8mYxiDjFQAbme7wwX2qATXotepMygqKv3Pzv-gzxroq3VPTMmqeZIt3p7qGze8qZrxSITH8M1hBZA6UNGvnlFjQ3YyQNOE2hZwIsxJpLF9lj6mE4xp5Kopr8u7QYDTv7z9W2oa4xieY-intuC2PwxF4mYC8UjwjX8BgAA__8%3D&