forked from mdaines/viz-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviz.c
37 lines (29 loc) · 1.03 KB
/
viz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "cdt.h"
#include "gvc.h"
extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;
extern gvplugin_library_t gvplugin_core_LTX_library;
GVC_t *context = NULL;
char *last_result = NULL;
__attribute__((used)) char* vizRenderFromString(const char *string,
const char *format,
const char *engine) {
if (context == NULL) {
context = gvContext();
gvAddLibrary(context, &gvplugin_core_LTX_library);
gvAddLibrary(context, &gvplugin_dot_layout_LTX_library);
gvAddLibrary(context, &gvplugin_neato_layout_LTX_library);
}
Agraph_t *graph = agmemread((char*)string);
gvLayout(context, graph, engine);
char *result = NULL;
unsigned int length;
gvRenderData(context, graph, format, &result, &length);
gvFreeLayout(context, graph);
agclose(graph);
if (last_result != NULL) {
gvFreeRenderData(last_result);
}
last_result = result;
return result;
}