static void node_induce(graph_t * par, graph_t * g) { node_t *n, *nn; edge_t *e; int i; /* enforce that a node is in at most one cluster at this level */ for (n = agfstnode(g); n; n = nn) { nn = agnxtnode(g, n); if (ND_ranktype(n)) { agdelete(g, n); continue; } for (i = 1; i < GD_n_cluster(par); i++) if (agcontains(GD_clust(par)[i], n)) break; if (i < GD_n_cluster(par)) agdelete(g, n); ND_clust(n) = NULL; } for (n = agfstnode(g); n; n = agnxtnode(g, n)) { for (e = agfstout(dot_root(g), n); e; e = agnxtout(dot_root(g), e)) { if (agcontains(g, aghead(e))) agsubedge(g,e,1); } } }
static void rebuild_vlists(graph_t * g) { int c, i, r, maxi; node_t *n, *lead; edge_t *e, *rep; for (r = GD_minrank(g); r <= GD_maxrank(g); r++) GD_rankleader(g)[r] = NULL; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { infuse(g, n); for (e = agfstout(g, n); e; e = agnxtout(g, e)) { for (rep = e; ED_to_virt(rep); rep = ED_to_virt(rep)); while (ND_rank(rep->head) < ND_rank(e->head)) { infuse(g, rep->head); rep = ND_out(rep->head).list[0]; } } } for (r = GD_minrank(g); r <= GD_maxrank(g); r++) { lead = GD_rankleader(g)[r]; if (ND_rank(g->root)[r].v[ND_order(lead)] != lead) abort(); GD_rank(g)[r].v = ND_rank(g->root)[r].v + GD_rankleader(g)[r]->u.order; maxi = -1; for (i = 0; i < GD_rank(g)[r].n; i++) { if ((n = GD_rank(g)[r].v[i]) == NULL) break; if (ND_node_type(n) == NORMAL) { if (agcontains(g, n)) maxi = i; else break; } else { edge_t *e; for (e = ND_in(n).list[0]; e && ED_to_orig(e); e = ED_to_orig(e)); if (e && (agcontains(g, e->tail)) && agcontains(g, e->head)) maxi = i; } } if (maxi == -1) agerr(AGWARN, "degenerate concentrated rank %s,%d\n", g->name, r); GD_rank(g)[r].n = maxi + 1; } for (c = 1; c <= GD_n_cluster(g); c++) rebuild_vlists(GD_clust(g)[c]); }
/* helper functions for model_edge */ static rep_t bindnode(Agraph_t *model, Agnode_t *orignode) { rep_t rep; if (agcontains(GD_originalgraph(model),orignode)) rep = model_intnode(model,orignode); else rep = model_extnode(model,orignode); return rep; }
/* * attach and install edges between clusters. * essentially, class2() for interclust edges. */ void interclexp(graph_t* subg) { graph_t *g; node_t *n; edge_t *e,*prev; g = subg->root; for (n = agfstnode(subg); n; n = agnxtnode(subg,n)) { /* N.B. n may be in a sub-cluster of subg */ prev = NULL; for (e = agfstedge(subg->root,n); e; e = agnxtedge(subg->root,e,n)) { if (agcontains(subg,e)) continue; /* short/flat multi edges */ if (mergeable(prev,e)) { if (e->tail->u.rank == e->head->u.rank) e->u.to_virt = prev; else e->u.to_virt = NULL; if (prev->u.to_virt == NULL) continue; /* internal edge */ merge_chain(subg,e,prev->u.to_virt,FALSE); safe_other_edge(e); continue; } /* flat edges */ if (e->tail->u.rank == e->head->u.rank) { if (find_flat_edge(e->tail,e->head) == NULL) { flat_edge(g,e); prev = e; } else prev = NULL; continue; } assert (e->u.to_virt != NULL); /* forward edges */ if (e->head->u.rank > e->tail->u.rank) { make_interclust_chain(g,e->tail,e->head,e); prev = e; continue; } /* backward edges */ else { /* I think that make_interclust_chain should create call other_edge(e) anyway if (agcontains(subg,e->tail) && agfindedge(subg->root,e->head,e->tail)) other_edge(e); */ make_interclust_chain(g,e->head,e->tail,e); prev = e; } } } }
/* twopi_layout: */ void twopi_layout(Agraph_t * g) { Agnode_t *ctr = 0; char *s; twopi_init_graph(g); s = agget(g, "root"); if (s && (*s != '\0')) { ctr = agfindnode(g, s); if (!ctr) { agerr(AGWARN, "specified root node \"%s\" was not found.", s); agerr(AGPREV, "Using default calculation for root node\n"); } } if (agnnodes(g)) { Agraph_t **ccs; Agraph_t *sg; Agnode_t *c = NULL; int ncc; int i; ccs = ccomps(g, &ncc, 0); if (ncc == 1) { circleLayout(g, ctr); adjustNodes(g); spline_edges(g); } else { pack_info pinfo; pack_mode pmode = getPackMode(g, l_node); for (i = 0; i < ncc; i++) { sg = ccs[i]; if (ctr && agcontains(sg, ctr)) c = ctr; else c = 0; nodeInduce(sg); circleLayout(sg, c); adjustNodes(sg); } spline_edges(g); pinfo.margin = getPack(g, CL_OFFSET, CL_OFFSET); pinfo.doSplines = 1; pinfo.mode = pmode; pinfo.fixed = 0; packSubgraphs(ncc, ccs, g, &pinfo); } for (i = 0; i < ncc; i++) { agdelete(g, ccs[i]); } free(ccs); } dotneato_postprocess(g); }
static void cluster_contents(Agraph_t *ug) { Agraph_t *mg; char *name; assert(is_a_cluster(ug)); assert(GD_model(ug) == 0); name = malloc(strlen(ug->name)+10); sprintf(name,"model_%s",ug->name); GD_model(ug) = mg = agopen(name,AGDIGRAPHSTRICT); free(name); /* install internal nodes */ for (n = agfstnode(ug); n; n = agnxtnode(ug,n)) { if (ND_cluster(n) == ug) model_intnode(mg,n); } /* install cluster skeletons */ rec_model_subclusts(mg,ug); /* install external edge endpoints */ root = GD_layoutroot(ug); for (n = agfstnode(ug); n; n = agnxtnode(ug,n)) { for (e = agfstout(root,n); e; e = agnxtout(root,e)) { if (!agcontains(ug,e->tail)) model_extnode(mg,e->tail); if (!agcontains(ug,e->head)) model_extnode(mg,e->head); } } /* install edges */ for (n = agfstnode(ug); n; n = agnxtnode(ug,n)) for (e = agfstout(root,n); e; e = agnxtout(root,e)) model_edge(mg,e); /* amazing if this is all it takes */ }
/* * attach and install edges between clusters. * essentially, class2() for interclust edges. */ void interclexp(graph_t * subg) { graph_t *g; node_t *n; edge_t *e, *prev, *next; g = agroot(subg); for (n = agfstnode(subg); n; n = agnxtnode(subg, n)) { /* N.B. n may be in a sub-cluster of subg */ prev = NULL; for (e = agfstedge(agroot(subg), n); e; e = next) { next = agnxtedge(agroot(subg), e, n); if (agcontains(subg, e)) continue; #ifdef WITH_CGRAPH /* canonicalize edge */ e = AGMKOUT(e); #endif /* short/flat multi edges */ if (mergeable(prev, e)) { if (ND_rank(agtail(e)) == ND_rank(aghead(e))) ED_to_virt(e) = prev; else ED_to_virt(e) = NULL; if (ED_to_virt(prev) == NULL) continue; /* internal edge */ merge_chain(subg, e, ED_to_virt(prev), FALSE); safe_other_edge(e); continue; } /* flat edges */ if (ND_rank(agtail(e)) == ND_rank(aghead(e))) { edge_t* fe; if ((fe = find_flat_edge(agtail(e), aghead(e))) == NULL) { flat_edge(g, e); prev = e; } else if (e != fe) { safe_other_edge(e); if (!ED_to_virt(e)) merge_oneway(e, fe); } continue; } /* This assertion is still valid if the new ranking is not used */ #ifndef WITH_CGRAPH assert(ED_to_virt(e) != NULL); #endif /* forward edges */ if (ND_rank(aghead(e)) > ND_rank(agtail(e))) { make_interclust_chain(g, agtail(e), aghead(e), e); prev = e; continue; } /* backward edges */ else { /* I think that make_interclust_chain should create call other_edge(e) anyway if (agcontains(subg,agtail(e)) && agfindedge(subg->root,aghead(e),agtail(e))) other_edge(e); */ make_interclust_chain(g, aghead(e), agtail(e), e); prev = e; } } } }
static void checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) { graph_t *tg; graph_t *hg; node_t *cn; node_t *cn1; node_t *t = e->tail; node_t *h = e->head; edge_t *ce; item *ip; tg = MAPC(t); hg = MAPC(h); if (!tg && !hg) return; if (tg == hg) { agerr(AGWARN, "cluster cycle %s -- %s not supported\n", t->name, t->name); return; } ip = mapEdge(map, e); if (ip) { cloneEdge(e, ip->t, ip->h); return; } if (hg) { if (tg) { if (agcontains(hg, tg)) { agerr(AGWARN, "tail cluster %s inside head cluster %s\n", tg->name, hg->name); return; } if (agcontains(tg, hg)) { agerr(AGWARN, "head cluster %s inside tail cluster %s\n", hg->name, tg->name); return; } cn = clustNode(t, tg, xb, clg); cn1 = clustNode(h, hg, xb, clg); ce = cloneEdge(e, cn, cn1); insertEdge(map, t, h, ce); } else { if (agcontains(hg, t)) { agerr(AGWARN, "tail node %s inside head cluster %s\n", t->name, hg->name); return; } cn = clustNode(h, hg, xb, clg); ce = cloneEdge(e, t, cn); insertEdge(map, t, h, ce); } } else { if (agcontains(tg, h)) { agerr(AGWARN, "head node %s inside tail cluster %s\n", h->name, tg->name); return; } cn = clustNode(t, tg, xb, clg); ce = cloneEdge(e, cn, h); insertEdge(map, t, h, ce); } }
/* twopi_layout: */ void twopi_layout(Agraph_t * g) { Agnode_t *ctr = 0; char *s; int setRoot = 0; pointf sc; int doScale = 0; int r; if (agnnodes(g) == 0) return; twopi_init_graph(g); s = agget(g, "root"); if ((s = agget(g, "root"))) { if (*s) { ctr = agfindnode(g, s); if (!ctr) { agerr(AGWARN, "specified root node \"%s\" was not found.", s); agerr(AGPREV, "Using default calculation for root node\n"); setRoot = 1; } } else { setRoot = 1; } } if ((s = agget(g, "scale")) && *s) { if ((r = sscanf (s, "%lf,%lf",&sc.x,&sc.y))) { if (r == 1) sc.y = sc.x; doScale = 1; if (Verbose) fprintf (stderr, "scale = (%f,%f)\n", sc.x, sc.y); } } if (agnnodes(g)) { Agraph_t **ccs; Agraph_t *sg; Agnode_t *c = NULL; Agnode_t *n; int ncc; int i; ccs = ccomps(g, &ncc, 0); if (ncc == 1) { c = circleLayout(g, ctr); if (setRoot && !ctr) ctr = c; n = agfstnode(g); free(ND_alg(n)); ND_alg(n) = NULL; if (doScale) scaleGraph (g, c, sc); adjustNodes(g); spline_edges(g); } else { pack_info pinfo; getPackInfo (g, l_node, CL_OFFSET, &pinfo); pinfo.doSplines = 0; for (i = 0; i < ncc; i++) { sg = ccs[i]; if (ctr && agcontains(sg, ctr)) c = ctr; else c = 0; nodeInduce(sg); c = circleLayout(sg, c); if (setRoot && !ctr) ctr = c; if (doScale) scaleGraph (sg, c, sc); adjustNodes(sg); } n = agfstnode(g); free(ND_alg(n)); ND_alg(n) = NULL; packSubgraphs(ncc, ccs, g, &pinfo); spline_edges(g); } for (i = 0; i < ncc; i++) { agdelete(g, ccs[i]); } free(ccs); } if (setRoot) agset (g, "root", agnameof (ctr)); dotneato_postprocess(g); }