rich-iannone / DiagrammeR

Graph and network visualization using tabular data in R
https://rich-iannone.github.io/DiagrammeR/
Other
1.68k stars 247 forks source link

Support subgraphs (including nesting) for Mermaid files #329

Open jmcastagnetto opened 5 years ago

jmcastagnetto commented 5 years ago

Now that support for 7.0.0 has been merged in the main branch, it could be feasible to support subgraphs (even nested ones)

I know you are implementing subgraphs/clusters for GraphViz too, and I guess it is not trivial. And, it would be nice to have also the mermaid "subgraph" command supported for flowcharts (see: https://mermaidjs.github.io/flowchart.html).

Ideally some code like the following:

DiagrammeR::mermaid("
graph TD
A[Christmas] -->|Get money| B(Go shopping)
subgraph Nerve wracking
B --> C{Roll a dice}
end
subgraph Don't look
  C -->|One| D[Laptop]
  C -->|Two| E[iPhone]
  subgraph High Probability
    C-->|Three| G
    C-->|Four| G
    C-->|Five| G[A gift card]
  end
  subgraph Low Probability
    C -->|Six| F[fa:fa-car Car]
  end
end
")

Producing something similar to:

screenshot_2018-12-12 online flowchart diagrams editor - mermaid live editor

(Edited online at: https://mermaidjs.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbkFbQ2hyaXN0bWFzXSAtLT58R2V0IG1vbmV5fCBCKEdvIHNob3BwaW5nKVxuc3ViZ3JhcGggTmVydmUgd3JhY2tpbmdcbkIgLS0-IEN7Um9sbCBhIGRpY2V9XG5lbmRcbnN1YmdyYXBoIERvbid0IGxvb2tcbiAgQyAtLT58T25lfCBEW0xhcHRvcF1cbiAgQyAtLT58VHdvfCBFW2lQaG9uZV1cbiAgc3ViZ3JhcGggSGlnaCBQcm9iYWJpbGl0eVxuICAgIEMtLT58VGhyZWV8IEdcbiAgICBDLS0-fEZvdXJ8IEdcbiAgICBDLS0-fEZpdmV8IEdbQSBnaWZ0IGNhcmRdXG4gIGVuZFxuICBzdWJncmFwaCBMb3cgUHJvYmFiaWxpdHlcbiAgICBDIC0tPnxTaXh8IEZbZmE6ZmEtY2FyIENhcl1cbiAgZW5kXG5lbmRcblxuIiwibWVybWFpZCI6eyJ0aGVtZSI6ImRlZmF1bHQifX0)

Originally posted by @jmcastagnetto in https://github.com/rich-iannone/DiagrammeR/issues/315#issuecomment-446656862

zachsa commented 3 years ago

I have found that using subgraph inside a flowchart works. Is this good practice?