graphvizml 0.3.1 → 0.4.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
  SHA1:
3
- metadata.gz: d2ee4042b59729e7f825e135a5aaa68c62595bd7
4
- data.tar.gz: 6418e4a1a1911768a6e2ba279d4788769a42ac36
3
+ metadata.gz: d063484a482cc9e2512ffd708dd8c8cfb29f85d2
4
+ data.tar.gz: 44a191e3277241d87b481a343fbfbd07ad0a293f
5
5
  SHA512:
6
- metadata.gz: 51aeed3ac59449d42ceb69db7f33dd0a759299090e77696e72a2f86ee9b34b856a3d5e20e76d0e5e28b79fb561444257e55fdf35256036e3aa56914ea11ad396
7
- data.tar.gz: 9fa09220d5e3e0fed477783a4a16730278782582674bf90dbcd8c4e21bb15dab32662071d6cf46306109b198d9a072bac13da2a10fb0424912dc4954655fed27
6
+ metadata.gz: 7622da9909b58dae25bd620f253f9a9711cd2eccad4ef20e3a6d1b9c38dda60ac59030934be4608b0a645a7f032bbc81aac225c837b04bc07d24d439c7c036df
7
+ data.tar.gz: 6fd1f2d279d1bf25ae43867bb5c80d1c27e7e7eb394272d8787f9175a83fa72f55e32c26101b404c98e515a2c0f9faae8b422ca9fe5d33a35a053fec22072cca
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/graphvizml.rb CHANGED
@@ -26,11 +26,10 @@ class GraphVizML
26
26
 
27
27
  h = @doc.root.attributes
28
28
 
29
- @type = h.has_key?(:type) ? h[:type].to_sym : :digraph
29
+ @type = (h.has_key?(:type) ? h[:type].to_sym : :digraph)
30
30
  direction = h.has_key?(:direction) ? h[:direction].to_s.upcase : 'LR'
31
31
 
32
- @g = GraphViz::new( :G, type: @type)
33
- @g[:rankdir] = direction
32
+ @g = Graphviz::Graph.new type: @type.to_s, rankdir: direction
34
33
 
35
34
  build()
36
35
 
@@ -39,26 +38,64 @@ class GraphVizML
39
38
  # writes to a PNG file (not a PNG blob)
40
39
  #
41
40
  def to_png(filename=@filename.sub(/\.xml$/,'.png'))
42
- @g.output( :png => filename )
41
+ Graphviz::output(@g, :path => filename)
43
42
  end
44
43
 
45
44
  # writes to a SVG file (not an SVG blob)
46
45
  #
47
46
  def to_svg(filename=@filename.sub(/\.xml$/,'.svg'))
48
- @g.output( :svg => filename )
47
+ Graphviz::output(@g, :path => filename)
49
48
  end
50
49
 
51
50
  private
52
51
 
53
52
  def build
54
53
 
55
- style = @doc.root.element('style')
56
-
57
- stylesheet = style ? style.text : default_stylesheet()
58
-
59
54
  e_nodes = @doc.root.element 'nodes'
60
55
  e_edges = @doc.root.element 'edges'
61
56
 
57
+ # add the nodes
58
+
59
+ nodes = {}
60
+
61
+ nodes = e_nodes.root.xpath('records/node').inject({}) do |r,node|
62
+
63
+ h =node.attributes
64
+ id = h[:id]
65
+ label = node.text('label')
66
+
67
+ # shape options: box, ellipse, record, diamond, circle, polygon, point
68
+ shape = h.has_key?(:shape) ? h[:shape] : :box
69
+ #puts "adding node id: %s label: %s" % [id, label]
70
+ r.merge(id => [label, {shape: shape}, nil])
71
+ end
72
+
73
+
74
+ # add the edges
75
+
76
+ id_1 = e_edges.root.element('records/edge/records/node/attribute::id').to_s
77
+ nodes[id_1][-1] = @g.add_node(nodes[id_1][0])
78
+
79
+
80
+ e_edges.root.xpath('records/edge').each do |edge|
81
+
82
+ id1, id2 = edge.xpath('records/node/attribute::id').map(&:to_s)
83
+
84
+ label = edge.text('summary/label').to_s
85
+ #puts "adding edge id1: %s id2: %s label: %s" % [id1, id2, label]
86
+ nodes[id2][-1] ||= nodes[id1].last.add_node(nodes[id2][0])
87
+
88
+ end
89
+
90
+ #puts @g.to_dot
91
+
92
+ # add the styling once the objects have been created
93
+
94
+ style = @doc.root.element('style')
95
+
96
+ stylesheet = style ? style.text : default_stylesheet()
97
+
98
+
62
99
  # parse the stylesheet
63
100
 
64
101
  a = stylesheet.split(/}/)[0..-2].map do |entry|
@@ -74,37 +111,25 @@ class GraphVizML
74
111
  end
75
112
 
76
113
  node_style = a.detect {|x| x.assoc 'node'}
77
- node_style.last.each {|key, value| @g.node[key] = value } if node_style
78
114
 
79
- edge_style = a.detect {|x| x.assoc 'edge'}
80
- edge_style.last.each {|key, value| @g.edge[key] = value } if edge_style
81
-
82
-
83
- # add the nodes
84
-
85
- e_nodes.root.xpath('records/node').each do |node|
86
-
87
- h =node.attributes
88
- id = h[:id]
89
- label = node.text('label')
115
+ if node_style then
90
116
 
91
- # shape options: box, ellipse, record, diamond, circle, polygon, point
92
- shape = h.has_key?(:shape) ? h[:shape] : :box
93
- #puts "adding node id: %s label: %s" % [id, label]
94
- @g.add_node(id, shape: shape).label = label
117
+ nodes.each do |id, x|
118
+ node_style.last.each {|key, value| x.last.attributes[key] = value }
119
+ end
95
120
  end
121
+
122
+ edge_style = a.detect {|x| x.assoc 'edge'}
123
+
124
+ if edge_style then
96
125
 
97
- # add the edges
98
-
99
- e_edges.root.xpath('records/edge').each do |edge|
100
-
101
- a = edge.xpath('records/node')
126
+ nodes.each do |id,x|
127
+ x.last.connections.each do |conn|
128
+ edge_style.last.each {|key, value| conn.attributes[key] = value }
129
+ end
130
+ end
131
+ end
102
132
 
103
- id1, id2 = a[0].attribute('id').to_s, a[1].attribute('id').to_s
104
- label = edge.text('summary/label').to_s
105
- #puts "adding edge id1: %s id2: %s label: %s" % [id1, id2, label]
106
- @g.add_edge(id1, id2).label = label
107
- end
108
133
 
109
134
  :build
110
135
  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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -54,25 +54,25 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.4.7
56
56
  - !ruby/object:Gem::Dependency
57
- name: ruby-graphviz
57
+ name: graphviz
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1.2'
62
+ version: '0.4'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 1.2.3
65
+ version: 0.4.0
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '1.2'
72
+ version: '0.4'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.2.3
75
+ version: 0.4.0
76
76
  description:
77
77
  email: james@jamesrobertson.eu
78
78
  executables: []
@@ -103,5 +103,6 @@ rubyforge_project:
103
103
  rubygems_version: 2.6.8
104
104
  signing_key:
105
105
  specification_version: 4
106
- summary: Generates a PNG file from GraphViz using a GraphViz Markup Language file
106
+ summary: Generates an SVG file or PNG file from GraphViz using a GraphViz Markup Language
107
+ file
107
108
  test_files: []
metadata.gz.sig CHANGED
Binary file