According to GraphViz documentation, something like this should do the layout job:
- (void) testGraph { Agraph_t* G; GVC_t* gvc; gvc = gvContext(); char* testGraph = "\ digraph G {\ subgraph cluster_c0 {a0 -> a1 -> a2 -> a3;}\ subgraph cluster_c1 {b0 -> b1 -> b2 -> b3;}\ x -> a0;\ x -> b0;\ a1 -> a3;\ a3 -> a0;\ }"; G = agmemread((char*)testGraph); [self dumpGraph:G]; gvLayout (gvc, G, "dot"); NSLog(@"after layout:"); [self dumpGraph:G]; gvFreeLayout(gvc, G); gvFreeContext(gvc); } - (void) printNode:(Agnode_t*) node { NSLog(@"Node: %s {{%f,%f},{%f,%f}}",node->name, node->u.coord.x, node->u.coord.y, ND_width(node), ND_height(node)); } - (void) dumpGraph:(Agraph_t*)graph { if (!graph) return; Agnode_t *n = NULL; Dict_t *dict = graph->nodes; for (n= dtfirst(dict); n ; n = dtnext(dict, n)) { [self printNode:n]; } }
Instead of using logNode: you should write drawing code.
Log output:
GraphTest[32319:303] Node: a0 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: a1 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: a2 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: a3 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: b0 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: b1 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: b2 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: b3 {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] Node: x {{0.000000,0.000000},{0.000000,0.000000}} GraphTest[32319:303] after layout: GraphTest[32319:303] Node: a0 {{83.000000,250.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: a1 {{63.000000,178.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: a2 {{43.000000,106.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: a3 {{83.000000,34.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: b0 {{161.000000,250.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: b1 {{161.000000,178.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: b2 {{161.000000,106.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: b3 {{161.000000,34.000000},{0.750000,0.500000}} GraphTest[32319:303] Node: x {{122.000000,322.000000},{0.750000,0.500000}}