ruby-graphviz_c 1.1.0 → 1.1.1
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 +4 -4
- data/lib/graphviz/constants.rb +1 -1
- data/lib/graphviz/edge.rb +141 -141
- data/test/test_graph.rb +13 -0
- data/test/test_theory.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24506db22ea6fd7e47f7d163fd56d3cefed2982d
|
4
|
+
data.tar.gz: 33275a0dd912e2a6cd28f1357bebb4f0b5b4b9f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fcc07aa946788eb222333c729b5b22eccd44912c78fdde6adc30b8792bf20b1ca4029970ae7d66d31a139589931841854f5abbef37155022593833f073bdac9
|
7
|
+
data.tar.gz: d7c4cbe57471fa8d7ea6aa0ba7f1018683a249e03aa2222dfa5c0adbb735d97e4997fbeec78b4759fb6772caf5904c355d0e5a060a6dfcd18503721501c29d1e
|
data/lib/graphviz/constants.rb
CHANGED
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|