Skip to content
Newer
Older
100644 95 lines (80 sloc) 2.33 KB
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
1 /*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 */
2614a7c [doc] review: Review of stdlib.graph
Guillem Rieu authored Jun 24, 2011
18
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
19 /**
20 * Utils for calling dot (using external plugin)
21 * Part of the fgraph lib
22 *
23 * @author Mathieu Barbin
24 * @category algorithmic
25 * @destination public
26 * @stabilization Totally untested, beware by using this code
27 */
28
2614a7c [doc] review: Review of stdlib.graph
Guillem Rieu authored Jun 24, 2011
29 /**
30 * {1 About this module}
31 *
32 * An interface to use dot in OPA.
33 *
34 * {1 Where should I start?}
35 *
36 * {1 What if I need more?}
37 */
38
39 /**
40 * {1 Types defined in this module}
41 */
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
42
43 /**
44 * Several supported output images format, using external {it dot} command line tool
45 **/
46 type Dot.format =
47 {png}
48 / {svg}
49 / {jpg}
50
2614a7c [doc] review: Review of stdlib.graph
Guillem Rieu authored Jun 24, 2011
51 /**
52 * {1 Interface}
53 */
54
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
55 Dot = {{
56
57 /**
58 * Convert the format into the option taken by the {it dot} application.
59 **/
60 format_to_string =
61 | {png} -> "png"
62 | {svg} -> "svg"
63 | {jpg} -> "jpg"
64
65 /**
66 * [Dot.convert(format, dot_source)]
67 * Convert a dot format source into a raw string, expressed
68 * in the given format, using a sys command to {it dot}.
69 * The given source should be written in the dot syntax
70 **/
71 convert(format : Dot.format, source) =
72 exec = %%BslSys.Process.exec%%
73 format = format_to_string(format)
74 command = "dot -T{format}"
1efb591 [enhance] stdlib: replace most jlog in stdlib
Hugo Heuzard authored Nov 17, 2011
75 do Log.info("Dot","calling external dot tool")
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
76 exec(command, source)
77
78 /**
2614a7c [doc] review: Review of stdlib.graph
Guillem Rieu authored Jun 24, 2011
79 * Parse the svg output of {it dot}, and extract the svg part (hackish)
fccc685 Initial open-source release
MLstate authored Jun 21, 2011
80 * for building an xhtml opa representation of a graph.
81 **/
82 @private find_svg=parser
83 | svg=("<svg" .*) -> Text.to_string(svg)
84 | . rem=find_svg -> rem
85
86 /**
87 * Convert to xhtml using the unsafe import.
88 * This function perform a sys call to {it dot}, on the server side.
89 **/
90 to_xhtml(source) =
91 unsafe_svg = convert({svg}, source)
92 unsafe_svg = Parser.parse(find_svg, unsafe_svg)
93 Xhtml.of_string_unsafe(unsafe_svg)
94 }}
Something went wrong with that request. Please try again.