Example #1
0
/** Expose event handler.
 * @param event event info structure.
 * @return signal return value
 */
bool
SkillGuiGraphDrawingArea::on_expose_event(GdkEventExpose* event)
{
  update_translations();
  // This is where we draw on the window
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window) {
    //Gtk::Allocation allocation = get_allocation();
    //const int width = allocation.get_width();
    //const int height = allocation.get_height();
    
    // coordinates for the center of the window
    //int xc, yc;
    //xc = width / 2;
    //yc = height / 2;
    
    __cairo = window->create_cairo_context();
    __cairo->set_source_rgb(1, 1, 1);
    __cairo->paint();

    if (__graph) {
      Glib::Timer t;
      gvRender(__gvc, __graph, (char *)"skillguicairo", NULL);
      t.stop();
      //printf("Rendering took %f seconds\n", t.elapsed());
    }

    __cairo.clear();
  }
  return true;
}
// render to string result, using binding-dependent gv_string_writer()
void renderresult(Agraph_t *g, const char *format, char *outdata)
{
    int err;

    if (!g)
        return;
    gv_string_writer_init(gvc);
    err = gvRender(gvc, g, format, (FILE*)outdata);
}
// render to an open FILE
bool render(Agraph_t *g, const char *format, FILE *f)
{
    int err;

    if (!g)
        return false;
    err = gvRender(gvc, g, format, f);
    return (! err);
}
// render to an open channel  
bool renderchannel(Agraph_t *g, const char *format, const char *channelname)
{
    int err;

    if (!g)
        return false;
    gv_channel_writer_init(gvc);
    err = gvRender(gvc, g, format, (FILE*)channelname);
    return (! err);
}
Example #5
0
static void json_begin_graph(GVJ_t *job)
{
    if (job->render.id == FORMAT_JSON) {
	GVC_t* gvc = gvCloneGVC (job->gvc); 
	graph_t *g = job->obj->u.g;
	gvRender (gvc, g, "xdot", NULL); 
	gvFreeCloneGVC (gvc);
    }
    else if (job->render.id == FORMAT_JSON0) {
	attach_attrs(job->gvc->g);
    }
}
Example #6
0
int main(int argc, char **argv)
{
    Agraph_t *g;
    Agnode_t *n, *m;
    Agedge_t *e;
    Agsym_t *a;

#ifdef NO_LAYOUT_OR_RENDERING
    aginit();
#else
    /* set up a graphviz context - but only once even for multiple graphs */
    static GVC_t *gvc;

    if (!gvc)
    	gvc = gvContext();
#endif

    /* Create a simple digraph */
    g = agopen("g", AGDIGRAPH);
    n = agnode(g, "n");
    m = agnode(g, "m");
    e = agedge(g, n, m);

    /* Set an attribute - in this case one that affects the visible rendering */
    agsafeset(n, "color", "red", "");
    
#ifdef NO_LAYOUT_OR_RENDERING
    /* Just write the graph without layout */
    agwrite(g, stdout);
#else
    /* Use the directed graph layout engine */
    gvLayout(gvc, g, "dot");

    /* Output in .dot format */
    gvRender(gvc, g, "dot", stdout);

    gvFreeLayout(gvc, g);
#endif

    agclose(g);

    return 0;
}
Example #7
0
File: gvc.c Project: lucemia/r3
/**
 * Render a tree to tree graph image via graphviz (dot)
 */
int r3_tree_render_dot(node * tree)
{
    Agraph_t *g;
    /* set up a graphviz context - but only once even for multiple graphs */
    static GVC_t *gvc;

    if (!gvc) {
        gvc = gvContext();
    }
    /* Create a simple digraph */
    g = agopen("g", Agdirected, 0);

    // create self node
    Agnode_t *ag_root = agnode(g, "{root}", 1);
    r3_tree_build_ag_nodes(g, ag_root, tree, 0);
    gvLayout(gvc, g, "dot");
    gvRender(gvc, g, "dot", stdout);
    gvFreeLayout(gvc, g);
    agclose(g);
    return 0;
}
Example #8
0
int main (int argc, char* argv[])
{
    graph_t *g;
    graph_t *sg;
    FILE *fp;
    graph_t** cc;
    int       i, ncc;
    GVC_t *gvc;

    gvc = gvContext();

    if (argc > 1)
        fp = fopen(argv[1], "r");
    else
        fp = stdin;
    g = agread(fp, 0);

    cc = ccomps(g, &ncc, (char*)0);

    for (i = 0; i < ncc; i++) {
        sg = cc[i];
        nodeInduce (sg);
        gvLayout(gvc, sg, "neato");
    }
    pack_graph (ncc, cc, g, 0);

    gvRender(gvc, g, "ps", stdout);

    for (i = 0; i < ncc; i++) {
        sg = cc[i];
        gvFreeLayout(gvc, sg);
        agdelete(g, sg);
    }

    agclose(g);

    return (gvFreeContext(gvc));

}
Example #9
0
void QGVScene::render (const QString &algorithm) {
  gvRender(_context->context(), _graph->graph(),
      algorithm.toLocal8Bit().data(), NULL);
}
Example #10
0
/** save current graph. */
void
SkillGuiGraphDrawingArea::save()
{
  Gtk::Window *w = dynamic_cast<Gtk::Window *>(get_toplevel());
  __fcd_save->set_transient_for(*w);

  int result = __fcd_save->run();
  if (result == Gtk::RESPONSE_OK) {

    Gtk::FileFilter *f = __fcd_save->get_filter();
    std::string filename = __fcd_save->get_filename();
    if (filename != "") {
      if (f == __filter_dot) {
	save_dotfile(filename.c_str());
      } else {
	Cairo::RefPtr<Cairo::Surface> surface;

	bool write_to_png = false;
	if (f == __filter_pdf) {
	  surface = Cairo::PdfSurface::create(filename, __bbw, __bbh);
	} else if (f == __filter_svg) {
	  surface = Cairo::SvgSurface::create(filename, __bbw, __bbh);
	} else if (f == __filter_png) {
	  surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
						(int)ceilf(__bbw),
						(int)ceilf(__bbh));
	  write_to_png = true;
	}

	if (surface) {
	  __cairo = Cairo::Context::create(surface);
	  
	  bool old_scale_override = __scale_override;
	  double old_tx = __translation_x;
	  double old_ty = __translation_y;
	  double old_scale = __scale;
	  __translation_x = __pad_x;
	  __translation_y = __bbh - __pad_y;
	  __scale = 1.0;
	  __scale_override = true;

	  if (__graph) {
	    gvRender(__gvc, __graph, (char *)"skillguicairo", NULL);
	  }

	  if (write_to_png) {
	    surface->write_to_png(filename);
	  }

	  __cairo.clear();

	  __translation_x = old_tx;
	  __translation_y = old_ty;
	  __scale = old_scale;
	  __scale_override = old_scale_override;
	}
      }

    } else {
      Gtk::MessageDialog md(*w, "Invalid filename",
			    /* markup */ false, Gtk::MESSAGE_ERROR,
			    Gtk::BUTTONS_OK, /* modal */ true);
      md.set_title("Invalid File Name");
      md.run();
    }
  }

  __fcd_save->hide();
}
Example #11
0
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));
}
Example #12
0
// render to a FILE
void render(Agraph_t *g, char *format, FILE *f)
{
    int err;

    err = gvRender(gvc, g, format, f);
}
Example #13
0
// render to stdout
void render(Agraph_t *g, char *format)
{
    int err;

    err = gvRender(gvc, g, format, stdout);
}