glejeune / Ruby-Graphviz

[MIRROR] Ruby interface to the GraphViz graphing tool
https://gitlab.com/glejeune/ruby-graphviz
Other
609 stars 116 forks source link

Making an edge between a node and a subgraph #35

Closed veberle closed 12 years ago

veberle commented 12 years ago

Making an edge between a note and a subgraph doesn't seem to work. Instead a new node is generated with the name of the subgraph.

c0 = g.add_graph( "cluster0", "label" => "cluster #1"  )
a0 = c0.add_nodes( "a0" )

c1 = g.add_graph( "cluster1", "label" => "cluster #2" )
b0 = c1.add_nodes( "b0" )

g.add_edges(c0,c1)
g.add_edges(c0,b0)

is generated to

digraph G {
subgraph cluster0 {
  label = "cluster #1";
  a0 [label = "a0"];
}
subgraph cluster1 {
  label = "cluster #2";
  b0 [label = "b0"];
}
  cluster0 [label = "cluster0"];
  cluster1 [label = "cluster1"];
  cluster0 -> cluster1
  cluster0 -> b0
}

I was trying something like this

glejeune commented 12 years ago

If you try the fdpcplus example (http://www.graphviz.org/Gallery/undirected/fdpclust.html) you will see that it does not work either. As indicated on the example's page, "fdp is being actively worked on, so the probability of hitting a bug is higher than with neato". I think, this is a fdp bug. I'll ask on the graphviz mailing list.

glejeune commented 12 years ago

Hi,

In the meantime, you can use "compound", "lhead" and "ltail" attributes, to clip the edge to the boundary of a cluster. Here is an example :

g = GraphViz::new( "G", :type => "graph" )
g[:compound] = true
g[:rankdir] = "LR"

c0 = g.add_graph( "cluster0", "label" => "cluster #1"  )
a0 = c0.add_nodes( "a0" )

c1 = g.add_graph( "cluster1", "label" => "cluster #2" )
b0 = c1.add_nodes( "b0" )

e1 = g.add_edges(a0,b0)
e1[:lhead] = c1.id
e1[:ltail] = c0.id

e2 = g.add_edges(a0,b0)
e2[:lhead] = c1.id

For more informations about these attributs, see http://www.graphviz.org/content/attrs

glejeune commented 12 years ago

That has been confirmed, it is a bug in graphviz 2.28.