ruby-graphviz_c 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemrc +0 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/AUTHORS.rdoc +33 -0
- data/CHANGELOG.rdoc +287 -0
- data/COPYING.rdoc +133 -0
- data/Gemfile +4 -0
- data/README.rdoc +206 -0
- data/Rakefile +71 -0
- data/bin/dot2ruby +91 -0
- data/bin/gem2gv +165 -0
- data/bin/git2gv +167 -0
- data/bin/ruby2gv +234 -0
- data/bin/xml2gv +96 -0
- data/examples/dot/JSP.dot +52 -0
- data/examples/dot/balanced.dot +36 -0
- data/examples/dot/cluster.dot +30 -0
- data/examples/dot/dotgraph.dot +28 -0
- data/examples/dot/fsm.dot +20 -0
- data/examples/dot/genetic.dot +118 -0
- data/examples/dot/hello.dot +1 -0
- data/examples/dot/hello_test.rb +33 -0
- data/examples/dot/lion_share.dot +103 -0
- data/examples/dot/prof.dot +150 -0
- data/examples/dot/psg.dot +28 -0
- data/examples/dot/rank.dot +6 -0
- data/examples/dot/sdh.dot +284 -0
- data/examples/dot/siblings.dot +492 -0
- data/examples/dot/so-sample001.gv +30 -0
- data/examples/dot/so-sample002.gv +33 -0
- data/examples/dot/so-sample003.gv +45 -0
- data/examples/dot/test.dot +17 -0
- data/examples/dot/test_parse.rb +13 -0
- data/examples/dot/this_crach_with_dot_2.20.dot +24 -0
- data/examples/dot/unix.dot +104 -0
- data/examples/graphml/attributes.ext.graphml +12 -0
- data/examples/graphml/attributes.graphml +40 -0
- data/examples/graphml/cluster.graphml +75 -0
- data/examples/graphml/failed_graph.graphml +461 -0
- data/examples/graphml/hyper.graphml +29 -0
- data/examples/graphml/nested.graphml +54 -0
- data/examples/graphml/port.graphml +32 -0
- data/examples/graphml/simple.graphml +30 -0
- data/examples/hello.png +0 -0
- data/examples/rgv/rgv.ps +125 -0
- data/examples/rgv/test_rgv.rb +12 -0
- data/examples/sample01.rb +32 -0
- data/examples/sample02.rb +42 -0
- data/examples/sample03.rb +31 -0
- data/examples/sample04.rb +22 -0
- data/examples/sample05.rb +32 -0
- data/examples/sample06.rb +46 -0
- data/examples/sample07.rb +23 -0
- data/examples/sample08.rb +34 -0
- data/examples/sample09.rb +50 -0
- data/examples/sample10.rb +50 -0
- data/examples/sample11.rb +42 -0
- data/examples/sample12.rb +55 -0
- data/examples/sample13.rb +48 -0
- data/examples/sample14.rb +44 -0
- data/examples/sample15.rb +25 -0
- data/examples/sample16.rb +8 -0
- data/examples/sample17.rb +92 -0
- data/examples/sample18.rb +24 -0
- data/examples/sample19.rb +59 -0
- data/examples/sample20.rb +47 -0
- data/examples/sample21.rb +12 -0
- data/examples/sample22.rb +10 -0
- data/examples/sample23.rb +11 -0
- data/examples/sample24.rb +11 -0
- data/examples/sample25.rb +11 -0
- data/examples/sample26.rb +8 -0
- data/examples/sample27.rb +8 -0
- data/examples/sample28.rb +12 -0
- data/examples/sample29.rb +8 -0
- data/examples/sample30.rb +12 -0
- data/examples/sample31.rb +10 -0
- data/examples/sample32.rb +14 -0
- data/examples/sample33.rb +43 -0
- data/examples/sample34.rb +29 -0
- data/examples/sample35.rb +43 -0
- data/examples/sample36.rb +35 -0
- data/examples/sample37.rb +87 -0
- data/examples/sample38.rb +12 -0
- data/examples/sample39.rb +11 -0
- data/examples/sample40.rb +17 -0
- data/examples/sample41.rb +8 -0
- data/examples/sample42.rb +35 -0
- data/examples/sample43.rb +26 -0
- data/examples/sample44.rb +97 -0
- data/examples/sample45.rb +24 -0
- data/examples/sample46.rb +43 -0
- data/examples/sample47.rb +7 -0
- data/examples/sample48.rb +62 -0
- data/examples/sample49.rb +10 -0
- data/examples/sample50.rb +215 -0
- data/examples/sample51.rb +37 -0
- data/examples/sample52.rb +62 -0
- data/examples/sample53.rb +26 -0
- data/examples/sample54.rb +26 -0
- data/examples/sample55.rb +9 -0
- data/examples/sample56.rb +10 -0
- data/examples/sample57.rb +8 -0
- data/examples/sample58.rb +33 -0
- data/examples/sample59.rb +14 -0
- data/examples/sample60.rb +12 -0
- data/examples/sample61.rb +12 -0
- data/examples/sample62.rb +24 -0
- data/examples/sample63.rb +32 -0
- data/examples/sample64.rb +31 -0
- data/examples/sample65.rb +9 -0
- data/examples/sample66.rb +4 -0
- data/examples/sample67.rb +10 -0
- data/examples/sample68.rb +27 -0
- data/examples/sample69.rb +23 -0
- data/examples/sample70.rb +9 -0
- data/examples/sample99.rb +70 -0
- data/examples/sdlshapes/README +2 -0
- data/examples/sdlshapes/sdl.ps +655 -0
- data/examples/sdlshapes/sdlshapes.dot +78 -0
- data/examples/test.xml +26 -0
- data/examples/theory/pert.rb +47 -0
- data/examples/theory/tests.rb +87 -0
- data/lib/ext/gvpr/dot2ruby.g +185 -0
- data/lib/graphviz/attrs.rb +73 -0
- data/lib/graphviz/constants.rb +294 -0
- data/lib/graphviz/core_ext.rb +64 -0
- data/lib/graphviz/dot2ruby.rb +59 -0
- data/lib/graphviz/dot_script.rb +109 -0
- data/lib/graphviz/dsl.rb +67 -0
- data/lib/graphviz/edge.rb +197 -0
- data/lib/graphviz/elements.rb +39 -0
- data/lib/graphviz/ext.rb +17 -0
- data/lib/graphviz/family_tree/couple.rb +63 -0
- data/lib/graphviz/family_tree/generation.rb +39 -0
- data/lib/graphviz/family_tree/person.rb +120 -0
- data/lib/graphviz/family_tree/sibling.rb +13 -0
- data/lib/graphviz/family_tree.rb +118 -0
- data/lib/graphviz/graphml.rb +268 -0
- data/lib/graphviz/math/matrix.rb +221 -0
- data/lib/graphviz/node.rb +160 -0
- data/lib/graphviz/nothugly/nothugly.xsl +321 -0
- data/lib/graphviz/nothugly.rb +63 -0
- data/lib/graphviz/theory.rb +321 -0
- data/lib/graphviz/types/arrow_type.rb +32 -0
- data/lib/graphviz/types/color.rb +58 -0
- data/lib/graphviz/types/color_list.rb +24 -0
- data/lib/graphviz/types/esc_string.rb +20 -0
- data/lib/graphviz/types/gv_bool.rb +49 -0
- data/lib/graphviz/types/gv_double.rb +32 -0
- data/lib/graphviz/types/html_string.rb +18 -0
- data/lib/graphviz/types/lbl_string.rb +22 -0
- data/lib/graphviz/types/rect.rb +35 -0
- data/lib/graphviz/types/spline_type.rb +77 -0
- data/lib/graphviz/types.rb +22 -0
- data/lib/graphviz/utils/colors.rb +1018 -0
- data/lib/graphviz/utils.rb +70 -0
- data/lib/graphviz/xml.rb +119 -0
- data/lib/graphviz.rb +967 -0
- data/lib/ruby-graphviz.rb +1 -0
- data/man/dot2ruby.1 +66 -0
- data/man/dot2ruby.1.ronn +55 -0
- data/man/gem2gv.1 +60 -0
- data/man/gem2gv.1.ronn +47 -0
- data/man/git2gv.1 +48 -0
- data/man/git2gv.1.ronn +40 -0
- data/man/ruby2gv.1 +60 -0
- data/man/ruby2gv.1.ronn +47 -0
- data/man/xml2gv.1 +48 -0
- data/man/xml2gv.1.ronn +39 -0
- data/ruby-graphviz.gemspec +47 -0
- data/setup.rb +1585 -0
- data/test/helper.rb +13 -0
- data/test/support.rb +95 -0
- data/test/test_dot_script.rb +47 -0
- data/test/test_examples.rb +151 -0
- data/test/test_graph.rb +115 -0
- data/test/test_search.rb +29 -0
- data/test/test_subgraph.rb +27 -0
- data/test/test_theory.rb +98 -0
- data/test/test_types.rb +65 -0
- data/test/test_utils_colors.rb +52 -0
- metadata +301 -0
@@ -0,0 +1,294 @@
|
|
1
|
+
# Copyright (C) 2004 - 2012 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
2
|
+
#
|
3
|
+
# This program is free software; you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation; either version 2 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
+
|
17
|
+
# Constants for ruby-graphviz
|
18
|
+
#
|
19
|
+
# GraphViz::Constants::FORMATS: the possible output formats
|
20
|
+
# "bmp", "canon", "dot", "xdot", "cmap", "dia", "eps",
|
21
|
+
# "fig", "gd", "gd2", "gif", "gtk", "hpgl", "ico", "imap",
|
22
|
+
# "cmapx", "imap_np", "cmapx_np", "ismap", "jpeg", "jpg",
|
23
|
+
# "jpe", "mif", "mp", "pcl", "pdf", "pic", "plain",
|
24
|
+
# "plain-ext", "png", "ps", "ps2", "svg", "svgz", "tga",
|
25
|
+
# "tiff", "tif", "vml", "vmlz", "vrml", "vtx", "wbmp",
|
26
|
+
# "xlib", "none"
|
27
|
+
#
|
28
|
+
# GraphViz::Constants::PROGRAMS: The possible programs
|
29
|
+
# "dot", "neato", "twopi", "fdp", "circo"
|
30
|
+
#
|
31
|
+
# GraphViz::Constants::GRAPHTYPE The possible types of graph
|
32
|
+
# "digraph", "graph"
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# The single letter codes used in constructors map as follows:
|
36
|
+
# G => The root graph, with GRAPHATTRS
|
37
|
+
# E => Edge, with EDGESATTRS
|
38
|
+
# N => Node, with NODESATTRS
|
39
|
+
# S => subgraph
|
40
|
+
# C => cluster
|
41
|
+
#
|
42
|
+
class GraphViz
|
43
|
+
module Constants
|
44
|
+
RGV_VERSION = "1.1.0"
|
45
|
+
|
46
|
+
## Const: Output formats
|
47
|
+
FORMATS = [
|
48
|
+
"bmp",
|
49
|
+
"canon",
|
50
|
+
"dot",
|
51
|
+
"xdot",
|
52
|
+
"cmap",
|
53
|
+
"dia",
|
54
|
+
"eps",
|
55
|
+
"fig",
|
56
|
+
"gd",
|
57
|
+
"gd2",
|
58
|
+
"gif",
|
59
|
+
"gtk",
|
60
|
+
"hpgl",
|
61
|
+
"ico",
|
62
|
+
"imap",
|
63
|
+
"cmapx",
|
64
|
+
"imap_np",
|
65
|
+
"cmapx_np",
|
66
|
+
"ismap",
|
67
|
+
"jpeg",
|
68
|
+
"jpg",
|
69
|
+
"jpe",
|
70
|
+
"mif",
|
71
|
+
"mp",
|
72
|
+
"pcl",
|
73
|
+
"pdf",
|
74
|
+
"pic",
|
75
|
+
"plain",
|
76
|
+
"plain-ext",
|
77
|
+
"png",
|
78
|
+
"ps",
|
79
|
+
"ps2",
|
80
|
+
"svg",
|
81
|
+
"svgz",
|
82
|
+
"tga",
|
83
|
+
"tiff",
|
84
|
+
"tif",
|
85
|
+
"vml",
|
86
|
+
"vmlz",
|
87
|
+
"vrml",
|
88
|
+
"vtx",
|
89
|
+
"wbmp",
|
90
|
+
"xlib",
|
91
|
+
"none"
|
92
|
+
]
|
93
|
+
|
94
|
+
## Const: programs
|
95
|
+
PROGRAMS = [
|
96
|
+
"dot",
|
97
|
+
"neato",
|
98
|
+
"twopi",
|
99
|
+
"fdp",
|
100
|
+
"circo",
|
101
|
+
"sfdp"
|
102
|
+
]
|
103
|
+
|
104
|
+
## Const: graphs type
|
105
|
+
GRAPHTYPE = [
|
106
|
+
"digraph",
|
107
|
+
"graph",
|
108
|
+
"strict digraph"
|
109
|
+
]
|
110
|
+
|
111
|
+
def self.getAttrsFor( x )
|
112
|
+
list = {}
|
113
|
+
GENCS_ATTRS.each { |k,v|
|
114
|
+
list[k] = v[:type] if x.match( v[:usedBy] ) and not list.keys.include?(k)
|
115
|
+
}
|
116
|
+
list
|
117
|
+
end
|
118
|
+
|
119
|
+
# E, N, G, S and C represent edges, nodes, the root graph, subgraphs and cluster subgraphs, respectively
|
120
|
+
GENCS_ATTRS = {
|
121
|
+
"Damping" => { :usedBy => "G", :type => :GvDouble },
|
122
|
+
"K" => { :usedBy => "GC", :type => :GvDouble },
|
123
|
+
"URL" => { :usedBy => "ENGC", :type => :EscString },
|
124
|
+
"area" => { :usedBy => "NC", :type => :GvDouble },
|
125
|
+
"arrowhead" => { :usedBy => "E", :type => :ArrowType }, # arrowType
|
126
|
+
"arrowsize" => { :usedBy => "E", :type => :GvDouble },
|
127
|
+
"arrowtail" => { :usedBy => "E", :type => :ArrowType }, # arrowType
|
128
|
+
"aspect" => { :usedBy => "G", :type => :EscString }, # aspectType
|
129
|
+
"bb" => { :usedBy => "G", :type => :Rect }, # rect
|
130
|
+
"bgcolor" => { :usedBy => "GC", :type => :Color }, # color
|
131
|
+
"center" => { :usedBy => "G", :type => :GvBool }, # bool
|
132
|
+
"charset" => { :usedBy => "G", :type => :EscString }, # string
|
133
|
+
"clusterrank" => { :usedBy => "G", :type => :EscString }, # clusterMode
|
134
|
+
"color" => { :usedBy => "ENC", :type => :ColorList }, # color, colorList
|
135
|
+
"colorscheme" => { :usedBy => "ENCG", :type => :EscString }, # string
|
136
|
+
"comment" => { :usedBy => "ENG", :type => :EscString }, # string
|
137
|
+
"compound" => { :usedBy => "G", :type => :GvBool }, # bool
|
138
|
+
"concentrate" => { :usedBy => "G", :type => :GvBool }, # bool
|
139
|
+
"constraint" => { :usedBy => "E", :type => :GvBool }, # bool
|
140
|
+
"decorate" => { :usedBy => "E", :type => :GvBool }, # bool
|
141
|
+
"defaultdist" => { :usedBy => "G", :type => :GvDouble },
|
142
|
+
"dim" => { :usedBy => "G", :type => :EscString }, # int
|
143
|
+
"dimen" => { :usedBy => "G", :type => :EscString }, # int
|
144
|
+
"dir" => { :usedBy => "E", :type => :EscString }, # dirType
|
145
|
+
"diredgeconstraints" => { :usedBy => "G", :type => :EscString }, # string, bool
|
146
|
+
"distortion" => { :usedBy => "N", :type => :GvDouble },
|
147
|
+
"dpi" => { :usedBy => "G", :type => :GvDouble },
|
148
|
+
"edgeURL" => { :usedBy => "E", :type => :EscString },
|
149
|
+
"edgehref" => { :usedBy => "E", :type => :EscString },
|
150
|
+
"edgetarget" => { :usedBy => "E", :type => :EscString },
|
151
|
+
"edgetooltip" => { :usedBy => "E", :type => :EscString },
|
152
|
+
"epsilon" => { :usedBy => "G", :type => :GvDouble },
|
153
|
+
"esep" => { :usedBy => "G", :type => :EscString }, # GvDouble , pointf
|
154
|
+
"fillcolor" => { :usedBy => "NEC", :type => :Color }, # color
|
155
|
+
"fixedsize" => { :usedBy => "N", :type => :GvBool }, # bool
|
156
|
+
"fontcolor" => { :usedBy => "ENGC", :type => :Color }, # color
|
157
|
+
"fontname" => { :usedBy => "ENGC", :type => :EscString }, # string
|
158
|
+
"fontnames" => { :usedBy => "G", :type => :EscString }, # string
|
159
|
+
"fontpath" => { :usedBy => "G", :type => :EscString }, # string
|
160
|
+
"fontsize" => { :usedBy => "ENGC", :type => :GvDouble },
|
161
|
+
"forcelabels" => { :usedBy => "G", :type => :GvBool}, # bool
|
162
|
+
"gradientangle" => { :usedBy => "NCG", :type => :EscString }, # int
|
163
|
+
"group" => { :usedBy => "N", :type => :EscString }, # string
|
164
|
+
"headURL" => { :usedBy => "E", :type => :EscString },
|
165
|
+
"headclip" => { :usedBy => "E", :type => :GvBool }, # bool
|
166
|
+
"headhref" => { :usedBy => "E", :type => :EscString },
|
167
|
+
"headlabel" => { :usedBy => "E", :type => :EscString }, # LblString
|
168
|
+
"headport" => { :usedBy => "E", :type => :EscString }, # portPos
|
169
|
+
"headtarget" => { :usedBy => "E", :type => :EscString },
|
170
|
+
"headtooltip" => { :usedBy => "E", :type => :EscString },
|
171
|
+
"height" => { :usedBy => "N", :type => :GvDouble },
|
172
|
+
"href" => { :usedBy => "ENGC", :type => :EscString },
|
173
|
+
"id" => { :usedBy => "ENG", :type => :EscString },
|
174
|
+
"image" => { :usedBy => "N", :type => :EscString }, # string
|
175
|
+
"imagepath" => { :usedBy => "G", :type => :EscString }, # string
|
176
|
+
"imagescale" => { :usedBy => "N", :type => :EscString }, # bool, string
|
177
|
+
"label" => { :usedBy => "ENGC", :type => :LblString },
|
178
|
+
"labelURL" => { :usedBy => "E", :type => :EscString },
|
179
|
+
"label_scheme" => { :usedBy => "G", :type => :EscString }, # int
|
180
|
+
"labelangle" => { :usedBy => "E", :type => :GvDouble },
|
181
|
+
"labeldistance" => { :usedBy => "E", :type => :GvDouble },
|
182
|
+
"labelfloat" => { :usedBy => "E", :type => :GvBool }, # bool
|
183
|
+
"labelfontcolor" => { :usedBy => "E", :type => :Color }, # color
|
184
|
+
"labelfontname" => { :usedBy => "E", :type => :EscString }, # string
|
185
|
+
"labelfontsize" => { :usedBy => "E", :type => :GvDouble },
|
186
|
+
"labelhref" => { :usedBy => "E", :type => :EscString },
|
187
|
+
"labeljust" => { :usedBy => "GC", :type => :EscString }, # string
|
188
|
+
"labelloc" => { :usedBy => "GCN", :type => :EscString }, # string
|
189
|
+
"labeltarget" => { :usedBy => "E", :type => :EscString },
|
190
|
+
"labeltooltip" => { :usedBy => "E", :type => :EscString },
|
191
|
+
"landscape" => { :usedBy => "G", :type => :GvBool }, # bool
|
192
|
+
"layer" => { :usedBy => "ENC", :type => :EscString }, # layerRange
|
193
|
+
"layerlistsep" => { :usedBy => "G", :type => :EscString }, # string
|
194
|
+
"layers" => { :usedBy => "G", :type => :EscString }, # layerList
|
195
|
+
"layerselect" => { :usedBy => "G", :type => :EscString }, # layerRange
|
196
|
+
"layersep" => { :usedBy => "G", :type => :EscString }, # string
|
197
|
+
"layout" => { :usedBy => "G", :type => :EscString }, # string
|
198
|
+
"len" => { :usedBy => "E", :type => :GvDouble },
|
199
|
+
"levels" => { :usedBy => "G", :type => :EscString }, # int
|
200
|
+
"levelsgap" => { :usedBy => "G", :type => :GvDouble },
|
201
|
+
"lhead" => { :usedBy => "E", :type => :EscString }, # string
|
202
|
+
"lheight" => { :usedBy => "GC", :type => :GvDouble },
|
203
|
+
"lp" => { :usedBy => "EGC", :type => :EscString }, # point
|
204
|
+
"ltail" => { :usedBy => "E", :type => :EscString }, # string
|
205
|
+
"lwidth" => { :usedBy => "GC", :type => :GvDouble },
|
206
|
+
"margin" => { :usedBy => "NGC", :type => :EscString }, # GvDouble , pointf
|
207
|
+
"maxiter" => { :usedBy => "G", :type => :EscString }, # int
|
208
|
+
"mclimit" => { :usedBy => "G", :type => :GvDouble },
|
209
|
+
"mindist" => { :usedBy => "G", :type => :GvDouble },
|
210
|
+
"minlen" => { :usedBy => "E", :type => :EscString }, # int
|
211
|
+
"mode" => { :usedBy => "G", :type => :EscString }, # string
|
212
|
+
"model" => { :usedBy => "G", :type => :EscString }, # string
|
213
|
+
"mosek" => { :usedBy => "G", :type => :GvBool }, # bool
|
214
|
+
"nodesep" => { :usedBy => "G", :type => :GvDouble },
|
215
|
+
"nojustify" => { :usedBy => "GCNE", :type => :GvBool }, # bool
|
216
|
+
"normalize" => { :usedBy => "G", :type => :GvBool }, # bool
|
217
|
+
"nslimit" => { :usedBy => "G", :type => :GvDouble },
|
218
|
+
"nslimit1" => { :usedBy => "G", :type => :GvDouble },
|
219
|
+
"ordering" => { :usedBy => "GN", :type => :EscString }, # string
|
220
|
+
"orientation" => { :usedBy => "NG", :type => :GvDouble }, # N: double, G: string
|
221
|
+
"outputorder" => { :usedBy => "G", :type => :EscString }, # outputMode
|
222
|
+
"overlap" => { :usedBy => "G", :type => :EscString }, # string, bool
|
223
|
+
"overlap_scaling" => { :usedBy => "G", :type => :GvDouble },
|
224
|
+
"pack" => { :usedBy => "G", :type => :EscString }, # bool, int
|
225
|
+
"packmode" => { :usedBy => "G", :type => :EscString }, # packMode
|
226
|
+
"pad" => { :usedBy => "G", :type => :EscString }, # GvDouble , pointf
|
227
|
+
"page" => { :usedBy => "G", :type => :EscString }, # GvDouble , pointf
|
228
|
+
"pagedir" => { :usedBy => "G", :type => :EscString }, # pageDir
|
229
|
+
"pencolor" => { :usedBy => "C", :type => :Color }, # color
|
230
|
+
"penwidth" => { :usedBy => "CNE", :type => :GvDouble },
|
231
|
+
"peripheries" => { :usedBy => "NC", :type => :EscString }, # int
|
232
|
+
"pin" => { :usedBy => "N", :type => :GvBool }, # bool
|
233
|
+
"pos" => { :usedBy => "EN", :type => :SplineType }, # point, splineTypes
|
234
|
+
"quadtree" => { :usedBy => "G", :type => :GvBool }, # bool
|
235
|
+
"quantum" => { :usedBy => "G", :type => :GvDouble },
|
236
|
+
"rank" => { :usedBy => "S", :type => :EscString }, # rankType
|
237
|
+
"rankdir" => { :usedBy => "G", :type => :EscString }, # rankDir
|
238
|
+
"ranksep" => { :usedBy => "G", :type => :EscString }, # GvDouble, doubleList
|
239
|
+
"ratio" => { :usedBy => "G", :type => :EscString }, # GvDouble, String
|
240
|
+
"rects" => { :usedBy => "N", :type => :Rect }, # rect
|
241
|
+
"regular" => { :usedBy => "N", :type => :GvBool }, # bool
|
242
|
+
"remincross" => { :usedBy => "G", :type => :GvBool }, # bool
|
243
|
+
"repulsiveforce" => { :usedBy => "G", :type => :GvDouble },
|
244
|
+
"resolution" => { :usedBy => "G", :type => :GvDouble },
|
245
|
+
"root" => { :usedBy => "GN", :type => :EscString }, # bool, string
|
246
|
+
"rotate" => { :usedBy => "G", :type => :EscString }, # int
|
247
|
+
"rotation" => { :usedBy => "G", :type => :GvDouble },
|
248
|
+
"samehead" => { :usedBy => "E", :type => :EscString }, # string
|
249
|
+
"sametail" => { :usedBy => "E", :type => :EscString }, # string
|
250
|
+
"samplepoints" => { :usedBy => "G", :type => :EscString }, # int
|
251
|
+
"scale" => { :usedBy => "G", :type => :EscString }, # double, pointf
|
252
|
+
"searchsize" => { :usedBy => "G", :type => :EscString }, # int
|
253
|
+
"sep" => { :usedBy => "G", :type => :EscString }, # double , pointf
|
254
|
+
"shape" => { :usedBy => "N", :type => :EscString }, # shape
|
255
|
+
"shapefile" => { :usedBy => "N", :type => :EscString }, # string
|
256
|
+
"showboxes" => { :usedBy => "ENG", :type => :EscString }, # int
|
257
|
+
"sides" => { :usedBy => "N", :type => :EscString }, # int
|
258
|
+
"size" => { :usedBy => "NG", :type => :EscString }, # double , pointf
|
259
|
+
"skew" => { :usedBy => "N", :type => :GvDouble },
|
260
|
+
"smoothing" => { :usedBy => "G", :type => :EscString }, # smoothType
|
261
|
+
"sortv" => { :usedBy => "GCN", :type => :EscString }, # int
|
262
|
+
"splines" => { :usedBy => "G", :type => :EscString }, # bool, string
|
263
|
+
"start" => { :usedBy => "G", :type => :EscString }, # startType
|
264
|
+
"style" => { :usedBy => "ENCG", :type => :EscString }, # style
|
265
|
+
"stylesheet" => { :usedBy => "G", :type => :EscString }, # string
|
266
|
+
"tailURL" => { :usedBy => "E", :type => :EscString },
|
267
|
+
"tailclip" => { :usedBy => "E", :type => :GvBool }, # bool
|
268
|
+
"tailhref" => { :usedBy => "E", :type => :EscString },
|
269
|
+
"taillabel" => { :usedBy => "E", :type => :EscString }, # lblString
|
270
|
+
"tailport" => { :usedBy => "E", :type => :EscString }, # portPos
|
271
|
+
"tailtarget" => { :usedBy => "E", :type => :EscString },
|
272
|
+
"tailtooltip" => { :usedBy => "E", :type => :EscString },
|
273
|
+
"target" => { :usedBy => "ENGC", :type => :EscString }, # escString, string
|
274
|
+
"tooltip" => { :usedBy => "NEC", :type => :EscString },
|
275
|
+
"truecolor" => { :usedBy => "G", :type => :GvBool }, # bool
|
276
|
+
"vertices" => { :usedBy => "N", :type => :EscString }, # pointfList
|
277
|
+
"viewport" => { :usedBy => "G", :type => :EscString }, # viewPort
|
278
|
+
"voro_margin" => { :usedBy => "G", :type => :GvDouble },
|
279
|
+
"weight" => { :usedBy => "E", :type => :GvDouble },
|
280
|
+
"width" => { :usedBy => "N", :type => :GvDouble },
|
281
|
+
"xlabel" => { :usedBy => "EN", :type => :LblString },
|
282
|
+
"z" => { :usedBy => "N", :type => :GvDouble }
|
283
|
+
}
|
284
|
+
|
285
|
+
## Const: Graph attributes
|
286
|
+
GRAPHSATTRS = GraphViz::Constants::getAttrsFor( /G|S|C/ )
|
287
|
+
|
288
|
+
## Const: Node attributes
|
289
|
+
NODESATTRS = GraphViz::Constants::getAttrsFor( /N/ )
|
290
|
+
|
291
|
+
## Const: Edge attributes
|
292
|
+
EDGESATTRS = GraphViz::Constants::getAttrsFor( /E/ )
|
293
|
+
end
|
294
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class String
|
2
|
+
def self.random(size)
|
3
|
+
s = ""
|
4
|
+
d = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
5
|
+
size.times {
|
6
|
+
s << d[rand(d.size)]
|
7
|
+
}
|
8
|
+
return s
|
9
|
+
end
|
10
|
+
|
11
|
+
def convert_base(from, to)
|
12
|
+
self.to_i(from).to_s(to)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Object
|
17
|
+
def to_ruby
|
18
|
+
begin
|
19
|
+
eval self
|
20
|
+
rescue
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# From : http://www.geekmade.co.uk/2008/09/ruby-tip-normalizing-hash-keys-as-symbols/
|
27
|
+
class Hash
|
28
|
+
def symbolize_keys
|
29
|
+
inject({}) do |options, (key, value)|
|
30
|
+
options[(key.to_sym rescue key) || key] = value
|
31
|
+
options
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# x = {
|
36
|
+
# :none => String,
|
37
|
+
# :png => "file.png",
|
38
|
+
# :svg => "file.svg"
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
# x.each_except( :key => [:none], :value => [/\.png$/] ) do |k, v|
|
42
|
+
# puts "#{k} -> #{v}"
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# => svg -> file.svg
|
46
|
+
def each_except( e, &b )
|
47
|
+
key_table = (e[:key]||[]).clone.delete_if {|i| i.kind_of? Regexp }
|
48
|
+
key_regexp = (e[:key]||[]).clone.delete_if {|i| key_table.include? i }.map {|i| i.to_s }.join("|")
|
49
|
+
|
50
|
+
value_table = (e[:value]||[]).clone.delete_if {|i| i.kind_of? Regexp }
|
51
|
+
value_regexp = (e[:value]||[]).clone.delete_if {|i| value_table.include? i }.map {|i| i.to_s }.join("|")
|
52
|
+
|
53
|
+
self.each do |k, v|
|
54
|
+
yield( k, v ) unless (key_table.size > 0 and key_table.include?(k)) or (key_regexp.size > 0 and k.to_s.match(key_regexp)) or (value_table.size > 0 and value_table.include?(v)) or (value_regexp.size > 0 and v.to_s.match(value_regexp))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
unless self.method_defined? :key
|
59
|
+
# Add Hash#key to Ruby < 1.9
|
60
|
+
def key(v)
|
61
|
+
index(v)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright (C) 2010 Gregoire Lejeune <gregoire.lejeune@free.fr>
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require 'graphviz/ext'
|
19
|
+
require 'graphviz/utils'
|
20
|
+
|
21
|
+
class Dot2Ruby #:nodoc:
|
22
|
+
include GraphViz::Utils
|
23
|
+
|
24
|
+
def initialize( xGVPath, xOutFile, xOutFormat = nil ) #:nodoc:
|
25
|
+
paths = (xGVPath.nil?) ? [] : [xGVPath]
|
26
|
+
@xGvprPath = find_executable( 'gvpr', paths )
|
27
|
+
@xOutFile = xOutFile
|
28
|
+
@xOutFormat = xOutFormat || "_"
|
29
|
+
@gvprScript = GraphViz::Ext.find( "dot2ruby.g" )
|
30
|
+
end
|
31
|
+
|
32
|
+
def run( xFile ) #:nodoc:
|
33
|
+
xCmd = [@xGvprPath, '-f', @gvprScript, '-a', @xOutFormat, xFile]
|
34
|
+
xOutput = output_from_command( xCmd )
|
35
|
+
if @xOutFile.nil?
|
36
|
+
puts xOutput
|
37
|
+
else
|
38
|
+
File.open( @xOutFile, "w" ) do |io|
|
39
|
+
io.print xOutput
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def eval( xFile ) #:nodoc:
|
45
|
+
xCmd = [@xGvprPath, '-f', @gvprScript, '-a', '-', xFile]
|
46
|
+
xOutput = output_from_command( xCmd )
|
47
|
+
instance_eval(xOutput)
|
48
|
+
return @_graph_eval
|
49
|
+
end
|
50
|
+
|
51
|
+
def eval_string( data ) #:nodoc:
|
52
|
+
t = Tempfile::open( File.basename(__FILE__) )
|
53
|
+
t.print( data )
|
54
|
+
t.close
|
55
|
+
result = self.eval(t.path)
|
56
|
+
t.close
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
class GraphViz
|
3
|
+
|
4
|
+
class DOTScriptData
|
5
|
+
attr_accessor :type
|
6
|
+
def initialize(type = nil)
|
7
|
+
@data = []
|
8
|
+
@separator = ""
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def append(data)
|
13
|
+
@data << data
|
14
|
+
end
|
15
|
+
alias :<< :append
|
16
|
+
|
17
|
+
def add_attribute(name, value)
|
18
|
+
@data << @separator << name << " = " << value
|
19
|
+
@separator = determine_separator
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_str
|
23
|
+
case @type
|
24
|
+
when "graph_attr" then "#{@data.join}#{@separator}"
|
25
|
+
when "node_attr" then "node[#{@data.join(' ')}];"
|
26
|
+
when "edge_attr" then "edge[#{@data.join(' ')}];"
|
27
|
+
else raise ArgumentError, "Wrong type: #{@type}."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
alias :to_s :to_str
|
31
|
+
|
32
|
+
def empty?
|
33
|
+
@data.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def determine_separator
|
39
|
+
case @type
|
40
|
+
when "graph_attr" then ";\n"
|
41
|
+
when "node_attr", "edge_attr" then ","
|
42
|
+
else raise ArgumentError, "Wrong type: #{@type}."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class DOTScript
|
49
|
+
extend Forwardable
|
50
|
+
|
51
|
+
def_delegators :@script, :end_with?
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
@script = ''
|
55
|
+
end
|
56
|
+
|
57
|
+
def append(line)
|
58
|
+
@script << assure_ends_with(line.to_s,"\n")
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
alias :<< :append
|
63
|
+
|
64
|
+
def prepend(line)
|
65
|
+
@script = assure_ends_with(line.to_s,"\n") + @script
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def make_subgraph(name)
|
71
|
+
prepend(assure_ends_with("subgraph #{name}"," {"))
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_type(type, data)
|
75
|
+
return self if data.empty?
|
76
|
+
|
77
|
+
case type
|
78
|
+
when "graph_attr"
|
79
|
+
append_statement(" " + data)
|
80
|
+
when "node_attr"
|
81
|
+
append_statement(" node [" + data + "]")
|
82
|
+
when "edge_attr"
|
83
|
+
append_statement(" edge [" + data + "]")
|
84
|
+
else
|
85
|
+
raise ArgumentError,
|
86
|
+
"Unknown type: #{type}." <<
|
87
|
+
"Possible: 'graph_attr','node_attr','edge_attr'"
|
88
|
+
end
|
89
|
+
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_str
|
94
|
+
@script
|
95
|
+
end
|
96
|
+
alias :to_s :to_str
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def assure_ends_with(str,ending="\n")
|
101
|
+
str.to_s.end_with?("\n") ? str : str + ending
|
102
|
+
end
|
103
|
+
|
104
|
+
def append_statement(statement)
|
105
|
+
append(assure_ends_with(statement, ";\n"))
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|