void QGVNode::setAttribute(const QString &name, const QString &value) { agsafeset(_node->node(), name.toLocal8Bit().data(), value.toLocal8Bit().data(), ""); }
int render_graph(rendering_ctx_t *rctx, const char* filename, const char* format) { Agraph_t *g; Agnode_t *n; Agnode_t *d; Agedge_t *e; GVC_t *gvc; rnsGraph_t *rnsGraph; char w[32]; FILE *fp; fp = fopen(filename, "w+"); gvc = gvContext(); rnsGraph = rctx->graph; if (rctx->directed){ g = agopen("g", Agstrictdirected, 0); }else{ g = agopen("g", Agstrictundirected, 0); } size_t i, j; for (i=0; i<rnsGraph->size; i++){ if ( !rnsGraph->repos[i]) { continue; } n = agnode(g, rnsGraph->repos[i]->id, 1); for (j=0; j<rnsGraph->repos[i]->maxLinks; j++){ if (!rnsGraph->repos[i]->links[j]){ continue; } d = agnode(g, rnsGraph->repos[i]->links[j]->repo->id, 1); e = agedge(g, n, d, 0, 1); snprintf(w, sizeof(w), "%1.3g", (double) cost(rnsGraph->repos[i], rnsGraph->repos[i]->links[j])); agsafeset(e, "label", w, ""); if (rnsGraph->repos[i]->links[j]->is_path){ agsafeset(e, "color", "red", ""); } } } // char *args[] = { // "sfdp", // "-x", // "-Tpng", // "-Goverlap=scale", // "-GK=5.0", // "-ooutput/random.png" // }; // gvParseArgs (gvc, sizeof(args)/sizeof(char*), args); // gvLayoutJobs(gvc, g); // gvRenderJobs(gvc, g); gvLayout(gvc, g, "dot"); gvRender(gvc, g, format, fp); gvFreeLayout(gvc, g); agclose(g); fclose(fp); return (gvFreeContext(gvc)); }
void GVSkeletonGraph::setGraphObjectAttributes(void *object, QString attr, QString value){ setlocale(LC_NUMERIC,"en_US.UTF-8"); agsafeset(object, const_cast<char *>(qPrintable(attr)),const_cast<char *>(qPrintable(value)),const_cast<char *>(qPrintable(value))); }
static Agraph_t* CreateGraph(Digraph& dg, VNG_Param& param) { // 缓存 char str[20]; //创建一个有向图g Agraph_t* g = agopen("g",Agdirected,NULL); // 设置有向图图g的属性 sprintf(str,"%s","BT"); agsafeset(g, "rankdir", str,""); sprintf(str,"%s",BOOL_2_STRING(param.m_splines)); agsafeset(g, "splines", str,""); sprintf(str,"%.3f", param.m_nodeSep); agsafeset(g, "nodesep", str,""); sprintf(str,"%.3f", param.m_rankSep,""); agsafeset(g, "ranksep", str, ""); if(!param.m_useDefWH) { sprintf(str,"%s","fill"); agsafeset(g, "ratio", str,""); sprintf(str,"%.3f,%.3f", param.m_graphWidth, param.m_graphHeight); agsafeset(g, "size", str,""); } //依次添加节点和分支,并设置属性 for(Digraph::ArcIt e(dg); e!=INVALID; ++e) { Digraph::Node u = dg.source(e); Digraph::Node v = dg.target(e); //创建节点和分支 sprintf(str,"%d",dg.id(u)); Agnode_t* gu = agnode(g, str,1); // 节点u sprintf(str,"%d",dg.id(v)); Agnode_t* gv = agnode(g, str,1); // 节点v sprintf(str,"%d",dg.id(e)); Agedge_t* ge = agedge(g, gu, gv,str,1); // 分支e(u,v) sprintf(str,"v%d", dg.id(u)); agsafeset(gu,"label",str,""); sprintf(str,"v%d", dg.id(v)); agsafeset(gv,"label",str,""); sprintf(str,"e%d", dg.id(e)); agsafeset(ge,"label",str,""); // 设置节点u的属性 sprintf(str,"%.3f",param.m_nodeWidth); agsafeset(gu,"width",str,""); sprintf(str,"%.3f",param.m_nodeHeight); agsafeset(gu,"height",str,""); sprintf(str,"%.3f",param.m_nodeTextHeight); agsafeset(gu,"fontsize",str,""); //设置节点v的属性 sprintf(str,"%.3f",param.m_nodeWidth); agsafeset(gv,"width",str,""); sprintf(str,"%.3f",param.m_nodeHeight); agsafeset(gv,"height",str,""); sprintf(str,"%.3f",param.m_nodeTextHeight); agsafeset(gv,"fontsize",str,""); //设置分支e的属性 sprintf(str,"%s","none"); agsafeset(ge,"arrowhead",str,""); agsafeset(ge,"arrowtail",str,""); sprintf(str,"%.3f",param.m_edgeTextHeight); agsafeset(ge,"fontsize",str,""); } return g; }
/* * John M. suggests: * You might want to add four more: * * _ohdraw_ (optional head-end arrow for edges) * _ohldraw_ (optional head-end label for edges) * _otdraw_ (optional tail-end arrow for edges) * _otldraw_ (optional tail-end label for edges) * * that would be generated when an additional option is supplied to * dot, etc. and * these would be the arrow/label positions to use if a user want to flip the * direction of an edge (as sometimes is there want). * * N.B. John M. asks: * By the way, I don't know if you ever plan to add other letters for * the xdot spec, but could you reserve "a" and also "A" (for attribute), * "n" and also "N" (for numeric), "w" (for sWitch), "s" (for string) * and "t" (for tooltip) and "x" (for position). We use those letters in * our drawing spec (and also "<" and ">"), so if you start generating * output with them, it could break what we have. */ void extend_attrs(GVJ_t * job, graph_t *g, int s_arrows, int e_arrows) { node_t *n; edge_t *e; attrsym_t *n_draw = NULL; attrsym_t *n_l_draw = NULL; attrsym_t *e_draw = NULL; attrsym_t *h_draw = NULL; attrsym_t *t_draw = NULL; attrsym_t *e_l_draw = NULL; attrsym_t *hl_draw = NULL; attrsym_t *tl_draw = NULL; unsigned char buf0[BUFSIZ]; unsigned char buf1[BUFSIZ]; unsigned char buf2[BUFSIZ]; unsigned char buf3[BUFSIZ]; unsigned char buf4[BUFSIZ]; unsigned char buf5[BUFSIZ]; gvc = job->gvc; agsafeset (g, "xdotversion", XDOTVERSION, ""); if (GD_has_labels(g) & GRAPH_LABEL) g_l_draw = safe_dcl(g, g, "_ldraw_", "", agraphattr); else g_l_draw = NULL; if (GD_n_cluster(g)) g_draw = safe_dcl(g, g, "_draw_", "", agraphattr); else g_draw = NULL; n_draw = safe_dcl(g, g->proto->n, "_draw_", "", agnodeattr); n_l_draw = safe_dcl(g, g->proto->n, "_ldraw_", "", agnodeattr); e_draw = safe_dcl(g, g->proto->e, "_draw_", "", agedgeattr); if (e_arrows) h_draw = safe_dcl(g, g->proto->e, "_hdraw_", "", agedgeattr); if (s_arrows) t_draw = safe_dcl(g, g->proto->e, "_tdraw_", "", agedgeattr); if (GD_has_labels(g) & EDGE_LABEL) e_l_draw = safe_dcl(g, g->proto->e, "_ldraw_", "", agedgeattr); if (GD_has_labels(g) & HEAD_LABEL) hl_draw = safe_dcl(g, g->proto->e, "_hldraw_", "", agedgeattr); if (GD_has_labels(g) & TAIL_LABEL) tl_draw = safe_dcl(g, g->proto->e, "_tldraw_", "", agedgeattr); agxbinit(&xbuf0, BUFSIZ, buf0); agxbinit(&xbuf1, BUFSIZ, buf1); agxbinit(&xbuf2, BUFSIZ, buf2); agxbinit(&xbuf3, BUFSIZ, buf3); agxbinit(&xbuf4, BUFSIZ, buf4); agxbinit(&xbuf5, BUFSIZ, buf5); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (ND_shape(n) && !isInvis(late_string(n, N_style, ""))) { ND_shape(n)->fns->codefn(job, n); agxset(n, n_draw->index, agxbuse(xbufs[EMIT_NDRAW])); agxset(n, n_l_draw->index, agxbuse(xbufs[EMIT_NLABEL])); } if (State < GVSPLINES) continue; for (e = agfstout(g, n); e; e = agnxtout(g, e)) { if (ED_edge_type(e) == IGNORED) continue; if (isInvis(late_string(e, E_style, ""))) continue; if (ED_spl(e) == NULL) continue; emit_edge_graphics (job, e); agxset(e, e_draw->index, agxbuse(xbufs[EMIT_EDRAW])); if (t_draw) agxset(e, t_draw->index, agxbuse(xbufs[EMIT_TDRAW])); if (h_draw) agxset(e, h_draw->index, agxbuse(xbufs[EMIT_HDRAW])); if (e_l_draw) agxset(e, e_l_draw->index,agxbuse(xbufs[EMIT_ELABEL])); if (tl_draw) agxset(e, tl_draw->index, agxbuse(xbufs[EMIT_TLABEL])); if (hl_draw) agxset(e, hl_draw->index, agxbuse(xbufs[EMIT_HLABEL])); } } emit_background(job, g); if (agxblen(xbufs[EMIT_GDRAW])) { if (!g_draw) g_draw = safe_dcl(g, g, "_draw_", "", agraphattr); agxset(g, g_draw->index, agxbuse(xbufs[EMIT_GDRAW])); } if (GD_label(g)) { emit_label(job, EMIT_GLABEL, GD_label(g), (void *) g); agxset(g, g_l_draw->index, agxbuse(xbufs[EMIT_GLABEL])); } emit_clusters(job, g, 0); agxbfree(&xbuf0); agxbfree(&xbuf1); agxbfree(&xbuf2); agxbfree(&xbuf3); agxbfree(&xbuf4); agxbfree(&xbuf5); }
void QGVEdge::setAttribute(const QString &name, const QString &value) { agsafeset(_edge->edge(), name.toLocal8Bit().data(), value.toLocal8Bit().data(), (char *)""); }
void QGVSubGraph::setAttribute(const QString &name, const QString &value) { agsafeset(_sgraph->graph(), name.toLocal8Bit().data(), value.toLocal8Bit().data(), ""); }
/* * Print in Graphviz format */ void FA_dump_dot_fn(struct FA *fa, const char *ofname, int inc_step) { struct FA_State *st_from = NULL; struct FA_State *st_to = NULL; struct FA_State *st = NULL; GVC_t *gvc = NULL; graph_t *g = NULL; Agedge_t *e = NULL; Agnode_t *e_from = NULL; Agnode_t *e_to = NULL; Agnode_t *state0 = NULL; Agnode_t **nodes = NULL; Agnode_t *node = NULL; char *argv[4] = { NULL }; char buf[4096]; int argc; int i; int ri, ci, ai; FA_ASSERT(fa); ASSERT(ofname != NULL); ASSERT(inc_step == FA_INSERT_EXT || inc_step == FA_INSERT_NOTHING); memset(buf, 0, sizeof(buf)); if (inc_step == FA_INSERT_EXT) (void)snprintf(buf, sizeof(buf) - 1, "-o%s.%d", ofname, fa->simstep); else (void)snprintf(buf, sizeof(buf) - 1, "-o%s", ofname); argv[0] = strdup("FLViz.exe"); argv[1] = strdup(buf); argv[2] = strdup("-Tsvg"); argv[3] = NULL; argc = (sizeof(argv) / sizeof(argv[0])) - 1; gvc = gvContext(); ASSERT(gvc != NULL); gvParseArgs(gvc, argc, argv); memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf) - 1, "flvizstep%d", fa->simstep); g = agopen(buf, AGDIGRAPHSTRICT); /* Ustawianie atrybutów dla grafu */ agraphattr(g, "size", "8,8"); agraphattr(g, "rankdir", "LR"); /* Stan 0 */ state0 = agnode(g, "state0"); agsafeset(state0, "label", "", ""); agsafeset(state0, "width", "0.1", ""); agsafeset(state0, "height", "0.1", ""); agsafeset(state0, "shape", "box", ""); agsafeset(state0, "style", "filled", ""); agsafeset(state0, "fillcolor", "white", ""); agsafeset(state0, "color", "white", ""); nodes = (Agnode_t **)calloc(sizeof(Agnode_t *), fa->nstates); ASSERT(nodes != NULL); for (i = 0; i < fa->nstates; i++) { st = &fa->states[i]; node = agnode(g, st->name); agsafeset(node, "label", st->name, ""); agsafeset(node, "width", "0.5", ""); agsafeset(node, "height", "0.5", ""); agsafeset(node, "shape", "circle", ""); if (st->flag & FA_STATE_LAST) agsafeset(node, "shape", "doublecircle", ""); agsafeset(node, "style", "filled", ""); agsafeset(node, "fillcolor", "gray", ""); if (st->flag & FA_STATE_CURR) agsafeset(node, "fillcolor", "green", ""); st->obj = node; nodes[i] = node; } e = agedge(g, state0, (Agnode_t *)fa->states[0].obj); agsafeset(e, "label", "START", ""); if (fa->trans_from == fa->state0 && fa->trans_to == &fa->states[0]) agsafeset(e, "color", "green", ""); for (ri = 0; ri < fa->nstates; ri++) { st_from = fa->transt[ri][0]; e_from = (Agnode_t *)st_from->obj; for (ai = 0; ai < fa->nalpha; ai++) { ci = ai + 1; st_to = fa->transt[ri][ci]; if (st_to == NULL) continue; e_to = (Agnode_t *)st_to->obj; e = agedge(g, e_from, e_to); agsafeset(e, "label", fa->alpha[ai].word, ""); if (fa->trans_from == st_from && fa->trans_to == st_to) agsafeset(e, "color", "green", ""); } } /* Compute a layout using layout engine from command line args */ gvLayoutJobs(gvc, g); /* Write the graph according to -T and -o options */ gvRenderJobs(gvc, g); gvFreeLayout(gvc, g); agclose(g); gvFreeContext(gvc); fa->simstep++; }
void GVSkeletonGraph::setGraphObjectAttributes(void *object, QString attr, QString value){ setlocale(LC_NUMERIC,"en_US.UTF-8"); // Débug séparateur de décimales en version française agsafeset(object, const_cast<char *>(qPrintable(attr)),const_cast<char *>(qPrintable(value)),const_cast<char *>(qPrintable(value))); }
void QGVEdge::setAttribute(const QString &name, const QString &value) { QString emptyStr(""); agsafeset(_edge->edge(), name.toLocal8Bit().data(), value.toLocal8Bit().data(), emptyStr.toLocal8Bit().data()); }