ruby-graphviz_c 1.1.0 → 1.1.1

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
2
  SHA1:
3
- metadata.gz: 15318896ef1e1aade7b73588478dde2d3bd1deaa
4
- data.tar.gz: 5f20d17a7415e14d42590081a3d79d7ee3e0a317
3
+ metadata.gz: 24506db22ea6fd7e47f7d163fd56d3cefed2982d
4
+ data.tar.gz: 33275a0dd912e2a6cd28f1357bebb4f0b5b4b9f6
5
5
  SHA512:
6
- metadata.gz: 22432b9db81be820037fb22bdec857dcf08c577e2d20c24a9fd15180e7f2360d83680965184408914f08fb840d525ccb63f1ad64ac25c65e93acc62e5b73a0b7
7
- data.tar.gz: 00fba34218edcd804f9ee0bfdf5e8bc9da6699ecfe4adaa23080d1395e5372bc8dc74946cb9448375d90658d7d2c2a197a6feb1d1fe02e29f5241c371cdd73ec
6
+ metadata.gz: 5fcc07aa946788eb222333c729b5b22eccd44912c78fdde6adc30b8792bf20b1ca4029970ae7d66d31a139589931841854f5abbef37155022593833f073bdac9
7
+ data.tar.gz: d7c4cbe57471fa8d7ea6aa0ba7f1018683a249e03aa2222dfa5c0adbb735d97e4997fbeec78b4759fb6772caf5904c355d0e5a060a6dfcd18503721501c29d1e
@@ -41,7 +41,7 @@
41
41
  #
42
42
  class GraphViz
43
43
  module Constants
44
- RGV_VERSION = "1.1.0"
44
+ RGV_VERSION = "1.1.1"
45
45
 
46
46
  ## Const: Output formats
47
47
  FORMATS = [
data/lib/graphviz/edge.rb CHANGED
@@ -18,151 +18,151 @@ require 'graphviz/attrs'
18
18
  require 'graphviz/constants'
19
19
 
20
20
  class GraphViz
21
- class Edge
22
- include GraphViz::Constants
23
-
24
- # Create a new edge
25
- #
26
- # In:
27
- # * vNodeOne : First node (can be a GraphViz::Node or a node ID)
28
- # * vNodeTwo : Second node (can be a GraphViz::Node or a node ID)
29
- # * parent_graph : Graph
30
- def initialize( vNodeOne, vNodeTwo, parent_graph )
31
- @node_one_id, @node_one_port = getNodeNameAndPort( vNodeOne )
32
- @node_two_id, @node_two_port = getNodeNameAndPort( vNodeTwo )
33
-
34
- @parent_graph = parent_graph
35
- @edge_attributes = GraphViz::Attrs::new( nil, "edge", EDGESATTRS )
36
- @index = nil
37
-
38
- unless @parent_graph.directed?
39
- (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).incidents << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id))
40
- (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).neighbors << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id))
41
- end
42
- (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).neighbors << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id))
43
- (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).incidents << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id))
44
- end
45
-
46
- # Return the node one as string (so with port if any)
47
- def node_one( with_port = true )
48
- if not(@node_one_port and with_port)
49
- GraphViz.escape(@node_one_id)
50
- else
51
- GraphViz.escape(@node_one_id, :force => true) + ":#{@node_one_port}"
52
- end
53
- end
54
- alias :tail_node :node_one
55
-
56
- # Return the node two as string (so with port if any)
57
- def node_two( with_port = true )
58
- if not(@node_two_port and with_port)
59
- GraphViz.escape(@node_two_id)
60
- else
61
- GraphViz.escape(@node_two_id, :force => true) + ":#{@node_two_port}"
62
- end
63
- end
64
- alias :head_node :node_two
65
-
66
- # Return the index of the edge
67
- def index
68
- @index
69
- end
70
- def index=(i) #:nodoc:
71
- @index = i if @index == nil
72
- end
73
-
74
- # Set value +attribute_value+ to the edge attribute +attribute_name+
75
- def []=( attribute_name, attribute_value )
76
- attribute_value = attribute_value.to_s if attribute_value.class == Symbol
77
- @edge_attributes[attribute_name.to_s] = attribute_value
78
- end
79
-
80
- # Set values for edge attributes or
81
- # get the value of the given edge attribute +attribute_name+
82
- def []( attribute_name )
83
- # Modification by axgle (http://github.com/axgle)
84
- if Hash === attribute_name
85
- attribute_name.each do |key, value|
86
- self[key] = value
87
- end
88
- else
89
- if @edge_attributes[attribute_name.to_s]
90
- @edge_attributes[attribute_name.to_s].clone
91
- else
92
- nil
93
- end
94
- end
95
- end
96
-
97
- #
98
- # Calls block once for each attribute of the edge, passing the name and value to the
99
- # block as a two-element array.
100
- #
101
- # If global is set to false, the block does not receive the attributes set globally
102
- #
103
- def each_attribute(global = true, &b)
104
- attrs = @edge_attributes.to_h
105
- if global
106
- attrs = pg.edge.to_h.merge attrs
107
- end
108
- attrs.each do |k,v|
109
- yield(k,v)
110
- end
111
- end
112
- def each_attribut(global = true, &b)
113
- warn "`GraphViz::Edge#each_attribut` is deprecated, please use `GraphViz::Edge#each_attribute`"
114
- each_attribute(global, &b)
115
- end
116
-
117
- def <<( node ) #:nodoc:
118
- n = @parent_graph.get_node(@node_two_id)
119
-
120
- GraphViz::commonGraph( node, n ).add_edges( n, node )
121
- end
122
- alias :> :<< #:nodoc:
123
- alias :- :<< #:nodoc:
124
- alias :>> :<< #:nodoc:
125
-
126
- #
127
- # Return the root graph
128
- #
129
- def root_graph
130
- return( (self.pg.nil?) ? nil : self.pg.root_graph )
131
- end
132
-
133
- def pg #:nodoc:
134
- @parent_graph
135
- end
136
-
137
- # Set edge attributes
138
- #
139
- # Example :
140
- # e = graph.add_edges( ... )
141
- # ...
142
- # e.set { |_e|
143
- # _e.color = "blue"
144
- # _e.fontcolor = "red"
145
- # }
146
- def set( &b )
147
- yield( self )
148
- end
149
-
150
- # Add edge options
151
- # use edge.<option>=<value> or edge.<option>( <value> )
152
- def method_missing( idName, *args, &block ) #:nodoc:
153
- return if idName == :to_ary # ruby 1.9.2 fix
154
- xName = idName.id2name
155
-
156
- self[xName.gsub( /=$/, "" )]=args[0]
157
- end
158
-
159
- def output( oGraphType ) #:nodoc:
160
- xLink = " -> "
21
+ class Edge
22
+ include GraphViz::Constants
23
+
24
+ # Create a new edge
25
+ #
26
+ # In:
27
+ # * vNodeOne : First node (can be a GraphViz::Node or a node ID)
28
+ # * vNodeTwo : Second node (can be a GraphViz::Node or a node ID)
29
+ # * parent_graph : Graph
30
+ def initialize( vNodeOne, vNodeTwo, parent_graph )
31
+ @node_one_id, @node_one_port = getNodeNameAndPort( vNodeOne )
32
+ @node_two_id, @node_two_port = getNodeNameAndPort( vNodeTwo )
33
+
34
+ @parent_graph = parent_graph
35
+ @edge_attributes = GraphViz::Attrs::new( nil, "edge", EDGESATTRS )
36
+ @index = nil
37
+
38
+ unless @parent_graph.directed?
39
+ (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).incidents << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id))
40
+ (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).neighbors << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id))
41
+ end
42
+ (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).neighbors << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id))
43
+ (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).incidents << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id))
44
+ end
45
+
46
+ # Return the node one as string (so with port if any)
47
+ def node_one( with_port = true )
48
+ if not(@node_one_port and with_port)
49
+ @node_one_id
50
+ else
51
+ "#{@node_one_id}:#{@node_one_port}"
52
+ end
53
+ end
54
+ alias :tail_node :node_one
55
+
56
+ # Return the node two as string (so with port if any)
57
+ def node_two( with_port = true )
58
+ if not(@node_two_port and with_port)
59
+ @node_two_id
60
+ else
61
+ "#{@node_two_id}:#{@node_two_port}"
62
+ end
63
+ end
64
+ alias :head_node :node_two
65
+
66
+ # Return the index of the edge
67
+ def index
68
+ @index
69
+ end
70
+ def index=(i) #:nodoc:
71
+ @index = i if @index == nil
72
+ end
73
+
74
+ # Set value +attribute_value+ to the edge attribute +attribute_name+
75
+ def []=( attribute_name, attribute_value )
76
+ attribute_value = attribute_value.to_s if attribute_value.class == Symbol
77
+ @edge_attributes[attribute_name.to_s] = attribute_value
78
+ end
79
+
80
+ # Set values for edge attributes or
81
+ # get the value of the given edge attribute +attribute_name+
82
+ def []( attribute_name )
83
+ # Modification by axgle (http://github.com/axgle)
84
+ if Hash === attribute_name
85
+ attribute_name.each do |key, value|
86
+ self[key] = value
87
+ end
88
+ else
89
+ if @edge_attributes[attribute_name.to_s]
90
+ @edge_attributes[attribute_name.to_s].clone
91
+ else
92
+ nil
93
+ end
94
+ end
95
+ end
96
+
97
+ #
98
+ # Calls block once for each attribute of the edge, passing the name and value to the
99
+ # block as a two-element array.
100
+ #
101
+ # If global is set to false, the block does not receive the attributes set globally
102
+ #
103
+ def each_attribute(global = true, &b)
104
+ attrs = @edge_attributes.to_h
105
+ if global
106
+ attrs = pg.edge.to_h.merge attrs
107
+ end
108
+ attrs.each do |k,v|
109
+ yield(k,v)
110
+ end
111
+ end
112
+ def each_attribut(global = true, &b)
113
+ warn "`GraphViz::Edge#each_attribut` is deprecated, please use `GraphViz::Edge#each_attribute`"
114
+ each_attribute(global, &b)
115
+ end
116
+
117
+ def <<( node ) #:nodoc:
118
+ n = @parent_graph.get_node(@node_two_id)
119
+
120
+ GraphViz::commonGraph( node, n ).add_edges( n, node )
121
+ end
122
+ alias :> :<< #:nodoc:
123
+ alias :- :<< #:nodoc:
124
+ alias :>> :<< #:nodoc:
125
+
126
+ #
127
+ # Return the root graph
128
+ #
129
+ def root_graph
130
+ return( (self.pg.nil?) ? nil : self.pg.root_graph )
131
+ end
132
+
133
+ def pg #:nodoc:
134
+ @parent_graph
135
+ end
136
+
137
+ # Set edge attributes
138
+ #
139
+ # Example :
140
+ # e = graph.add_edges( ... )
141
+ # ...
142
+ # e.set { |_e|
143
+ # _e.color = "blue"
144
+ # _e.fontcolor = "red"
145
+ # }
146
+ def set( &b )
147
+ yield( self )
148
+ end
149
+
150
+ # Add edge options
151
+ # use edge.<option>=<value> or edge.<option>( <value> )
152
+ def method_missing( idName, *args, &block ) #:nodoc:
153
+ return if idName == :to_ary # ruby 1.9.2 fix
154
+ xName = idName.id2name
155
+
156
+ self[xName.gsub( /=$/, "" )]=args[0]
157
+ end
158
+
159
+ def output( oGraphType ) #:nodoc:
160
+ xLink = " -> "
161
161
  if oGraphType == "graph"
162
162
  xLink = " -- "
163
163
  end
164
164
 
165
- xOut = self.node_one + xLink + self.node_two
165
+ xOut = GraphViz.escape(self.node_one) + xLink + GraphViz.escape(self.node_two)
166
166
  xAttr = ""
167
167
  xSeparator = ""
168
168
  @edge_attributes.data.each do |k, v|
data/test/test_graph.rb CHANGED
@@ -104,6 +104,19 @@ class GraphVizTest < Test::Unit::TestCase
104
104
  assert_nil c1.search_node("a0")
105
105
  end
106
106
 
107
+ def test_getting_escaped_node_from_edge
108
+ @g = GraphViz.graph "G" do |g|
109
+ g.add_nodes 'a@com'
110
+ g.add_nodes 'b@com'
111
+ g.add_edges 'a@com', 'b@com'
112
+ end
113
+
114
+ @g.each_edge do |e|
115
+ assert_not_nil @g.get_node e.node_one
116
+ assert_not_nil @g.get_node e.node_two
117
+ end
118
+ end
119
+
107
120
  def test_to_s
108
121
  assert_nothing_raised 'to_s with edge with numeric label failed.' do
109
122
  a = @graph.add_nodes('a')
data/test/test_theory.rb CHANGED
@@ -95,4 +95,18 @@ class GraphVizTheoryTest < Test::Unit::TestCase
95
95
  assert_equal [1, 6], r[:path]
96
96
  assert_equal 6.0, r[:distance]
97
97
  end
98
+
99
+ def test_escaped_node_ids__adjancy_matrix
100
+ @g = GraphViz.graph "G" do |g|
101
+ g.add_nodes 'a@com'
102
+ g.add_nodes 'b@com'
103
+ g.add_edges 'a@com', 'b@com'
104
+ end
105
+
106
+ @t = GraphViz::Theory.new( @g )
107
+
108
+ assert_nothing_raised NoMethodError do
109
+ @t.adjancy_matrix
110
+ end
111
+ end
98
112
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-graphviz_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Clausen