/
viz.c
74 lines (57 loc) · 1.5 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <gvc.h>
#include <emscripten.h>
extern int Y_invert;
extern int Nop;
extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
#ifndef VIZ_LITE
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;
#endif
char *errorMessage = NULL;
int vizErrorf(char *buf) {
errorMessage = buf;
return 0;
}
char* vizLastErrorMessage() {
return errorMessage;
}
void vizCreateFile(char *path, char *data) {
EM_ASM_({
var path = Pointer_stringify($0);
var data = Pointer_stringify($1);
FS.createPath("/", PATH.dirname(path));
FS.writeFile(PATH.join("/", path), data);
}, path, data);
}
void vizSetY_invert(int invert) {
Y_invert = invert;
}
void vizSetNop(int value) {
if (value != 0)
Nop = value;
}
char* vizRenderFromString(const char *src, const char *format, const char *engine) {
GVC_t *context;
Agraph_t *graph;
char *result = NULL;
unsigned int length;
context = gvContext();
gvAddLibrary(context, &gvplugin_core_LTX_library);
gvAddLibrary(context, &gvplugin_dot_layout_LTX_library);
#ifndef VIZ_LITE
gvAddLibrary(context, &gvplugin_neato_layout_LTX_library);
#endif
agseterr(AGERR);
agseterrf(vizErrorf);
agreadline(1);
while ((graph = agmemread(src))) {
if (result == NULL) {
gvLayout(context, graph, engine);
gvRenderData(context, graph, format, &result, &length);
gvFreeLayout(context, graph);
}
agclose(graph);
src = "";
}
return result;
}