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
69.33k stars 6.14k forks source link

Share nodes between subgraphs #2567

Open dbartholomae opened 2 years ago

dbartholomae commented 2 years ago

Is your feature request related to a problem? Please describe. I'm using Mermaid to describe the flow in our system and which teams are responsible for which part, e. g.

flowchart LR;
  subgraph Buy
    Customer --issues--> Order
  end
  Order
  subgraph Send
    Order --sent from--> Warehouse
  end

This will display the Order as being part of the Buy domain, but, actually, it should be a shared interface between both domains.

Describe the solution you'd like Allow to display nodes half-half in two subgraphs similar to this sketch: image

Ideally, this could be achieved with the following syntax:

flowchart LR;
  Order
  subgraph Buy
    Customer --issues--> Order
  end
  subgraph Send
    Order --sent from--> Warehouse
  end
``

But as this most likely would break a lot of existing use cases, instead I would propose a different syntax:
```mermaid
flowchart LR;
  subgraph Buy
    Customer --issues--> Order
  end
  subgraph Send
    Order --sent from--> Warehouse
  end
  share Order Buy Send
``

**Describe alternatives you've considered**
Showing the node as being part of neither domain:
```mermaid
flowchart LR;
  subgraph Buy
    Customer
  end
  Customer --issues--> Order --sent from--> Warehouse
  subgraph Send
    Warehouse
  end

But this robs both domains of a very important concept they have.

Additional context If someone is willing to get me started, I would be happy to try my hands on a PR (and use that knowledge also for further contributions).

felixsdys commented 2 years ago

Displaying a node half-half in two subgraphs does not seem very intuitive. What about having two subgraphs enclosing the shared node like the tikz-bayesnet library for latex? TikZ

dbartholomae commented 2 years ago

This could also work, but might add a bit of complexity, as mermaid then needs to decide which box should be the bigger and which the smaller one, so the rendering of one box no longer depends only on properties of that box itself.

jumale commented 1 year ago

I have a similar problem - I need to somehow display a grouping of nodes in my graph, where nodes can be in different groups. For example, I expect to have code something like this:

flowchart TD
    A([Parent workspace])
    B([Child workspace 1])
    C([Child workspace 2])

    N1[Node 1]
    N2[Node 2]
    N2[Node 3]

    subgraph setup1["Setup 1"]
        B
        N1
        N2
    end
    subgraph setup2["Setup 2"]
        C
        N2
        N3
    end
    subgraph setup3["Setup 3"]
        A
        B
        C
    end

    A-->B
    A-->C
    B-->N1
    B-->N2
    C-->N2
    C-->N3

A the moment it displays the result like on the screenshot, but my goal is to have grouping like it's showed with the colored lines: Screenshot 2023-04-12 at 12 05 53

Actually, I would say that the subgraph as a rectangular container is not even the best tool to achieve this goal - it's not about wrapping nodes inside containers, but rather about drawing a line around some nodes. So something like a free-form dash line without background filling would perfectly work for this purpose.

eosfor commented 7 months ago

Displaying a node half-half in two subgraphs does not seem very intuitive. What about having two subgraphs enclosing the shared node like the tikz-bayesnet library for latex? TikZ

+1 for this :D

zhfk930129 commented 6 months ago

Displaying a node half-half in two subgraphs does not seem very intuitive. What about having two subgraphs enclosing the shared node like the tikz-bayesnet library for latex? TikZ

+1 for this as well. :D

yuis-ice commented 6 months ago

I have the same problem.

dstockton commented 4 months ago

+1