graphvizml 0.6.4 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09f4e0e919d540db36dd055b5fb536842c41a705fcbcfafa6d553e80ddbed455'
4
- data.tar.gz: 7ac4ff32bcc0af37f631e24e6683a3b2642e616c105e227989b66f8a4ca1a2d1
3
+ metadata.gz: 1177c0f368688b11b03baf3bc48c47663cba20382bbae91664cd04802b4ee84a
4
+ data.tar.gz: 8de0bc97739fa89072392f39ef8535b2348c6e0840313b00f44f2731f128be25
5
5
  SHA512:
6
- metadata.gz: db9aa9df16d0cf2197248b865cc1849f769059ea62becb0e8afec0c1024118325c5c147b9c10ec8d5b6fed6d7ae9e2df60df9a4a453ad032791fc5aa29e25372
7
- data.tar.gz: '0088ebafbe6facb94c488c60f8d8cf3dee311f3961d4f98dadbcc147273d74439de1899e9e5ffe09455a655c47e99175dc64779b01a54cdda30227e166eca573'
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,42 +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
-
38
+
39
+
40
40
  xml = if obj.is_a? Rexle or obj.is_a? Rexle::Element
41
-
41
+
42
42
  obj.xml
43
-
44
- else
45
-
43
+
44
+ else
45
+
46
46
  s = RXFHelper.read(obj).first
47
-
47
+
48
48
  if s =~ /<\?graphvizml\b/ then
49
-
50
- import_string s
51
-
49
+
50
+ import_string s
51
+
52
52
  else
53
-
53
+
54
54
  if @debug then
55
55
  #File.write '/tmp/graphviz.xml', xml
56
- puts('graphvizml xml: ' + s.inspect)
57
- end
58
-
56
+ puts('graphvizml xml: ' + s.inspect)
57
+ end
58
+
59
59
  s
60
-
60
+
61
61
  end
62
-
62
+
63
63
  end
64
-
64
+
65
65
  @g = build_from_nodes Domle.new(xml)
66
-
66
+
67
67
  end
68
-
68
+
69
69
  @css = "
70
70
  .node ellipse {stroke: #{stroke}; fill: #{fill}}
71
71
  .node text {fill: #{text_color}}
@@ -74,82 +74,85 @@ class GraphVizML
74
74
  "
75
75
 
76
76
  end
77
-
77
+
78
78
  def import(obj)
79
-
79
+
80
80
  s = RXFHelper.read(obj).first
81
81
  xml = import_string s
82
82
  puts('graphvizml/import xml: ' + xml.inspect).debug if @debug
83
83
  @g = build_from_nodes Domle.new(xml)
84
84
  self
85
-
85
+
86
86
  end
87
87
 
88
-
88
+
89
89
  def to_dot()
90
+
90
91
  @g.to_dot
92
+
91
93
  end
92
94
 
93
-
95
+
94
96
  # returns an SVG blob
95
97
  #
96
98
  def to_svg()
97
99
  f = Tempfile.new('graphvizml')
98
- 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')
99
102
  s = File.read f.path
100
103
  #s.sub!('xmlns:xlink="http://www.w3.org/1999/xlink"','')
101
104
  #s.sub!('xlink:','') # not yet implemented because of a local namespace issue
102
- s.lines.insert(8, css_code()).join
105
+ s.lines.insert(8, css_code()).join
103
106
  end
104
107
 
105
-
108
+
106
109
  private
107
-
108
-
110
+
111
+
109
112
  def build_from_nodes(doc)
110
113
 
111
114
  puts 'inside build_from_nodes'.info if @debug
112
115
 
113
- g = Graphviz::Graph.new format_summary_attributes(doc.root.attributes)
114
-
115
- # add the nodes
116
+ g = Graphviz::Graph.new **format_summary_attributes(doc.root.attributes)
117
+
118
+ # add the nodes
116
119
 
117
120
  nodes = doc.root.xpath('//node').inject({}) do |r,e|
118
-
121
+
119
122
  r.merge fetch_node(e)
120
123
 
121
124
  end
122
-
125
+
123
126
  if @debug then
124
- puts 'nodes: ' + nodes.inspect
127
+ puts 'nodes: ' + nodes.inspect
125
128
  puts 'doc: ' + doc.root.xml.inspect
126
129
  end
127
130
 
128
131
  a = doc.root.element('style/text()').to_s.strip.split(/}/).map do |entry|
129
-
132
+
130
133
  puts 'entry: ' + entry.inspect if @debug
131
134
 
132
135
  raw_selector,raw_styles = entry.split(/{/,2)
133
136
 
134
- h = raw_styles.strip.split(/;/).inject({}) do |r, x|
137
+ h = raw_styles.strip.split(/;/).inject({}) do |r, x|
135
138
  k, v = x.split(/:/,2).map(&:strip)
136
139
  r.merge(k.to_sym => v)
137
140
  end
138
141
 
139
142
  [raw_selector.split(/,\s*/).map(&:strip), h]
140
143
  end
141
-
144
+
142
145
  puts ' a: ' + a.inspect if @debug
143
-
146
+
144
147
 
145
148
  edge_style = a.any? ? a.find {|x| x[0].grep(/edge/).any?}.last : []
146
149
 
147
-
148
-
149
- # add the edges
150
+
151
+
152
+ # add the edges
150
153
 
151
154
  id_1 = nodes.first[0]
152
- nodes[id_1][-1] = g.add_node(nodes[id_1][0])
155
+ nodes[id_1][-1] = g.add_node(nodes[id_1][0])
153
156
 
154
157
 
155
158
  doc.root.each_recursive do |node|
@@ -157,7 +160,7 @@ class GraphVizML
157
160
  next unless node.name == 'node'
158
161
 
159
162
  node.xpath('a/node | node').each do |child|
160
-
163
+
161
164
  id1, id2 = node.object_id, child.object_id
162
165
 
163
166
  label = child.attributes[:connection].to_s
@@ -168,127 +171,127 @@ class GraphVizML
168
171
 
169
172
  conn = nodes[id1][-1].connections.last
170
173
  conn.attributes[:label] = label
171
-
172
- edge_style.each {|key,val| conn.attributes[key] = m(val) }
173
-
174
+
175
+ edge_style.each {|key,val| conn.attributes[key] = m(val) }
176
+
174
177
  end
175
- end
176
-
177
- format_attributes nodes
178
-
178
+ end
179
+
180
+ format_attributes nodes
181
+
179
182
  g
180
-
183
+
181
184
  end
182
-
185
+
183
186
  def css_code()
184
- <<EOF
187
+ <<EOF
185
188
  <defs>
186
189
  <style type='text/css'><![CDATA[
187
190
  #{@css}
188
191
  ]]></style>
189
- </defs>
190
-
192
+ </defs>
193
+
191
194
  EOF
192
- end
193
-
195
+ end
196
+
194
197
  def fetch_node(node)
195
198
 
196
199
  puts 'inside fetch_node'.info if @debug
197
-
200
+
198
201
  h = node.attributes
199
202
  #puts 'h: ' + h.inspect
200
203
  puts('graphvizml/fetch_node h: ' + h.inspect) if @debug
201
-
204
+
202
205
  if node.parent.name == 'a' then
203
-
206
+
204
207
  url = node.parent.attributes[:href]
205
208
  h[:url] = url if url
206
-
207
- end
209
+
210
+ end
208
211
 
209
212
  id = h[:gid] || node.object_id
210
213
  label = node.text('label')
211
-
214
+
212
215
  # shape options: box, ellipse, record, diamond, circle, polygon, point
213
-
216
+
214
217
  style = {}
215
218
 
216
219
  style[:shape] = h[:shape] if h[:shape] and !h[:shape].empty?
217
220
  style[:URL] = h[:url] if h[:url]
218
221
 
219
222
  #puts "adding node id: %s label: %s" % [id, label]
220
-
221
- # the nil is replaced by the Graphviz node object
223
+
224
+ # the nil is replaced by the Graphviz node object
222
225
  {id => [label, node.style.merge(style), nil]}
223
-
226
+
224
227
  end
225
-
228
+
226
229
  def format_attributes(nodes)
227
-
230
+
228
231
  nodes.each do |id, x|
229
232
 
230
233
  _, attributes, obj = x
231
234
  next unless obj
232
235
  attributes.each {|key, val| obj.attributes[key] = m(val) }
233
-
234
- end
236
+
237
+ end
235
238
 
236
239
  end
237
-
240
+
238
241
  def format_summary_attributes(h)
239
-
240
- type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
242
+
243
+ type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
241
244
 
242
245
  h[:type] = type.to_s
243
246
  h[:rankdir] = h.has_key?(:direction) ? h[:direction].to_s.upcase : 'LR'
244
-
245
- %i(recordx_type format_mask schema direction).each do |x|
247
+
248
+ %i(recordx_type format_mask schema direction).each do |x|
246
249
  h.delete x; h.delete x.to_s
247
250
  end
248
-
251
+
249
252
  # remove any entries with an empty value
250
- h.each {|key, value| h.delete key if value.empty?}
251
-
253
+ h.each {|key, value| h.delete key if value.empty?}
254
+
252
255
  h
253
256
  end
254
-
255
-
257
+
258
+
256
259
  def import_string(s)
257
-
258
-
260
+
261
+
259
262
  s2 = s.slice!(/<\?graphvizml\b[^>]*\?>/)
260
263
 
261
264
  if s2 then
262
-
265
+
263
266
  attributes = %w(id fill stroke text_color).inject({}) do |r, keyword|
264
267
  found = s2[/(?<=#{keyword}=['"])[^'"]+/]
265
268
  found ? r.merge(keyword.to_sym => found) : r
266
269
  end
267
-
270
+
268
271
  fill, stroke, text_color = %i(fill stroke text_color).map do |x|
269
272
  attributes[x] ? attributes[x] : method(x).call
270
273
  end
271
-
274
+
272
275
  @css = "
273
276
  .node ellipse {stroke: #{stroke}; fill: #{fill}}
274
277
  .node text {fill: #{text_color}}
275
278
  .edge path {stroke: #{stroke}}
276
279
  .edge polygon {stroke: #{stroke}; fill: #{stroke}}
277
- "
278
-
279
- end
280
-
280
+ "
281
+
282
+ end
283
+
281
284
  xml = LineTree.new(s, root: 'nodes', debug: @debug).to_xml
282
-
285
+
283
286
  end
284
-
287
+
285
288
  # modify the value if it matches the following criteria
286
289
  #
287
290
  def m(s)
288
-
291
+
289
292
  # is it a shorthand hexcode? e.g. #fff
290
293
  s.gsub(/^#([\da-f]{3})$/)\
291
294
  { '#' + ($1).chars.inject([]) {|r,x| r << x + x}.join}
292
295
  end
293
-
296
+
294
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.4
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/a1iHRxi9fYFBbT3scMvWEzPE55/1mSGJ
21
- tPQF8bt/8krtSQsFqKfEWPaU8CiRT5m3s7CVwMZtAo/Ydo7UyMJ0ZEuviCLvzErS
22
- cyVD6OYF8mQd6gxNnAeHln9SEqDd9A/EOzdm1VYTW5+bicFYApwu34XlJvuqhv/0
23
- NJp6B5qIHnvBzdwjJdx0WuE+p+Rx1AwbwofKxvJogWZ6S9Eh12iV0ZCGob7akga2
24
- 2+tG/ovV3u4VFt4ilJiz4naMmbjkANK8Vag6W/fbhSEJZskle1u9O+aAhOsCAwEA
25
- AaOBijCBhzAJBgNV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WJbZFPCdpEX1l
35
+ n5la83UsDTB94LHIHb/W8YdApT3vWP/4nxl+/aAPJPBgyN8mZ4Td0FFgbaPGbW4e
36
+ PxZXxv6QqQ7uOHhRsvNRkYj3
37
37
  -----END CERTIFICATE-----
38
- date: 2019-06-10 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