graphvizml 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/graphvizml.rb +118 -53
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de0694551027289ed8fa1585ad6b6c623ec452ba
|
4
|
+
data.tar.gz: 126a11754c78559bf196baab8c64df3f4f893981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583cc6f8a779814a1388b734439b799342661490abd92472de500b9e1154eb11553ff71996640f106be09f73e4051ba6789b6469344d1a93a6676d6e460c33e0
|
7
|
+
data.tar.gz: 74f5895b91a83eecfbda1e3b0da57c3fca2a76fe67e135c32d3175c01504aeca370432f3b1508c072d6eacbebed4a05f2e41c64d34e8ac619e412fdfb5ebd184
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/graphvizml.rb
CHANGED
@@ -14,34 +14,24 @@ class GraphVizML
|
|
14
14
|
|
15
15
|
def initialize(obj)
|
16
16
|
|
17
|
-
|
17
|
+
xml = if obj.is_a? String then
|
18
18
|
|
19
|
-
|
19
|
+
File.read filename=obj
|
20
20
|
|
21
|
-
elsif obj.is_a?
|
21
|
+
elsif obj.is_a? Rexle or obj.is_a? Rexle::Element
|
22
22
|
|
23
|
-
|
24
|
-
obj
|
23
|
+
obj.xml
|
25
24
|
|
26
|
-
end
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
@type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
|
27
|
+
doc = Domle.new(xml)
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
# check if the root node is gvml or nodes
|
30
|
+
@g = if doc.root.name == 'gvml' then
|
31
|
+
build_from_gvml doc
|
32
|
+
elsif doc.root.name == 'nodes'
|
33
|
+
build_from_nodes doc
|
37
34
|
end
|
38
|
-
|
39
|
-
# remove any entries with an empty value
|
40
|
-
h.each {|key, value| h.delete key if value.empty?}
|
41
|
-
|
42
|
-
@g = Graphviz::Graph.new h
|
43
|
-
|
44
|
-
build()
|
45
35
|
|
46
36
|
end
|
47
37
|
|
@@ -71,42 +61,19 @@ class GraphVizML
|
|
71
61
|
|
72
62
|
private
|
73
63
|
|
74
|
-
def
|
64
|
+
def build_from_gvml(doc)
|
65
|
+
|
66
|
+
g = Graphviz::Graph.new format_summary_attributes(doc.root.attributes)
|
75
67
|
|
76
|
-
e_nodes =
|
77
|
-
e_edges =
|
68
|
+
e_nodes = doc.root.element 'nodes'
|
69
|
+
e_edges = doc.root.element 'edges'
|
78
70
|
|
79
71
|
|
80
72
|
# add the nodes
|
81
73
|
|
82
74
|
nodes = e_nodes.root.xpath('records/a | records/node').inject({}) do |r,e|
|
83
75
|
|
84
|
-
|
85
|
-
|
86
|
-
url = e.attributes[:href]
|
87
|
-
child = e.element 'node'
|
88
|
-
child.attributes[:url] = url
|
89
|
-
|
90
|
-
child
|
91
|
-
else
|
92
|
-
e
|
93
|
-
end
|
94
|
-
|
95
|
-
h = node.attributes
|
96
|
-
|
97
|
-
id = h[:gid]
|
98
|
-
label = node.text('label')
|
99
|
-
|
100
|
-
# shape options: box, ellipse, record, diamond, circle, polygon, point
|
101
|
-
|
102
|
-
style = {}
|
103
|
-
style[:shape] = h[:shape] || 'box'
|
104
|
-
style[:URL] = h[:url] if h[:url]
|
105
|
-
|
106
|
-
#puts "adding node id: %s label: %s" % [id, label]
|
107
|
-
|
108
|
-
# the nil is replaced by the Graphviz node object
|
109
|
-
r.merge(id => [label, node.style.merge(style), nil])
|
76
|
+
r.merge fetch_node(e)
|
110
77
|
|
111
78
|
end
|
112
79
|
|
@@ -114,7 +81,7 @@ class GraphVizML
|
|
114
81
|
# add the edges
|
115
82
|
|
116
83
|
id_1 = e_edges.root.element('records/edge/records/node/attribute::gid').to_s
|
117
|
-
nodes[id_1][-1] =
|
84
|
+
nodes[id_1][-1] = g.add_node(nodes[id_1][0])
|
118
85
|
|
119
86
|
e_edges.root.xpath('records/edge').each do |edge|
|
120
87
|
|
@@ -131,14 +98,112 @@ class GraphVizML
|
|
131
98
|
|
132
99
|
end
|
133
100
|
|
101
|
+
format_attributes nodes
|
102
|
+
|
103
|
+
return g
|
104
|
+
end
|
105
|
+
|
106
|
+
def build_from_nodes(doc)
|
107
|
+
|
108
|
+
|
109
|
+
g = Graphviz::Graph.new format_summary_attributes(doc.root.attributes)
|
110
|
+
|
111
|
+
|
112
|
+
# add the nodes
|
113
|
+
|
114
|
+
nodes = doc.root.xpath('//a | //node').inject({}) do |r,e|
|
115
|
+
|
116
|
+
r.merge fetch_node(e)
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
# add the edges
|
121
|
+
|
122
|
+
id_1 = nodes.first[0]
|
123
|
+
nodes[id_1][-1] = g.add_node(nodes[id_1][0])
|
124
|
+
|
125
|
+
|
126
|
+
doc.root.each_recursive do |node|
|
127
|
+
|
128
|
+
node.xpath('node').each do |child|
|
129
|
+
|
130
|
+
id1, id2 = node.object_id, child.object_id
|
131
|
+
|
132
|
+
label = child.attributes[:connection].to_s
|
133
|
+
#puts "adding edge id1: %s id2: %s label: %s" % [id1, id2, label]
|
134
|
+
nodes[id2][-1] ||= nodes[id1].last.add_node(nodes[id2][0])
|
135
|
+
attributes = child.style.merge({label: label})
|
136
|
+
|
137
|
+
conn = nodes[id1][-1].connections.last
|
138
|
+
conn.attributes[:label] = label
|
139
|
+
child.style.each {|key,val| conn.attributes[key] = m(val) }
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
format_attributes nodes
|
145
|
+
|
146
|
+
g
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
def fetch_node(e)
|
151
|
+
|
152
|
+
node = if e.name == 'a' then
|
153
|
+
|
154
|
+
url = e.attributes[:href]
|
155
|
+
child = e.element 'node'
|
156
|
+
child.attributes[:url] = url
|
157
|
+
|
158
|
+
child
|
159
|
+
else
|
160
|
+
e
|
161
|
+
end
|
162
|
+
|
163
|
+
h = node.attributes
|
164
|
+
|
165
|
+
id = h[:gid] || node.object_id
|
166
|
+
label = node.text('label')
|
167
|
+
|
168
|
+
# shape options: box, ellipse, record, diamond, circle, polygon, point
|
169
|
+
|
170
|
+
style = {}
|
171
|
+
style[:shape] = h[:shape] || 'box'
|
172
|
+
style[:URL] = h[:url] if h[:url]
|
173
|
+
|
174
|
+
#puts "adding node id: %s label: %s" % [id, label]
|
175
|
+
|
176
|
+
# the nil is replaced by the Graphviz node object
|
177
|
+
{id => [label, node.style.merge(style), nil]}
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
def format_attributes(nodes)
|
182
|
+
|
134
183
|
nodes.each do |id, x|
|
135
184
|
|
136
185
|
_, attributes, obj = x
|
137
186
|
attributes.each {|key, val| obj.attributes[key] = m(val) }
|
138
187
|
|
139
|
-
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
def format_summary_attributes(h)
|
193
|
+
|
194
|
+
type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
|
140
195
|
|
141
|
-
:
|
196
|
+
h[:type] = type.to_s
|
197
|
+
h[:rankdir] = h.has_key?(:direction) ? h[:direction].to_s.upcase : 'LR'
|
198
|
+
|
199
|
+
%i(recordx_type format_mask schema direction).each do |x|
|
200
|
+
h.delete x; h.delete x.to_s
|
201
|
+
end
|
202
|
+
|
203
|
+
# remove any entries with an empty value
|
204
|
+
h.each {|key, value| h.delete key if value.empty?}
|
205
|
+
|
206
|
+
h
|
142
207
|
end
|
143
208
|
|
144
209
|
# modify the value if it matches the following criteria
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphvizml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
0fBBWVqwHyWs77T9gCuDZmQrw2NmfyhNWhBw0iljBXo7WLDNB3x0nP6mYTzk47O8
|
32
32
|
sL5FGYJNgQqFlw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-09-
|
34
|
+
date: 2017-09-10 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: domle
|
metadata.gz.sig
CHANGED
Binary file
|