16 #include <flecsi-config.h> 20 #if !defined(FLECSI_ENABLE_GRAPHVIZ) 21 #error FLECSI_ENABLE_GRAPHVIZ not defined! This file depends on Graphviz! 24 #include <graphviz/gvc.h> 30 static constexpr
const char * gv_graph =
"graph";
31 static constexpr
const char * gv_label_default =
"";
32 static constexpr
const char * gv_label =
"label";
33 static constexpr
const char * gv_color =
"color";
34 static constexpr
const char * gv_color_black =
"black";
35 static constexpr
const char * gv_penwidth =
"penwidth";
36 static constexpr
const char * gv_penwidth_default =
"";
37 static constexpr
const char * gv_shape =
"shape";
38 static constexpr
const char * gv_shape_default =
"ellipse";
39 static constexpr
const char * gv_style =
"style";
40 static constexpr
const char * gv_style_default =
"";
41 static constexpr
const char * gv_fill_color =
"fillcolor";
42 static constexpr
const char * gv_color_lightgrey =
"lightgrey";
43 static constexpr
const char * gv_font_color =
"fontcolor";
44 static constexpr
const char * gv_dir =
"dir";
45 static constexpr
const char * gv_dir_default =
"forward";
46 static constexpr
const char * gv_headport =
"headport";
47 static constexpr
const char * gv_headport_default =
"c";
48 static constexpr
const char * gv_tailport =
"tailport";
49 static constexpr
const char * gv_tailport_default =
"c";
50 static constexpr
const char * gv_arrowsize =
"arrowsize";
51 static constexpr
const char * gv_arrowsize_default =
"0.75";
52 static constexpr
const char * gv_arrowhead =
"arrowhead";
53 static constexpr
const char * gv_arrowhead_default =
"normal";
54 static constexpr
const char * gv_arrowtail =
"arrowtail";
55 static constexpr
const char * gv_arrowtail_default =
"normal";
57 #define GV_GRAPH const_cast<char *>(gv_graph) 58 #define GV_LABEL const_cast<char *>(gv_label) 59 #define GV_LABEL_DEFAULT const_cast<char *>(gv_label_default) 60 #define GV_PENWIDTH const_cast<char *>(gv_penwidth) 61 #define GV_PENWIDTH_DEFAULT const_cast<char *>(gv_penwidth_default) 62 #define GV_COLOR const_cast<char *>(gv_color) 63 #define GV_COLOR_BLACK const_cast<char *>(gv_color_black) 64 #define GV_SHAPE const_cast<char *>(gv_shape) 65 #define GV_SHAPE_DEFAULT const_cast<char *>(gv_shape_default) 66 #define GV_STYLE const_cast<char *>(gv_style) 67 #define GV_STYLE_DEFAULT const_cast<char *>(gv_style_default) 68 #define GV_FILL_COLOR const_cast<char *>(gv_fill_color) 69 #define GV_COLOR_LIGHTGREY const_cast<char *>(gv_color_lightgrey) 70 #define GV_FONT_COLOR const_cast<char *>(gv_font_color) 71 #define GV_DIR const_cast<char *>(gv_dir) 72 #define GV_DIR_DEFAULT const_cast<char *>(gv_dir_default) 73 #define GV_HEADPORT const_cast<char *>(gv_headport) 74 #define GV_HEADPORT_DEFAULT const_cast<char *>(gv_headport_default) 75 #define GV_TAILPORT const_cast<char *>(gv_tailport) 76 #define GV_TAILPORT_DEFAULT const_cast<char *>(gv_tailport_default) 77 #define GV_ARROWSIZE const_cast<char *>(gv_arrowsize) 78 #define GV_ARROWSIZE_DEFAULT const_cast<char *>(gv_arrowsize_default) 79 #define GV_ARROWHEAD const_cast<char *>(gv_arrowhead) 80 #define GV_ARROWHEAD_DEFAULT const_cast<char *>(gv_arrowhead_default) 81 #define GV_ARROWTAIL const_cast<char *>(gv_arrowtail) 82 #define GV_ARROWTAIL_DEFAULT const_cast<char *>(gv_arrowtail_default) 84 const int ag_create(1);
85 const int ag_access(0);
94 graphviz() : gvc_(
nullptr), graph_(
nullptr) {
100 if(graph_ !=
nullptr) {
101 gvFreeLayout(gvc_, graph_);
115 if(graph_ !=
nullptr) {
116 gvFreeLayout(gvc_, graph_);
120 graph_ = agopen(GV_GRAPH, Agdirected,
nullptr);
122 graph_, AGRAPH, const_cast<char *>(
"nodesep"), const_cast<char *>(
".5"));
125 agattr(graph_, AGNODE, GV_LABEL, GV_LABEL_DEFAULT);
126 agattr(graph_, AGNODE, GV_PENWIDTH, GV_PENWIDTH_DEFAULT);
127 agattr(graph_, AGNODE, GV_COLOR, GV_COLOR_BLACK);
128 agattr(graph_, AGNODE, GV_SHAPE, GV_SHAPE_DEFAULT);
129 agattr(graph_, AGNODE, GV_STYLE, GV_STYLE_DEFAULT);
130 agattr(graph_, AGNODE, GV_FILL_COLOR, GV_COLOR_LIGHTGREY);
131 agattr(graph_, AGNODE, GV_FONT_COLOR, GV_COLOR_BLACK);
134 agattr(graph_, AGEDGE, GV_DIR, GV_DIR_DEFAULT);
135 agattr(graph_, AGEDGE, GV_LABEL, GV_LABEL_DEFAULT);
136 agattr(graph_, AGEDGE, GV_PENWIDTH, GV_PENWIDTH_DEFAULT);
137 agattr(graph_, AGEDGE, GV_COLOR, GV_COLOR_BLACK);
138 agattr(graph_, AGEDGE, GV_STYLE, GV_STYLE_DEFAULT);
139 agattr(graph_, AGEDGE, GV_FILL_COLOR, GV_COLOR_BLACK);
140 agattr(graph_, AGEDGE, GV_FONT_COLOR, GV_COLOR_BLACK);
141 agattr(graph_, AGEDGE, GV_HEADPORT, GV_HEADPORT_DEFAULT);
142 agattr(graph_, AGEDGE, GV_TAILPORT, GV_TAILPORT_DEFAULT);
143 agattr(graph_, AGEDGE, GV_ARROWSIZE, GV_ARROWSIZE_DEFAULT);
144 agattr(graph_, AGEDGE, GV_ARROWHEAD, GV_ARROWHEAD_DEFAULT);
145 agattr(graph_, AGEDGE, GV_ARROWTAIL, GV_ARROWTAIL_DEFAULT);
154 Agnode_t * add_node(
const char * name,
const char * label =
nullptr) {
156 sprintf(buffer,
"%s", name);
157 Agnode_t * node = agnode(graph_, buffer, ag_create);
159 if(label !=
nullptr) {
161 sprintf(attr,
"%s",
"label");
162 sprintf(buffer,
"%s", label);
163 agset(node, attr, buffer);
169 Agnode_t * node(
const char * name) {
171 sprintf(buffer,
"%s", name);
172 return agnode(graph_, buffer, ag_access);
179 void remove_node(
const char * name) {
181 sprintf(buffer,
"%s", name);
182 Agnode_t * node = agfindnode(graph_, buffer);
184 if(node !=
nullptr) {
185 agdelete(graph_, node);
194 set_node_attribute(
const char * name,
const char * attr,
const char * value) {
196 sprintf(buffer,
"%s", name);
197 Agnode_t * node = agnode(graph_, buffer, ag_access);
199 if(node ==
nullptr) {
200 flog(warn) <<
"node " << name <<
" does not exist";
206 sprintf(_attr,
"%s", attr);
207 sprintf(_value,
"%s", value);
208 agset(node, _attr, _value);
212 set_node_attribute(Agnode_t * node,
const char * attr,
const char * value) {
215 sprintf(_attr,
"%s", attr);
216 sprintf(_value,
"%s", value);
217 agset(node, _attr, _value);
224 void set_label(
const char * name,
const char * label) {
226 sprintf(buffer,
"%s", name);
227 Agnode_t * node = agnode(graph_, buffer, ag_access);
229 if(node ==
nullptr) {
230 flog(warn) <<
"node " << name <<
" does not exist";
234 set_node_attribute(name,
"label", label);
241 char * get_node_attribute(
const char * name,
const char * attr) {
243 sprintf(buffer,
"%s", name);
244 Agnode_t * node = agnode(graph_, buffer, ag_access);
246 if(node ==
nullptr) {
247 flog(warn) <<
"node " << name <<
" does not exist";
252 sprintf(_attr,
"%s", attr);
253 return agget(node, _attr);
256 int inedge_count(
const char * name) {
258 sprintf(buffer,
"%s", name);
259 Agnode_t * node = agnode(graph_, buffer, ag_access);
261 if(node ==
nullptr) {
262 flog(warn) <<
"node " << name <<
" does not exist";
266 return agdegree(graph_, node,
true,
false);
273 Agedge_t * add_edge(Agnode_t * parent, Agnode_t * child) {
274 return agedge(graph_, parent, child,
nullptr, ag_create);
278 set_edge_attribute(Agedge_t * edge,
const char * attr,
const char * value) {
281 sprintf(_attr,
"%s", attr);
282 sprintf(_value,
"%s", value);
283 agset(edge, _attr, _value);
290 void layout(
const char * engine) {
292 sprintf(_engine,
"%s", engine);
294 gvLayout(gvc_, graph_, _engine);
302 void write(
const std::string & name) {
306 void write(
const char * name) {
307 FILE * file = fopen(name,
"w");
309 if(name ==
nullptr) {
313 agwrite(graph_, file);
Definition: graphviz.hh:91
#define flog(severity)
Definition: flog.hh:136
#define flog_fatal(message)
Definition: flog.hh:358
Definition: control.hh:31