alignment problems for lib python

Hi,
Alignment problem for libgv_python.
I used the python script to generate one graph: "test.py"
#!/usr/bin/python
import gv
g = gv.digraph("G")
gv.setv(g, "label", "Just for test")

c1 = "cluster1"
gv.graph(g, c1)
g1 = gv.findsubg(g, c1)
gv.setv(g1, "label", c1)
gv.node(g1, "a1")
gv.node(g1, "a2")
gv.node(g1, "a3")
gv.edge(g1, "a1", "a2")

gv.write(g, "test.dot")
gv.layout(g, "dot")
gv.render(g, "png", "test.png")
gv.rm(g)

Which will generate "test.dot"("a3" is in the same node with "a1")
digraph G {
    graph [label="Just for test"];
    node [label="\N"];
    subgraph cluster1 {
        graph [label=cluster1];
        a1;
        a2;
        a3;
    }
    a1 -> a2;
}

If I add {rank=same; a3; a2} in "test.dot" manually (Then "a3" "a2" are in the same rank)
digraph G {
    graph [label="Just for test"];
    node [label="\N"];
    subgraph cluster1 {
        graph [label=cluster1];
        {rank=same; a3; a2}
        a1;
        a2;
        a3;
    }
    a1 -> a2;
}

Is there any libgv_python support functions that can add this line?

 

That line is just an

That line is just an anonymous subgraph with the attribute rank=same, so you just use the same commands as you did elsewhere:

g1 = gv.graph(g, c1)
gv.setv(g1, "label", c1)
gv.node(g1, "a1")
g2 = gv.graph(g1, "")
gv.setv(g2, "rank", "same")
gv.node(g2, "a2")
gv.node(g2, "a3")
gv.edge(g1, "a1", "a2")

Note also that gv.graph returns the handle, so you don't need to do a separate gv.findsub().

Running the amended script, the gv.rm(g) at the end causes an error. I am tracking this down. Meanwhile, the gv.rm is unnecessary for short-lived programs.

I have tried your method. It

I have tried your method. It works. But have one error as you said gv.rm(g).

# cluster 1
c1 = "cluster1"
g1 = gv.graph(g, c1)
gv.setv(g1, "label", c1)
#gv.setv(g1, "clusterrank", "local")
gv.node(g1, "a1")
gv.node(g1, "a2")
gv.node(g1, "a3")
gv.edge(g1, "a1", "a2")

g2 = gv.graph(g1, "")
gv.setv(g2, "rank", "same")
gv.node(g2, "a2")
gv.node(g2, "a3")

I have another two small problems:

1. Why this function gv.edge(g1, "a1", "a2") does not make a1->a2 into the g1 body?

2. Why "a2" and "a3" only show in the anonymous subgraph, not in the subgraph cluster1?

digraph G {
        graph [label="Just for test"];
        node [label="\N"];
        subgraph cluster1 {
                graph [label=cluster1];
                 {
                        graph [rank=same];
                        a2;
                        a3;
                }
                a1;
        }
        a1 -> a2;
}

 

As I mentioned, the gv.rm()

As I mentioned, the gv.rm() bug is fixed in the new working version.

1) Good question. This was a bug which I have just fixed.

2) Because the graph output attempts to be as terse as possible. a2 and a3 belong to the anonymous cluster, but it sits inside cluster1, so a2 and a3 automatically belong to cluster1.

Recent comments