1 ! Copyright (C) 2011 Alex Vondrak.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.data
4 alien.destructors alien.libraries alien.strings alien.syntax
5 combinators debugger destructors fry graphviz io
6 io.encodings.ascii kernel libc literals locals math memoize
7 prettyprint sequences specialized-arrays splitting system ;
8 SPECIALIZED-ARRAY: void*
13 { [ os macosx? ] [ "libgraph.dylib" ] }
14 { [ os unix? ] [ "libgraph.so" ] }
15 { [ os windows? ] [ "graph.dll" ] }
16 } cond cdecl add-library
20 { [ os macosx? ] [ "libgvc.dylib" ] }
21 { [ os unix? ] [ "libgvc.so" ] }
22 { [ os windows? ] [ "gvc.dll" ] }
23 } cond cdecl add-library
36 FUNCTION: Agraph_t* agopen ( c-string name, int kind ) ;
37 FUNCTION: Agraph_t* agsubg ( Agraph_t* g, c-string name ) ;
38 FUNCTION: void agclose ( Agraph_t* g ) ;
42 : kind ( graph -- magic-constant )
43 [ directed?>> ] [ strict?>> ] bi
44 [ 3 2 ? ] [ 1 0 ? ] if ;
48 FUNCTION: Agnode_t* agnode ( Agraph_t* g, c-string name ) ;
49 FUNCTION: Agnode_t* agfstnode ( Agraph_t* g ) ;
50 FUNCTION: Agnode_t* agnxtnode ( Agraph_t* g, Agnode_t* n ) ;
54 : next-node ( g n -- g n' )
55 [ dup ] dip agnxtnode ; inline
57 : (each-node) ( Agraph_t* Agnode_t* quot -- )
58 '[ [ nip @ ] 2keep next-node dup ] loop 2drop ; inline
62 : each-node ( Agraph_t* quot -- )
64 over [ (each-node) ] [ 3drop ] if ; inline
68 FUNCTION: Agedge_t* agedge ( Agraph_t* g,
74 FUNCTION: Agnode_t* agprotonode ( Agraph_t* g ) ;
75 FUNCTION: Agedge_t* agprotoedge ( Agraph_t* g ) ;
77 FUNCTION: c-string agget ( void* obj, c-string name ) ;
79 FUNCTION: int agsafeset ( void* obj,
91 FUNCTION: GVC_t* gvContext ( ) ;
95 FUNCTION-ALIAS: int-gvFreeContext
96 int gvFreeContext ( GVC_t* gvc ) ;
100 ERROR: ffi-errors n ;
102 "Graphviz FFI indicates that " write
104 " error(s) occurred while rendering." print
105 "(The messages were probably printed to STDERR.)" print ;
107 : gvFreeContext ( gvc -- )
108 int-gvFreeContext dup zero? [ drop ] [ ffi-errors ] if ;
110 DESTRUCTOR: gvFreeContext
114 FUNCTION: int gvLayout ( GVC_t* gvc,
117 FUNCTION: int gvFreeLayout ( GVC_t* gvc, Agraph_t* g ) ;
121 FUNCTION: int gvRenderFilename ( GVC_t* gvc,
124 c-string filename ) ;
126 ! Supported layout engines (dot, neato, etc.) and output
127 ! formats (png, jpg, etc.)
137 ! This function doesn't exist on the Linux mason in Graphviz 2.28
140 ( GVC_t* gvc, c-string kind, int* size, c-string str ) ;
142 :: Plugin-list ( kind-string -- seq )
144 gvContext &gvFreeContext
146 0 int <ref> dup :> size*
148 gvPluginList &(free) :> ret
149 size* int deref :> size
150 ret size void* <c-direct-array> [
151 &(free) ascii alien>string
155 ! This function doesn't exist on the Windows mason in Graphviz 2.28
158 ( GVC_t* gvc, api_t api, c-string str ) ;
160 : plugin-list ( API_t -- seq )
162 gvContext &gvFreeContext _ "" gvplugin_list
168 MEMO: supported-engines ( -- seq ) API_layout plugin-list ;
169 MEMO: supported-formats ( -- seq ) API_device plugin-list ;