Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

graphviz Cluster with the same rank as other nodes

Tags:

graphviz

dot

I am trying to create a graph I explicitly specify the ranks of many of the nodes and specify clusters. The following code produces the type of graph I want:

digraph {
    rankdir=LR
    subgraph cluster0 {
        "MATH 208"
        "MATH 211"
        graph [rankdir=LR, style="rounded,filled", color=gray]
    }
    subgraph year1 {
        subgraph {
            "MATH 100"
            "MATH 110"
            graph [rankdir=LR, rank=same]
        }
        subgraph {
            "MATH 101"
            "MATH 211"
            "MATH 208"
            graph [rankdir=LR, rank=same]
        }
        graph [rankdir=LR]
    }
    subgraph year2 {
        subgraph {
            "MATH 205"
            "PHIL 203"
            graph [rankdir=LR, rank=same]
        }
        graph [rankdir=LR]
    }
    subgraph year3 {
        subgraph {
            "MATH 311"
            "MATH 312"
            "MATH 375"
            graph [rankdir=LR, rank=same]
        }
        graph [rankdir=LR]
    }
    subgraph year4 {
        subgraph {
            "MATH 447"
            "MATH 412"
            graph [rankdir=LR, rank=same]
        }
        graph [rankdir=LR]
    }
    "MATH 100" -> "MATH 101"
    "MATH 100" -> "MATH 208"
    "MATH 101" -> "MATH 205"
    "MATH 110" -> "MATH 311"
    "MATH 211" -> "MATH 311"
    "MATH 110" -> "MATH 312"
    "MATH 211" -> "MATH 312"
    "PHIL 203" -> "MATH 375"
    "MATH 110" -> "MATH 447"
    "MATH 211" -> "MATH 447"
    "MATH 311" -> "MATH 412"
    "MATH 312" -> "MATH 412"
}

This produces a correct graph with "MATH 211" at the same rank as "MATH 101", however graphviz issues the warnings

Warning: MATH 208 was already in a rankset, ignored in cluster pruned
Warning: MATH 211 was already in a rankset, ignored in cluster pruned

If I remove "MATH 211" and "MATH 208" from the year1 subgraph, graphviz no longer complains but the resulting graph no longer has the cluster in the same rank as "MATH 101" (why would it...):

Is there any way to rearrange/reorder my dot file to produce the first graph but without any warnings? Or to specify that a certain cluster should be positioned at the same rank as another node?

I should note that this graph successfully compiles with graphviz 2.26, but fails with graphviz 2.28...

like image 237
Jason Siefken Avatar asked Nov 29 '25 02:11

Jason Siefken


1 Answers

A couple thoughts

  • I think subgraphs need to have a name that starts with 'cluster' in order to get any styling. Actually, without the cluster prefix, they might not do anything at all and this could be the source of many of your problems.
  • You shouldn't need to repeat rankdir=LR. Specifying it once at the top should be enough.
  • If none of nodes in a subgraph have dependencies on each other, then there is a good chance they should already be in the same rank and rank=same shouldn't be needed.

Here is one version that works for me:

    digraph {
    rankdir=LR
    subgraph cluster0 {
        "MATH 208"
        "MATH 211"
        graph [style="rounded,filled", color=gray]
    }
    subgraph clusteryear1 {
        subgraph cluster100{
            "MATH 100"
            "MATH 110"
            graph [rank=same]
        }
        subgraph cluster101{
            "MATH 101"
            "MATH 211"
            "MATH 208"
            graph [rank=same]
        }
    }
    subgraph clusteryear2 {
        subgraph cluster205{
            "MATH 205"
            "PHIL 203"
            graph [rank=same]
        }
    }
    subgraph clusteryear3 {
        subgraph cluster311{
            "MATH 311"
            "MATH 312"
            "MATH 375"
            graph [rank=same]
        }
    }
    subgraph clusteryear4 {
        subgraph cluster447 {
            "MATH 447"
            "MATH 412"
            graph [rank=same]
        }
    }
    "MATH 100" -> "MATH 101"
    "MATH 100" -> "MATH 208"
    "MATH 101" -> "MATH 205"
    "MATH 110" -> "MATH 311"
    "MATH 211" -> "MATH 311"
    "MATH 110" -> "MATH 312"
    "MATH 211" -> "MATH 312"
    "PHIL 203" -> "MATH 375"
    "MATH 110" -> "MATH 447"
    "MATH 211" -> "MATH 447"
    "MATH 311" -> "MATH 412"
    "MATH 312" -> "MATH 412"
}
like image 150
Rick Avatar answered Dec 01 '25 21:12

Rick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!