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
72.44k stars 6.6k forks source link

Bidirectional arrows should not force nodes into different levels #4745

Open e-pet opened 1 year ago

e-pet commented 1 year ago

Description

Bidirectional arrows (A <--> B) force the involved nodes to be on different levels, with the first-mentioned one being placed higher up even if the nodes would be on the same level without the addition of the bidirectional link. This seems unnecessary and often yields undesirable results. Adding a bidirectional link should not change the relative ranking of the nodes.

Steps to reproduce

Example 1: without bidirectional link - A and B are on the same level.

flowchart TD
    C --> A & B

image

Example 2: with bidirectional link - now B is forced down one level. The diagram would look much nicer if everything stayed as in the previous example, just with the extra arrow.

flowchart TD
    C --> A & B
    A <--> B

image

Example 3: without bidirectional link - A and B are on the same level.

flowchart TD
    C --> A & B
    A --> D
    B --> E

image

Example 4: with bidirectional link - now B is forced down one level. The diagram would look much nicer if everything stayed as in the previous example, just with the extra arrow.

flowchart TD
    C --> A & B
    A --> D
    B --> E
    A <--> B

image

Screenshots

No response

Code Sample

No response

Setup

Suggested Solutions

I know too little about the placement algorithm to make a useful suggestion. Could it be possible to just ignore bidirectional links for the purposes of determining the level on which to place a node? (Is the placement algorithm described / documented somewhere?)

Additional Context

Note that this is different from https://github.com/mermaid-js/mermaid/issues/4317 which is about keeping nodes on the same level even if they are connected by unidirectional links. While that issue would clearly require special treatment / syntax, I would hope that the issue described here could give a general improvement of the default placement behavior.

e-pet commented 1 year ago

Maybe this has to wait until after the planned Dagre/cytoscape migration? https://github.com/orgs/mermaid-js/discussions/3811