graphvizml 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/graphvizml.rb +118 -103
  4. data.tar.gz.sig +0 -0
  5. metadata +48 -47
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70367b15cd9ecda5a2010ca241fdd7e5ff80c3356df9ab7b599c8a4e0a812fc7
4
- data.tar.gz: 8fc13a6a0f08d6786a12327ed39fdb0735d5ff7b7f43359eefd05b6771ca43b4
3
+ metadata.gz: 1177c0f368688b11b03baf3bc48c47663cba20382bbae91664cd04802b4ee84a
4
+ data.tar.gz: 8de0bc97739fa89072392f39ef8535b2348c6e0840313b00f44f2731f128be25
5
5
  SHA512:
6
- metadata.gz: 75ba5f6d83152d16c870101bb3157cb5fcd6aa651586992d84f19a34631ce67a5d88601bb9682b5bd3e5881f2374098d59ab400d484bc8bfbb3e39f4470561a4
7
- data.tar.gz: 661c553f24df368c9c8855d9bb98c39dba70d5bf35eba744ca349647847754691a339bbb46457689cd36b080387b3a19e9e0a2de401002ea0ddd4cddfe5b70f5
6
+ metadata.gz: e527204ac7a3ac49e0bc48310716fb9985952caa389bb29eb52d0d338fadf33f58c1797d838f0a1c973467c228fc5b242546babb5950adb8338a22ea04ec694c
7
+ data.tar.gz: 44dd8c179e7d8bc20be227db17b302575258ef076862e51a80de1782f73ff9293f693b810308271359d30ec591d836866d58384acfb36e5b289c6896e03eb7b2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/graphvizml.rb CHANGED
@@ -19,7 +19,7 @@ hkey_gems
19
19
  require graphvizml
20
20
  class GraphVizML
21
21
  media_type svg
22
- '
22
+ '
23
23
  end
24
24
  end
25
25
 
@@ -30,31 +30,42 @@ class GraphVizML
30
30
  attr_reader :g
31
31
 
32
32
  def initialize(obj=nil, debug: false, fill: 'transparent', stroke: '#000', text_color: '#000')
33
-
33
+
34
34
  @debug = debug
35
35
  @fill, @stroke, @text_color = fill, stroke, text_color
36
-
36
+
37
37
  if obj then
38
-
39
- s = RXFHelper.read(obj).first
40
-
41
- if s =~ /<\?graphvizml\b/ then
42
-
43
- import_string s
44
-
38
+
39
+
40
+ xml = if obj.is_a? Rexle or obj.is_a? Rexle::Element
41
+
42
+ obj.xml
43
+
45
44
  else
46
-
47
- if @debug then
48
- #File.write '/tmp/graphviz.xml', xml
49
- puts('graphvizml xml: ' + s.inspect)
45
+
46
+ s = RXFHelper.read(obj).first
47
+
48
+ if s =~ /<\?graphvizml\b/ then
49
+
50
+ import_string s
51
+
52
+ else
53
+
54
+ if @debug then
55
+ #File.write '/tmp/graphviz.xml', xml
56
+ puts('graphvizml xml: ' + s.inspect)
57
+ end
58
+
59
+ s
60
+
50
61
  end
51
-
52
- @g = build_from_nodes Domle.new(s)
53
-
62
+
54
63
  end
55
-
64
+
65
+ @g = build_from_nodes Domle.new(xml)
66
+
56
67
  end
57
-
68
+
58
69
  @css = "
59
70
  .node ellipse {stroke: #{stroke}; fill: #{fill}}
60
71
  .node text {fill: #{text_color}}
@@ -63,78 +74,85 @@ class GraphVizML
63
74
  "
64
75
 
65
76
  end
66
-
77
+
67
78
  def import(obj)
68
-
79
+
69
80
  s = RXFHelper.read(obj).first
70
- import_string s
71
-
81
+ xml = import_string s
82
+ puts('graphvizml/import xml: ' + xml.inspect).debug if @debug
83
+ @g = build_from_nodes Domle.new(xml)
84
+ self
85
+
72
86
  end
73
87
 
74
-
88
+
75
89
  def to_dot()
90
+
76
91
  @g.to_dot
92
+
77
93
  end
78
94
 
79
-
95
+
80
96
  # returns an SVG blob
81
97
  #
82
98
  def to_svg()
83
99
  f = Tempfile.new('graphvizml')
84
- Graphviz::output(@g, format: 'svg', path: f.path)
100
+ #jr 26-01-2022 Graphviz::output(@g, format: 'svg', path: f.path)
101
+ Graphviz.output(@g, path: f.path, format: 'svg')
85
102
  s = File.read f.path
86
- s.sub!('xmlns:xlink="http://www.w3.org/1999/xlink"','')
87
- s.lines.insert(8, css_code()).join
103
+ #s.sub!('xmlns:xlink="http://www.w3.org/1999/xlink"','')
104
+ #s.sub!('xlink:','') # not yet implemented because of a local namespace issue
105
+ s.lines.insert(8, css_code()).join
88
106
  end
89
107
 
90
-
108
+
91
109
  private
92
-
93
-
110
+
111
+
94
112
  def build_from_nodes(doc)
95
113
 
96
114
  puts 'inside build_from_nodes'.info if @debug
97
115
 
98
- g = Graphviz::Graph.new format_summary_attributes(doc.root.attributes)
99
-
100
- # add the nodes
116
+ g = Graphviz::Graph.new **format_summary_attributes(doc.root.attributes)
117
+
118
+ # add the nodes
101
119
 
102
120
  nodes = doc.root.xpath('//node').inject({}) do |r,e|
103
-
121
+
104
122
  r.merge fetch_node(e)
105
123
 
106
124
  end
107
-
125
+
108
126
  if @debug then
109
- puts 'nodes: ' + nodes.inspect
127
+ puts 'nodes: ' + nodes.inspect
110
128
  puts 'doc: ' + doc.root.xml.inspect
111
129
  end
112
130
 
113
131
  a = doc.root.element('style/text()').to_s.strip.split(/}/).map do |entry|
114
-
132
+
115
133
  puts 'entry: ' + entry.inspect if @debug
116
134
 
117
135
  raw_selector,raw_styles = entry.split(/{/,2)
118
136
 
119
- h = raw_styles.strip.split(/;/).inject({}) do |r, x|
137
+ h = raw_styles.strip.split(/;/).inject({}) do |r, x|
120
138
  k, v = x.split(/:/,2).map(&:strip)
121
139
  r.merge(k.to_sym => v)
122
140
  end
123
141
 
124
142
  [raw_selector.split(/,\s*/).map(&:strip), h]
125
143
  end
126
-
144
+
127
145
  puts ' a: ' + a.inspect if @debug
128
-
146
+
129
147
 
130
148
  edge_style = a.any? ? a.find {|x| x[0].grep(/edge/).any?}.last : []
131
149
 
132
-
133
-
134
- # add the edges
150
+
151
+
152
+ # add the edges
135
153
 
136
154
  id_1 = nodes.first[0]
137
- nodes[id_1][-1] = g.add_node(nodes[id_1][0])
155
+ nodes[id_1][-1] = g.add_node(nodes[id_1][0])
138
156
 
139
157
 
140
158
  doc.root.each_recursive do |node|
@@ -142,7 +160,7 @@ class GraphVizML
142
160
  next unless node.name == 'node'
143
161
 
144
162
  node.xpath('a/node | node').each do |child|
145
-
163
+
146
164
  id1, id2 = node.object_id, child.object_id
147
165
 
148
166
  label = child.attributes[:connection].to_s
@@ -153,130 +171,127 @@ class GraphVizML
153
171
 
154
172
  conn = nodes[id1][-1].connections.last
155
173
  conn.attributes[:label] = label
156
-
157
- edge_style.each {|key,val| conn.attributes[key] = m(val) }
158
-
174
+
175
+ edge_style.each {|key,val| conn.attributes[key] = m(val) }
176
+
159
177
  end
160
- end
161
-
162
- format_attributes nodes
163
-
178
+ end
179
+
180
+ format_attributes nodes
181
+
164
182
  g
165
-
183
+
166
184
  end
167
-
185
+
168
186
  def css_code()
169
- <<EOF
187
+ <<EOF
170
188
  <defs>
171
189
  <style type='text/css'><![CDATA[
172
190
  #{@css}
173
191
  ]]></style>
174
- </defs>
175
-
192
+ </defs>
193
+
176
194
  EOF
177
- end
178
-
195
+ end
196
+
179
197
  def fetch_node(node)
180
198
 
181
199
  puts 'inside fetch_node'.info if @debug
182
-
200
+
183
201
  h = node.attributes
184
202
  #puts 'h: ' + h.inspect
185
203
  puts('graphvizml/fetch_node h: ' + h.inspect) if @debug
186
-
204
+
187
205
  if node.parent.name == 'a' then
188
-
206
+
189
207
  url = node.parent.attributes[:href]
190
208
  h[:url] = url if url
191
-
192
- end
209
+
210
+ end
193
211
 
194
212
  id = h[:gid] || node.object_id
195
213
  label = node.text('label')
196
-
214
+
197
215
  # shape options: box, ellipse, record, diamond, circle, polygon, point
198
-
216
+
199
217
  style = {}
200
218
 
201
219
  style[:shape] = h[:shape] if h[:shape] and !h[:shape].empty?
202
220
  style[:URL] = h[:url] if h[:url]
203
221
 
204
222
  #puts "adding node id: %s label: %s" % [id, label]
205
-
206
- # the nil is replaced by the Graphviz node object
223
+
224
+ # the nil is replaced by the Graphviz node object
207
225
  {id => [label, node.style.merge(style), nil]}
208
-
226
+
209
227
  end
210
-
228
+
211
229
  def format_attributes(nodes)
212
-
230
+
213
231
  nodes.each do |id, x|
214
232
 
215
233
  _, attributes, obj = x
216
234
  next unless obj
217
235
  attributes.each {|key, val| obj.attributes[key] = m(val) }
218
-
219
- end
236
+
237
+ end
220
238
 
221
239
  end
222
-
240
+
223
241
  def format_summary_attributes(h)
224
-
225
- type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
242
+
243
+ type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
226
244
 
227
245
  h[:type] = type.to_s
228
246
  h[:rankdir] = h.has_key?(:direction) ? h[:direction].to_s.upcase : 'LR'
229
-
230
- %i(recordx_type format_mask schema direction).each do |x|
247
+
248
+ %i(recordx_type format_mask schema direction).each do |x|
231
249
  h.delete x; h.delete x.to_s
232
250
  end
233
-
251
+
234
252
  # remove any entries with an empty value
235
- h.each {|key, value| h.delete key if value.empty?}
236
-
253
+ h.each {|key, value| h.delete key if value.empty?}
254
+
237
255
  h
238
256
  end
239
-
240
-
241
- def import_string(obj)
242
-
243
- s = RXFHelper.read(obj).first
244
-
245
- s2 = s.slice(/<\?graphvizml\b[^>]*\?>/)
257
+
258
+
259
+ def import_string(s)
260
+
261
+
262
+ s2 = s.slice!(/<\?graphvizml\b[^>]*\?>/)
246
263
 
247
264
  if s2 then
248
-
265
+
249
266
  attributes = %w(id fill stroke text_color).inject({}) do |r, keyword|
250
267
  found = s2[/(?<=#{keyword}=['"])[^'"]+/]
251
268
  found ? r.merge(keyword.to_sym => found) : r
252
269
  end
253
-
270
+
254
271
  fill, stroke, text_color = %i(fill stroke text_color).map do |x|
255
272
  attributes[x] ? attributes[x] : method(x).call
256
273
  end
257
-
274
+
258
275
  @css = "
259
276
  .node ellipse {stroke: #{stroke}; fill: #{fill}}
260
277
  .node text {fill: #{text_color}}
261
278
  .edge path {stroke: #{stroke}}
262
279
  .edge polygon {stroke: #{stroke}; fill: #{stroke}}
263
- "
264
-
265
- end
266
-
267
- xml = LineTree.new(s, root: 'nodes', debug: true).to_xml
268
- @g = build_from_nodes Domle.new(xml)
269
- self
270
-
280
+ "
281
+
282
+ end
283
+
284
+ xml = LineTree.new(s, root: 'nodes', debug: @debug).to_xml
285
+
271
286
  end
272
-
287
+
273
288
  # modify the value if it matches the following criteria
274
289
  #
275
290
  def m(s)
276
-
291
+
277
292
  # is it a shorthand hexcode? e.g. #fff
278
293
  s.gsub(/^#([\da-f]{3})$/)\
279
294
  { '#' + ($1).chars.inject([]) {|r,x| r << x + x}.join}
280
295
  end
281
-
296
+
282
297
  end
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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwNjA5MTczOTQxWhcN
15
- MjAwNjA4MTczOTQxWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDYTr9/
17
- 0s/6N5/dRrEOhJYBRMqcrGr3VC058Pfvii4xqLgy+AHTOxZLEIV5DY5JWICEQGKO
18
- rQUS7iN49f0odEW/7JciVo5yAotUaCVgL/ipjoTt7ti29coGx//9GvGKnEyEAbVu
19
- 3RS7SNDy+zE2MPrGA2d3o2fZ2nl/F8DAQ2zFvmLpa2dQ1mlvO6w/az5Zj/Cqq2Jj
20
- 5x5kVZjNvkt5x7fT0vcZDKuK97ALkiJ/a1iHRxi9fYFBbT3sc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gsZpDSXvWmorO0sxFdS3bX+wGpIqjTucov3xCL29oipOTed78
31
+ CiGPYDYX2ddYBPv4DCnKRlmpbQPSEAv+Vr4MIXK2DIz/pNKhVkO60CkhQLfbmuIt
32
+ tHEHxLaJBrdFImPRVRDbCA7h+a5QyotAldi99hPBCdxS5CyAaFQkn5ScfyBbGOla
33
+ 88GxnM8dyYQwA7jGKJzEVP4Oe2tIlC66Cuvt9aFJY5ILYAvn8yaL9Zz/jfvK/txT
34
+ g5jRbEphIM24ZKx4Ujg457ks1jQG6qQxzJOQk1dDKsKzY+75/npWJbZFPCdpEX1l
35
+ n5la83UsDTB94LHIHb/W8YdApT3vWP/4nxl+/aAPJPBgyN8mZ4Td0FFgbaPGbW4e
36
+ PxZXxv6QqQ7uOHhRsvNRkYj3
37
37
  -----END CERTIFICATE-----
38
- date: 2019-06-09 00:00:00.000000000 Z
38
+ date: 2022-01-26 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: domle
@@ -43,62 +43,62 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.3'
46
+ version: '0.5'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.3.1
49
+ version: 0.5.3
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0.3'
56
+ version: '0.5'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.3.1
59
+ version: 0.5.3
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: graphviz
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 1.1.0
67
64
  - - "~>"
68
65
  - !ruby/object:Gem::Version
69
- version: '1.1'
66
+ version: '1.2'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.1
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 1.1.0
77
74
  - - "~>"
78
75
  - !ruby/object:Gem::Version
79
- version: '1.1'
76
+ version: '1.2'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.2.1
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: line-tree
82
82
  requirement: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 0.8.0
87
84
  - - "~>"
88
85
  - !ruby/object:Gem::Version
89
- version: '0.8'
86
+ version: '0.9'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 0.8.0
97
94
  - - "~>"
98
95
  - !ruby/object:Gem::Version
99
- version: '0.8'
96
+ version: '0.9'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.9.3
100
100
  description:
101
- email: james@jamesrobertson.eu
101
+ email: digital.robertson@gmail.com
102
102
  executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
@@ -116,14 +116,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: '0'
119
+ version: 3.0.2
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.0.1
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.10
127
128
  signing_key:
128
129
  specification_version: 4
129
130
  summary: Generates an SVG file from GraphViz using a GraphViz Markup Language file
metadata.gz.sig CHANGED
Binary file