Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make block diagrams with node inside nodes in mermaid?

Tags:

mermaid

How do I create block diagrams where one node is inside another node like the CPU in the picture below?

My use case is that I want to draw an architecture and show what does inside a certain part of the system. The problem with class is that it just draws lines inside the node, and does not show the whole rectangle of the child node inside the parent node.

enter image description here

like image 723
user3061876 Avatar asked Sep 07 '25 00:09

user3061876


2 Answers

At last I found that you can create subgraphs.

flowchart LR
    A --> B

subgraph B
    C --> D
end

subgraph in graph

like image 171
user3061876 Avatar answered Sep 11 '25 00:09

user3061876


You can use subgraph to do this. Check this link for more information.
https://mermaid-js.github.io/mermaid/#/flowchart?id=subgraphs

Your graph will look like this.

flowchart LR
    subgraph CPU["Central Processing Unit (CPU)"]
        direction TB
        ArithmeticUnit["Arithmetic & Logic Unit"]
        ControlUnit["Control Unit"]
        MemoryUnit["Memory Unit"]
        
        ArithmeticUnit-->ControlUnit-->ArithmeticUnit
        MemoryUnit-->ControlUnit-->MemoryUnit
    end
    InputUnit["Input Unit"]-->CPU 
    CPU-->OutputUnit["Output Unit"]
like image 31
William Buron Avatar answered Sep 11 '25 01:09

William Buron