Graphviz 13.0.0~dev.20241212.1010
Loading...
Searching...
No Matches
demo.c
Go to the documentation of this file.
1
4
5/*************************************************************************
6 * Copyright (c) 2011 AT&T Intellectual Property
7 * All rights reserved. This program and the accompanying materials
8 * are made available under the terms of the Eclipse Public License v1.0
9 * which accompanies this distribution, and is available at
10 * https://www.eclipse.org/legal/epl-v10.html
11 *
12 * Contributors: Details at https://graphviz.org
13 *************************************************************************/
14
15/* Note that, with the call to gvParseArgs(), this application assumes that
16 * a known layout algorithm is going to be specified. This can be done either
17 * using argv[0] or requiring the user to run this code with a -K flag
18 * specifying which layout to use. In the former case, after this program has
19 * been built as 'demo', you will need to rename it as one of the installed
20 * layout engines such as dot, neato, sfdp, etc.
21 */
22#include <graphviz/gvc.h>
23
24int main(int argc, char **argv) {
25
26 // set up a graphviz context
27 GVC_t *gvc = gvContext();
28
29 // parse command line args - minimally argv[0] sets layout engine
30 gvParseArgs(gvc, argc, argv);
31
32 // Create a simple digraph
33 Agraph_t *g = agopen("g", Agdirected, 0);
34 Agnode_t *n = agnode(g, "n", 1);
35 Agnode_t *m = agnode(g, "m", 1);
36 Agedge_t *e = agedge(g, n, m, 0, 1);
37
38 // Set an attribute - in this case one that affects the visible rendering
39 agsafeset(n, "color", "red", "");
40
41 // Compute a layout using layout engine from command line args
42 gvLayoutJobs(gvc, g);
43
44 // Write the graph according to -T and -o options
45 gvRenderJobs(gvc, g);
46
47 // Free layout data
48 gvFreeLayout(gvc, g);
49
50 // Free graph structures
51 agclose(g);
52
53 // close output file, free context, and return number of errors
54 return gvFreeContext(gvc);
55}
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:102
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
Agdesc_t Agdirected
directed
Definition graph.c:284
Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
Definition node.c:147
int gvParseArgs(GVC_t *gvc, int argc, char **argv)
Definition args.c:220
int gvFreeLayout(GVC_t *gvc, graph_t *g)
Definition gvlayout.c:105
GVC_t * gvContext(void)
Definition gvc.c:24
int gvRenderJobs(GVC_t *gvc, graph_t *g)
Definition emit.c:3893
int gvLayoutJobs(GVC_t *gvc, graph_t *g)
Definition gvlayout.c:53
int gvFreeContext(GVC_t *gvc)
Definition gvcontext.c:64
static GVC_t * gvc
Definition gv.cpp:23
graph or subgraph
Definition cgraph.h:425
Definition gvcint.h:80
int main()