@startuml !function $system($s_name, $s_id, $s_type="Component") !if ($s_type == "") !$s_type = "Component" !endif !return $s_type + " " + %chr(34) + $s_name + %chr(34) + " as " + $s_id !endfunction !function $sys_diagram($sd_diagram) /' initialise empty system list string '/ !$system_list = "" !foreach $sd_subsys in $sd_diagram.subsystems /' build the system part of the diagram '/ !$system_list = $system_list + $system($sd_subsys.name, $sd_subsys.id, $sd_subsys.type) !if %not($sd_subsys.subsystems == "") /' set up the recursive part of the function '/ !$system_list = $system_list + " { " + %newline() /' recursively call this same function to build the diagram to any depth '/ /' this doesn't work '/ /' !system_list = !$system_list + !$sys_diagram_1($subsys) '/ !$system_list = $system_list + $sys_diagram_sub($sd_subsys) /' complete the embedded systems '/ !$system_list = $system_list + " } " + %newline() !else !$system_list = $system_list + %newline() !endif !endfor !return $system_list !endfunction /' this is a copy/paste the function above with a different name to allow that function "to call itself" '/ /' as many copies could be created with different names to the desired depth of the diagram recursion, but it's wasteful and hard to maintain '/ !function $sys_diagram_sub($sd_diagram) /' initialise empty system list string '/ !$system_list = "" !foreach $sd_subsys in $sd_diagram.subsystems /' build the system part of the diagram '/ !$system_list = $system_list + $system($sd_subsys.name, $sd_subsys.id, $sd_subsys.type) !if %not($sd_subsys.subsystems == "") /' set up the recursive part of the function '/ !$system_list = $system_list + " { " + %newline() /' recursively call this same function to build the diagram to any depth '/ /' this doesn't work '/ /' !system_list = !$system_list + !$sys_diagram_1($subsys) '/ !$system_list = $system_list + $sys_diagram($sd_subsys) /' complete the embedded systems '/ !$system_list = $system_list + " } " + %newline() !else !$system_list = $system_list + %newline() !endif !endfor !return $system_list !endfunction !$diagram = { "title": "Recursive functions", "subsystems":[ { "id": "1", "name": "Main System", "type": "cloud", "subsystems": [ { "id": "1.1", "name": "Subsystem 1.1", "subsystems": [ { "id": "1.1.1", "name": "Subsystem 1.1.1", "subsystems": [ { "id": "1.1.1.1", "name": "Subsystem 1.1.1.1" }, { "id": "1.1.1.2", "name": "Subsystem 1.1.1.2" }, { "id": "1.1.1.3", "name": "Subsystem 1.1.1.3" } ] } ] } , { "id": "1.2", "name": "Subsystem 1.2", "type": "database", "subsystems": [ { "id": "1.2.1", "name": "Subsystem 1.2.1", "subsystems": [ { "id": "1.2.1.1", "name": "Subsystem 1.2.1.1" }, { "id": "1.2.1.2", "name": "Subsystem 1.2.1.2", "type": "package" }, { "id": "1.2.1.3", "name": "Subsystem 1.2.1.3", "type": "node" } ] } ] } , { "id": "1.3", "name": "Subsystem 1.3", "type": "file" } ] } , { "id": "2", "name": "Second System", "type": "Cloud" } ] } title $diagram.title end title /' Debug: JSON visualisation '/ rectangle document_data as " {{json $diagram }} " /' Systems diagram '/ $sys_diagram($diagram) @enduml
Decode URL
Submit
amiga
aws-orange
black-knight
bluegray
blueprint
cerulean-outline
cerulean
crt-amber
crt-green
cyborg-outline
cyborg
hacker
lightgray
mars
materia-outline
materia
metal
mimeograph
minty
plain
reddress-darkblue
reddress-darkgreen
reddress-darkorange
reddress-darkred
reddress-lightblue
reddress-lightgreen
reddress-lightorange
reddress-lightred
sandstone
silver
sketchy-outline
sketchy
spacelab
spacelab-white
superhero-outline
superhero
toy
united
vibrant
Pure Javascript
PNG
SVG
ASCII Art