nmiculinic
nmiculinic

Reputation: 2474

How to align specific nodes in subgraph vertically in graphviz

I'm trying to produce nice looking aligned graph, where each s_i is underneath d_i. This is my code:

digraph G {
    rankdir="LR"

    graph [bgcolor="#EAEAF2" fontname="Noto Sans", colorscheme=gnbu3]
    node [fontname="Noto Sans" style=filled, colorscheme=gnbu3]
    edge [fontname="Noto Sans"]

    node[fontname="Noto Sans"];
    subgraph cluster_1 {
        node [style=filled, color=1];
        edge [style="invis"];
        s3[group=3];
        s0 -> s1 -> s2 -> s3;
        label = "Raw signal";
        color=2;
    }

    subgraph cluster_0 {
        color=lightgrey;
        node [style=dotted,color=""];
        edge [style="invis"];
        d0[label="..."]
        d1[label="..."]
        d2[label="..."]
        d3[label="...", group=f]
        label = "CNN";
        d0 -> d1 -> d2 -> d3;
    }
    edge[style=dotted, weight=10000]
    s0 -> d0;
    s1 -> d1;
    s2 -> d2;
    s3 -> d3;
}

What I get is anything but: https://i.sstatic.net/CAR5V.jpg

If I try adding:

{rank=same s0->d0}; 

s0 and d0 nodes became aligned, but they fall out of subclusters

Upvotes: 0

Views: 1671

Answers (1)

marapet
marapet

Reputation: 56566

Simply change the order of your subgraphs (cluster_0 first), and change the line edge[style=dotted, weight=10000] into edge[style=dotted, constraint=false].

This will put the subgraphs into the right order (of appearance), and prevent the edges between the 2 subgraph's nodes to have an impact on ranking.

Upvotes: 1

Related Questions