Clusters in sfdp

Hello everyone,

For context, my end goal is to draw a collaboration graph using gvmap, similar to

but specifying my own clusters.

So, I have a graph (see minimal example below) with clusters (which represents coauthors, each cluster is a “topic”, but it’s irrelevant for my question). Inspired by the code above, I try:

sfdp -Goverlap=prism example.gv | gvmap -e -D | neato -Ecolor="#5555555522" -Tpng > out.png

Now, I have three issues:

  • sfdp does not “respect” the clusters: what I’d like is that it positions clusters as much as possible “away from each other”. For larger examples, the clusters are spread throughout the graph (this is not visible for such a small example!).
  • more concretely on my example (see below), each cluster comes with a “box” which hides the rest of the picture
  • also on my example, one of the cluster is filled with black, making it unreadable.

How can I get rid of the “box”, and why is one cluster filled with black?

The main question is the first one:

Given a clustered graph, how to make sfdp “respect” clusters (meaning, put vertices in a cluster all together, and as much as possible clusters far from one another)?

I tried playing with the constant K, to make vertices inside a cluster attract each other, but I couldn’t make them repulse the other ones.

Many thanks for your help!

graph {

"A" [fontsize=30,fontcolor=red]
	subgraph cluster1{
		"B" [fontsize=10]
		"C" [fontsize=10]
		"D" [fontsize=20]
		"A" -- "B" [weight=1]
		"A" -- "C" [weight=1]
		"A" -- "D" [weight=1]
		"B" -- "C" [weight=1]
	}
	subgraph cluster2{
		"E" [fontsize=10]
		"F" [fontsize=10]
		"G" [fontsize=20]
		"A" -- "E" [weight=1]
		"A" -- "F" [weight=1]
		"A" -- "G" [weight=1]
		"E" -- "E" [weight=1]
	}
}

Sorry to disappoint. sfdp doesn’t support clusters. At an algorithmic level, it only handles basic graphs, and doesn’t cope with variable edge lengths either.

graphviz fdp can solve this problem. One other thing - none of the graphviz layout programs allow a node to belong to more than one cluster (as siblings, not parent/child) and in your example, A is in both clusters, so it’s simpler to do something like this:

graph {

        "A" [fontsize=30,fontcolor=red]
        subgraph cluster1{
                "B" [fontsize=10]
                "C" [fontsize=10]
                "D" [fontsize=20]
        }
        subgraph cluster2{
                "E" [fontsize=10]
                "F" [fontsize=10]
                "G" [fontsize=20]
        }
        "A" -- "E" [weight=1]
        "A" -- "F" [weight=1]
        "A" -- "G" [weight=1]
        "E" -- "E" [weight=1]
        "A" -- "B" [weight=1]
        "A" -- "C" [weight=1]
        "A" -- "D" [weight=1]
        "B" -- "C" [weight=1]
}

[I am not expert in **sfdp** or **gvmap**, so no guarantees]

  • FYI, I do not get any black cluster boxes, but I doubt that is important to my answers
  • your command line misuses sfdp, gvmap, and neato.
    • sfdp and gvmap each will do a layout from scratch, i.e. the sfdp layout will be ignored by gvmap
    • neato can make use of layout from a previous engine, but only if -n or -n2 is on the command line (note that -n2 is used on the gvmap example)
  • I do not believe that sfdp recognizes clusters as input. As I remember, the documentation used to be more clear about this.
  • placing your edges inside the clusters will cause problems, move the to the bottom of the input . gvmap will assume all the referenced nodes are members of the current cluster - e.g. A can’t be part of two clusters

My suggestion:

  • drop sfdp
  • move your edges
  • add -n2 to the neato command line

[It took me too long to compose my answer. I bow (again) to Stephen]

1 Like