nidi3 / graphviz-java

Use graphviz with pure java
Apache License 2.0
934 stars 106 forks source link

FDP layout - how to create a clusters link? #194

Open yauhen-l opened 3 years ago

yauhen-l commented 3 years ago

Example:

       Graphviz.useEngine(new GraphvizCmdLineEngine());

        Node a = node("a");
        Node b = node("b");
        Node c = node("c");

        MutableGraph subgraph1 = mutGraph("subgraph1").setCluster(true).add(a.link(b));
        MutableGraph subgraph2 = mutGraph("subgraph2").setCluster(true).add(c);

        MutableGraph g = mutGraph("example1");

        g.add(subgraph1);
        g.add(subgraph2);

        subgraph1.addLink(subgraph2);

        Graphviz.fromGraph(g).engine(Engine.FDP).height(100).render(Format.SVG).toFile(new File("example/ex1.svg"));

Produces dot file:

graph "example1" {
subgraph "cluster_subgraph1" {
"a" -- "b"
} -- subgraph "cluster_subgraph2" {
"c"
}
}

Which looks like this: image

However expected result is:

graph "example1" {
subgraph "cluster_subgraph1" {
"a" -- "b"
}
subgraph "cluster_subgraph2" {
"c"
}
cluster_subgraph1 -- cluster_subgraph2
}

Which gives completely different look with a link between clusters: image

Is dot file always optimized? Or there is a way to create links between clusters? There is also an example on graphviz site: http://www.graphviz.org/Gallery/undirected/fdpclust.html

nidi3 commented 3 years ago

Interesting, I thought cluster_1 { a, b } -- cluster_2 { c } is the same as cluster_1 { a, b } cluster_2 { c } cluser_1 -- cluster_2 but appearantly not. I don't see any workaround right now, I'll have to fix it.