Question

I'm trying to visualize a graph in C with the help of graphviz library. Graph is given by the adjacency matrix. The graph is directed and there is a problem. I work with the matrix and create an edge between n and m, and go on, but the edge between m and n are also there, and I create another edge. As a result, graphviz draws, as expected, two edges, but the graph with a large number of edges is very difficult to read. I want to create a single edge, with a both-directed arrow, but don't know how to do it right. (There is a stupid idea first create a file with a description of the graph (add to the description of the edge [dir = both]), and then later process it and draw a graph. I'm sure there is a better solution, but I do not know it.)

I'm working with matrix like this:

for(i=0; i<n; i++)
            nodes[i] =  agnode(g, itoa(i+1, name)); // Agnode_t *nodes[100];
    for(i=0; i<n; i++)
            for(j=0; j<n; j++)
                    if(matrix[i][j])
                            agedge(g, nodes[i], nodes[j]); // add edges

Thank you for your answers!

P.S. Excuse me for my bad English.

Was it helpful?

Solution

You need to set the dir attribute on the edges, which I believe you can do like this in your innermost loop:

Agedge_t *e = agedge(g, nodes[i], nodes[j]);
agsafeset(e, "dir", "both", "");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top