{% macro subgraph_cluster(name, group, color="lightgrey") -%}
subgraph cluster_{{ name }} {
    style=filled;
    color={{ color }};
    node [style=filled,color=pink];
    label="{{ name }}";
    fontsize=20;

    {% for sg in group.subgroups %}
    # this is a subgroup
    {{ subgraph_cluster(sg.name, sg, "yellow") | indent }}
    {% endfor %}

    {%- for field in group.fields %}
    subgraph cluster_{{ field.name }} {
        style=filled;
        color=white;
        node [style=filled,color=pink];
        label="{{ field.name }}";
        fontsize=20;
        {{ field.path|join(' -> ') }};
    }
    {% endfor -%}
}
{%- endmacro %}

digraph G {
    concentrate=true;
    graph [fontname = "Courier"];
    node [fontname = "Courier"];
    edge [fontname = "Courier"];

    bgcolor=transparent;

    {%- for name, group in groups|items %}
    # this is a top-level group: {{ name }}
    {{ subgraph_cluster(name, group)|indent }}
    {%- endfor %}
}
