Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
example.c
Go to the documentation of this file.
1
4
5#include <graphviz/gvc.h>
6#include <stdio.h>
7#include <stdlib.h>
8
9#define NO_LAYOUT_OR_RENDERING
10
11int main(void) {
12#ifndef NO_LAYOUT_OR_RENDERING
13 // set up a graphviz context - but only once even for multiple graphs
14 GVC_t *gvc = gvContext();
15#endif
16
17 // Create a simple digraph
18 Agraph_t *g = agopen("g", Agdirected, 0);
19 Agnode_t *n = agnode(g, "n", 1);
20 Agnode_t *m = agnode(g, "m", 1);
21 Agedge_t *e = agedge(g, n, m, 0, 1);
22
23 // Set an attribute - in this case one that affects the visible rendering
24 agsafeset(n, "color", "red", "");
25
26#ifdef NO_LAYOUT_OR_RENDERING
27 // Just write the graph without layout
28 agwrite(g, stdout);
29#else
30 // Use the directed graph layout engine
31 gvLayout(gvc, g, "dot");
32
33 // Output in .dot format
34 gvRender(gvc, g, "dot", stdout);
35
36 gvFreeLayout(gvc, g);
37#endif
38
39 agclose(g);
40
41 return EXIT_SUCCESS;
42}
int main(void)
Definition example.c:11
int agsafeset(void *obj, char *name, const char *value, const char *def)
ensures the given attribute is declared before setting it locally on an object
Definition attr.c:510
Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
Definition edge.c:260
int agclose(Agraph_t *g)
deletes a graph, freeing its associated storage
Definition graph.c:96
Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
creates a new graph with the given name and kind
Definition graph.c:44
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Definition write.c:708
Agdesc_t Agdirected
directed
Definition graph.c:273
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition node.c:147
int gvFreeLayout(GVC_t *gvc, graph_t *g)
Definition gvlayout.c:105
int gvLayout(GVC_t *gvc, graph_t *g, const char *engine)
Definition gvc.c:52
GVC_t * gvContext(void)
Definition gvc.c:24
int gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out)
Definition gvc.c:84
GVC_t * gvc
Definition htmlparse.c:99
graph or subgraph
Definition cgraph.h:425
Definition gvcint.h:80