graphvizml 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c518866f1ae8f45f7e48fb850ecae83c3ca7df99
4
- data.tar.gz: 9ffb3522c4aee7d887dfe1734797a751056ca9ef
2
+ SHA256:
3
+ metadata.gz: 2ff0cd920435956aaf72422a17a849f326726c37cc63b2f7f87cc6fb3de6c697
4
+ data.tar.gz: 6df521883b1b22c4c78dc9b89487139c281e5fc61daf09b9e4e3092f24ddef9f
5
5
  SHA512:
6
- metadata.gz: '039b03b9fb2d33c7bdd4f0e7664f73dde30b1f60ff77771669df918c9f95fbe27de0301b80dd483400cebac95b913a3f3612d59ed0ca00836821610cc4765821'
7
- data.tar.gz: a43c19e842e379f69641fea9969fe3b0fa399f4435a7b0d32c02b9ac2460e376caa4569e2e1f28f1c17d59ed524df97dafa55b0a6a7d4fd2d7da6cda6fa030d1
6
+ metadata.gz: bfb61f402699fb0d36d1500a5c69c97902ba989a14e3a549f80d913e624ea099e3fd43d6ffd19f0d5e93adf00d511cc7c3403bc149b53ffea5ac275e8bd69715
7
+ data.tar.gz: c95c574367ad7eb83f56b62abd25b55070e3224bd2260f19643cedc95a9a4fc26781105ec79ec205b37c85b1538be2814aed72cc1ccb2d69521b5166131e5e6e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/graphvizml.rb CHANGED
@@ -5,57 +5,92 @@
5
5
 
6
6
  require 'domle'
7
7
  require 'graphviz'
8
- require 'tempfile'
8
+ require 'line-tree'
9
9
 
10
10
 
11
+ module RegGem
12
+
13
+ def self.register()
14
+ '
15
+ hkey_gems
16
+ doctype
17
+ graphvizml
18
+ require graphvizml
19
+ class GraphVizML
20
+ media_type svg
21
+ '
22
+ end
23
+ end
24
+
11
25
  class GraphVizML
26
+ using ColouredText
12
27
 
28
+ attr_accessor :css, :stroke, :fill, :text_color
13
29
  attr_reader :g
14
30
 
15
- def initialize(obj)
31
+ def initialize(obj=nil, debug: false, fill: 'transparent', stroke: '#000', text_color: '#000')
16
32
 
17
- xml = if obj.is_a? String then
18
-
19
- File.read filename=obj
33
+ @debug = debug
34
+ @fill, @stroke, @text_color = fill, stroke, text_color
35
+
36
+ if obj then
20
37
 
21
- elsif obj.is_a? Rexle or obj.is_a? Rexle::Element
38
+ s = RXFHelper.read(obj).first
39
+
40
+ if s =~ /<\?graphvizml\b/ then
41
+
42
+ import_string s
43
+
44
+ else
45
+
46
+ if @debug then
47
+ #File.write '/tmp/graphviz.xml', xml
48
+ puts('graphvizml xml: ' + s.inspect)
49
+ end
50
+
51
+ @g = build_from_nodes Domle.new(s)
52
+
53
+ end
22
54
 
23
- obj.xml
24
-
25
55
  end
56
+
57
+ @css = "
58
+ .node ellipse {stroke: #{stroke}; fill: #{fill}}
59
+ .node text {fill: #{text_color}}
60
+ .edge path {stroke: #{stroke}}
61
+ .edge polygon {stroke: #{stroke}; fill: #{stroke}}
62
+ "
26
63
 
27
- @g = build_from_nodes Domle.new(xml)
28
-
29
64
  end
30
65
 
66
+ def import(obj)
67
+
68
+ s = RXFHelper.read(obj).first
69
+ import_string s
70
+
71
+ end
72
+
73
+
31
74
  def to_dot()
32
75
  @g.to_dot
33
76
  end
34
77
 
35
- # returns a PNG blob
36
- #
37
- def to_png()
38
- f = Tempfile.new('graphvizml')
39
- Graphviz::output(@g, output_format: 'png', path: f.path)
40
- File.read f.path
41
- end
42
78
 
43
79
  # returns an SVG blob
44
80
  #
45
81
  def to_svg()
46
- f = Tempfile.new('graphvizml')
47
- Graphviz::output(@g, format: 'svg', path: f.path)
48
- File.read f.path
82
+ svg = Graphviz::output(@g, format: 'svg')
83
+ svg.sub!('xmlns:xlink="http://www.w3.org/1999/xlink"','')
84
+ svg.lines.insert(8, css_code()).join
49
85
  end
50
86
 
51
- def write(filename)
52
- Graphviz::output(@g, :path => filename)
53
- end
54
87
 
55
88
  private
56
89
 
57
90
 
58
- def build_from_nodes(doc)
91
+ def build_from_nodes(doc)
92
+
93
+ puts 'inside build_from_nodes'.info if @debug
59
94
 
60
95
  g = Graphviz::Graph.new format_summary_attributes(doc.root.attributes)
61
96
 
@@ -66,8 +101,15 @@ class GraphVizML
66
101
  r.merge fetch_node(e)
67
102
 
68
103
  end
104
+
105
+ if @debug then
106
+ puts 'nodes: ' + nodes.inspect
107
+ puts 'doc: ' + doc.root.xml.inspect
108
+ end
69
109
 
70
- a = doc.root.element('style/text()').strip.split(/}/).map do |entry|
110
+ a = doc.root.element('style/text()').to_s.strip.split(/}/).map do |entry|
111
+
112
+ puts 'entry: ' + entry.inspect if @debug
71
113
 
72
114
  raw_selector,raw_styles = entry.split(/{/,2)
73
115
 
@@ -79,7 +121,11 @@ class GraphVizML
79
121
  [raw_selector.split(/,\s*/).map(&:strip), h]
80
122
  end
81
123
 
82
- edge_style = a.find {|x| x[0].grep(/edge/).any?}.last
124
+ puts ' a: ' + a.inspect if @debug
125
+
126
+
127
+ edge_style = a.any? ? a.find {|x| x[0].grep(/edge/).any?}.last : []
128
+
83
129
 
84
130
 
85
131
  # add the edges
@@ -92,13 +138,13 @@ class GraphVizML
92
138
 
93
139
  next unless node.name == 'node'
94
140
 
95
- node.xpath('a | node').each do |childx|
141
+ node.xpath('a/node | node').each do |child|
96
142
 
97
- child = childx.name == 'node' ? childx : childx.element('node')
98
143
  id1, id2 = node.object_id, child.object_id
99
144
 
100
145
  label = child.attributes[:connection].to_s
101
-
146
+ puts('nodes[id1]: ' + nodes[id1].inspect) if @debug
147
+ puts('nodes[id1].last: ' + nodes[id1].last.inspect) if @debug
102
148
  nodes[id2][-1] ||= nodes[id1].last.add_node(nodes[id2][0])
103
149
  attributes = child.style.merge({label: label})
104
150
 
@@ -116,9 +162,24 @@ class GraphVizML
116
162
 
117
163
  end
118
164
 
165
+ def css_code()
166
+ <<EOF
167
+ <defs>
168
+ <style type='text/css'><![CDATA[
169
+ #{@css}
170
+ ]]></style>
171
+ </defs>
172
+
173
+ EOF
174
+ end
175
+
119
176
  def fetch_node(node)
120
177
 
178
+ puts 'inside fetch_node'.info if @debug
179
+
121
180
  h = node.attributes
181
+ #puts 'h: ' + h.inspect
182
+ puts('graphvizml/fetch_node h: ' + h.inspect) if @debug
122
183
 
123
184
  if node.parent.name == 'a' then
124
185
 
@@ -134,7 +195,7 @@ class GraphVizML
134
195
 
135
196
  style = {}
136
197
 
137
- style[:shape] = h[:shape] unless h[:shape].empty?
198
+ style[:shape] = h[:shape] if h[:shape] and !h[:shape].empty?
138
199
  style[:URL] = h[:url] if h[:url]
139
200
 
140
201
  #puts "adding node id: %s label: %s" % [id, label]
@@ -173,6 +234,39 @@ class GraphVizML
173
234
  h
174
235
  end
175
236
 
237
+
238
+ def import_string(obj)
239
+
240
+ s = RXFHelper.read(obj).first
241
+
242
+ s2 = s.slice(/<\?graphvizml\b[^>]*\?>/)
243
+
244
+ if s2 then
245
+
246
+ attributes = %w(id fill stroke text_color).inject({}) do |r, keyword|
247
+ found = s2[/(?<=#{keyword}=['"])[^'"]+/]
248
+ found ? r.merge(keyword.to_sym => found) : r
249
+ end
250
+
251
+ fill, stroke, text_color = %i(fill stroke text_color).map do |x|
252
+ attributes[x] ? attributes[x] : method(x).call
253
+ end
254
+
255
+ @css = "
256
+ .node ellipse {stroke: #{stroke}; fill: #{fill}}
257
+ .node text {fill: #{text_color}}
258
+ .edge path {stroke: #{stroke}}
259
+ .edge polygon {stroke: #{stroke}; fill: #{stroke}}
260
+ "
261
+
262
+ end
263
+
264
+ xml = LineTree.new(s, root: 'nodes', debug: true).to_xml
265
+ @g = build_from_nodes Domle.new(xml)
266
+ self
267
+
268
+ end
269
+
176
270
  # modify the value if it matches the following criteria
177
271
  #
178
272
  def m(s)
@@ -182,4 +276,4 @@ class GraphVizML
182
276
  { '#' + ($1).chars.inject([]) {|r,x| r << x + x}.join}
183
277
  end
184
278
 
185
- end
279
+ end
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.8
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE3MDEwNjEzMjA1MloXDTE4MDEwNjEzMjA1MlowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAOTZDlwcF3nlkpgerB73R+FnQaD/dbGeRqYOfBmeTaPuzHOE2ZqqrojvEIlH
19
- JhmEs3RP3/nIGjlmUrf6QvCnvGAgPgxnoCWw48LHcwLGefk8+M4SUOvox4T4N7gy
20
- RQpITK88ZyDwt5mzYaLHwT4pX+LjexWBTjOI1xNhh9aiBgcuq7E32a8xgULMZk+e
21
- Jy1cYkgf0xDyf70t0bCuxtycDXaZFE2nC1P7oQS5lyYWzltiGigltTmtoBSoblNB
22
- tKym6PIq+Dy81m//jKffGOkd+oe5U/VNFYCaM4mXJis4VhxrR/rbcrFN75FY32wZ
23
- Sgarov2CBapH8K6b4FZOJZT0aXECAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
- DwQEAwIEsDAdBgNVHQ4EFgQUULJuuHOowirVpIUB5xhE27wdZuUwJgYDVR0RBB8w
25
- HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
- c3RlckBqYW1lc3J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  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: domle
@@ -39,40 +43,60 @@ dependencies:
39
43
  requirements:
40
44
  - - "~>"
41
45
  - !ruby/object:Gem::Version
42
- version: '0.2'
46
+ version: '0.3'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 0.2.0
49
+ version: 0.3.1
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
54
  - - "~>"
51
55
  - !ruby/object:Gem::Version
52
- version: '0.2'
56
+ version: '0.3'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 0.2.0
59
+ version: 0.3.1
56
60
  - !ruby/object:Gem::Dependency
57
61
  name: graphviz
58
62
  requirement: !ruby/object:Gem::Requirement
59
63
  requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '0.4'
63
64
  - - ">="
64
65
  - !ruby/object:Gem::Version
65
- version: 0.4.0
66
+ version: 1.1.0
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.1'
66
70
  type: :runtime
67
71
  prerelease: false
68
72
  version_requirements: !ruby/object:Gem::Requirement
69
73
  requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.1.0
70
77
  - - "~>"
71
78
  - !ruby/object:Gem::Version
72
- version: '0.4'
79
+ version: '1.1'
80
+ - !ruby/object:Gem::Dependency
81
+ name: line-tree
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
73
84
  - - ">="
74
85
  - !ruby/object:Gem::Version
75
- version: 0.4.0
86
+ version: 0.8.0
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.0
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.8'
76
100
  description:
77
101
  email: james@jamesrobertson.eu
78
102
  executables: []
@@ -99,10 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
123
  - !ruby/object:Gem::Version
100
124
  version: '0'
101
125
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.8
126
+ rubygems_version: 3.0.1
104
127
  signing_key:
105
128
  specification_version: 4
106
- summary: Generates an SVG file or PNG file from GraphViz using a GraphViz Markup Language
107
- file
129
+ summary: Generates an SVG file from GraphViz using a GraphViz Markup Language file
108
130
  test_files: []
metadata.gz.sig CHANGED
Binary file