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.69k stars 6.34k forks source link

Record based nodes in diagrams #1575

Open FabianWilms opened 4 years ago

FabianWilms commented 4 years ago

Is your feature request related to a problem? Please describe.

We regularly have to do data migration at our company and drawing graphs for the mapping relations of different entities is especially cumbersome in visual editors.

We recently stumbled upon graphvizs "record based nodes" visualization, with wich multiple nodes can be joined together to one object but can be linked individually (see their documentation about this feature here: https://renenyffenegger.ch/notes/tools/Graphviz/elems/node/main-types/record-based)

While we regularly use mermaids class diagram type (especially because we use gitlab as our VCS of choice), this is something we currently can't use it for.

Describe the solution you'd like

I can imagine two syntatic options:

The Graphviz-Style would require the labels of a node to be parsed and searched through for keys. As a format I would propose the same syntax as in Graphviz (seen in the documentation above).

The new alternative to subgraphs could maybe look look like this:

graph TB
    a1-->b2
    node one
    a1-->a2
    end
    node two
    b1[b1]
    b2[b2]
    end

and would produce something like this:

node

All elements inside a node would be rendered directly next to each other without spacing and connections between the elements wouldn't produce gaps eiter.

Describe alternatives you've considered

A workaround currently would be to use a Flowchart with subgraphs for each "node" and add the records to the subgraph. This does work, but the output of it is not ideal especially with larger nodes.

Additional context

An example of such a diagram in Graphviz can be found here https://bit.ly/3jCC04b

bish0polis commented 4 years ago

Graphviz's record format is Phenomenal:

image

I'd LOVE to see this capability. Combined with an undirected graph layout it'd be ideal!

fowles commented 2 years ago

I would really like to use this, especially with a LR layout for the nodes

jgreywolf commented 1 year ago

I think this would be better supported as a new diagram type

sharwell commented 1 year ago

@jgreywolf I was referred to Mermaid as a possible option for some data flow graphs I'm working on. This feature is the main item I was looking for to see how it would compare to GraphViz. You can see some examples of how I've used record types within a flow chart here: https://www.antlr.org/api/Java/org/antlr/v4/runtime/atn/ATNState.html

In standard flow charts, it's beneficial for cases where the order/index of a line matters.

For GraphViz, the record element is treated similar to a subgraph. The source for the "Block of one or more alternatives" is here: https://github.com/antlr/antlr4/blob/master/runtime/Java/src/main/dot/org/antlr/v4/runtime/atn/images/Block.dot GraphViz Online Link

It seems to work well with the current subgraph element of a flow chart in Mermaid, where the primary difference is simply controlling the placement of the child nodes within the containing element.