mootoh-rubigraph 0.2.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.
@@ -0,0 +1,12 @@
1
+ === 0.1.0 / 2008-05-29
2
+
3
+ * 2nd release
4
+
5
+ * works with UbiGraph-alpha-0.2.2-r1680.
6
+
7
+ === 0.0.1 / 2008-05-25
8
+
9
+ * initial release
10
+
11
+ * Birthday!
12
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/rubigraph.rb
6
+ test/test_rubigraph.rb
@@ -0,0 +1,61 @@
1
+ = Rubigraph
2
+
3
+ http://rubyforge.org/projects/rubigraph
4
+
5
+ == DESCRIPTION:
6
+
7
+ a Ruby wrap for Ubigraph (http://www.ubietylab.net/ubigraph).
8
+
9
+ see http://www.ubietylab.net/ubigraph/content/Docs/index.html to get complete description about API.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ It provides a shortcut to plot, draw a graph (by calling XML-RPC internally).
14
+
15
+ == SYNOPSIS:
16
+ Make sure Ubigraph serverr is started before using this library.
17
+
18
+ require 'rubigraph'
19
+ Rubigraph.init
20
+
21
+ v1 = Vertex.new
22
+ v2 = Vertex.new
23
+ e12 = Edge.new(v1, v2)
24
+
25
+ v1.color = '#003366'
26
+ v2.shape = 'sphere'
27
+ e12.label = 'edge between 1 and 2'
28
+
29
+ == REQUIREMENTS:
30
+
31
+ Ubigraph (http://www.ubietylab.net/ubigraph),
32
+ tested under rev1450, rev1554
33
+
34
+ == INSTALL:
35
+
36
+ sudo gem install
37
+
38
+ == LICENSE:
39
+
40
+ The MIT License
41
+
42
+ Copyright (c) 2008 mootoh
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/rubigraph.rb'
6
+
7
+ Hoe.new('rubigraph', Rubigraph::VERSION) do |p|
8
+ p.rubyforge_name = 'rubigraph' # if different than lowercase project name
9
+ p.email = 'mootoh@gmail.com'
10
+ p.author = 'mootoh'
11
+ end
12
+
13
+ # vim: syntax=Ruby
@@ -0,0 +1,195 @@
1
+ require 'xmlrpc/client'
2
+ require 'pp'
3
+ require 'thread'
4
+
5
+ #
6
+ # Ruby wrapper for Ubigraph.
7
+ #
8
+ # Call Rubigraph.init at first.
9
+ #
10
+ module Rubigraph
11
+ VERSION = '0.2.0'
12
+
13
+ class Vertex
14
+ attr_reader :id
15
+
16
+ def initialize(id = Rubigraph.genid)
17
+ @id = id
18
+ Rubigraph.call('ubigraph.new_vertex_w_id', id)
19
+ end
20
+
21
+ def remove
22
+ Rubigraph.call('ubigraph.remove_vertex', @id)
23
+ end
24
+
25
+ def set_attribute(att, value)
26
+ Rubigraph.call('ubigraph.set_vertex_attribute', @id, att, value.to_s)
27
+ end
28
+
29
+ def set_attributes(attrs)
30
+ attrs.each do |k, v|
31
+ Rubigraph.call('ubigraph.set_vertex_attribute', @id, k, v.to_s)
32
+ end
33
+ end
34
+
35
+ def color=(c)
36
+ set_attribute('color', c)
37
+ end
38
+
39
+ def colour=(c)
40
+ self.color=(c)
41
+ end
42
+
43
+ def shape=(s)
44
+ set_attribute('shape', s)
45
+ end
46
+
47
+ def shapedetail=(d)
48
+ set_attribute('shapedetail', d)
49
+ end
50
+
51
+ def label=(l)
52
+ set_attribute('label', l)
53
+ end
54
+
55
+ def labelpos=(p)
56
+ set_attribute('labelpos', p)
57
+ end
58
+
59
+ def size=(s)
60
+ set_attribute('size', s)
61
+ end
62
+
63
+ def fontcolor=(c)
64
+ set_attribute('fontcolor', c)
65
+ end
66
+
67
+ def fontfamily=(f)
68
+ # TODO: should assert 'Helvetica' | 'Times Roman'
69
+ set_attribute('fontfamily', f)
70
+ end
71
+
72
+ def fontsize=(s)
73
+ # TODO: should assert 10, 12, 18. 24
74
+ set_attribute('fontsize', s)
75
+ end
76
+ end # Vertex
77
+
78
+ # Edge between Vertexes
79
+ class Edge
80
+ # create an Edge.
81
+ # from, to should be Vertex.
82
+ def initialize(from, to, id = Rubigraph.genid)
83
+ @id = id
84
+ Rubigraph.call('ubigraph.new_edge_w_id', id, from.id, to.id)
85
+ end
86
+
87
+ def remove
88
+ Rubigraph.call('ubigraph.remove_edge', @id)
89
+ end
90
+
91
+ def set_attribute(att, value)
92
+ Rubigraph.call('ubigraph.set_edge_attribute', @id, att, value.to_s)
93
+ end
94
+
95
+ def set_attributes(attrs)
96
+ attrs.each do |k, v|
97
+ Rubigraph.call('ubigraph.set_edge_attribute', @id, k, v.to_s)
98
+ end
99
+ end
100
+
101
+ def color=(c)
102
+ set_attribute('color', c)
103
+ end
104
+
105
+ def colour=(c)
106
+ self.color=(c)
107
+ end
108
+
109
+ def label=(l)
110
+ set_attribute('label', l)
111
+ end
112
+
113
+ def labelpos=(p)
114
+ set_attribute('labelpos', p)
115
+ end
116
+
117
+ def fontcolor=(c)
118
+ set_attribute('fontcolor', c)
119
+ end
120
+
121
+ def fontfamily=(f)
122
+ # TODO: should assert 'Helvetica' | 'Times Roman'
123
+ set_attribute('fontfamily', f)
124
+ end
125
+
126
+ def fontsize=(s)
127
+ # TODO: should assert 10, 12, 18. 24
128
+ set_attribute('fontsize', s)
129
+ end
130
+
131
+ def strength=(s)
132
+ set_attribute('strength', s)
133
+ end
134
+
135
+ def orientationweight=(o)
136
+ set_attribute('orientationweight', o)
137
+ end
138
+
139
+ def width=(w)
140
+ set_attribute('width', w)
141
+ end
142
+
143
+ def arrow=(a)
144
+ set_attribute('arrow', a)
145
+ end
146
+
147
+ def showstrain=(s)
148
+ set_attribute('showstrain', s)
149
+ end
150
+
151
+ end # Edge
152
+
153
+
154
+ # initialize XML-RPC client
155
+ def self.init(host='127.0.0.1', port='20738',ttl=1)
156
+ @server = XMLRPC::Client.new2("http://#{host}:#{port}/RPC2")
157
+ @mutex = Mutex.new
158
+ @pool = Array.new
159
+ @num = -1 * (1 << 31) - 1 # XMLPRC i4's minimum
160
+ @flusher = Thread.start(ttl) do |ttl|
161
+ while true do
162
+ sleep ttl
163
+ flush!
164
+ end
165
+ end
166
+ at_exit { flush! }
167
+ end
168
+
169
+ # clear all vertex, edges
170
+ def self.clear
171
+ call('ubigraph.clear')
172
+ flush!
173
+ end
174
+
175
+ def self.flush!
176
+ @mutex.synchronize {
177
+ @server.multicall(*@pool)
178
+ @pool.clear
179
+ }
180
+ end
181
+
182
+ def self.genid
183
+ @mutex.synchronize {
184
+ @num += 1
185
+ }
186
+ @num
187
+ end
188
+
189
+ def self.call(*argv)
190
+ @mutex.synchronize {
191
+ @pool.push argv
192
+ }
193
+ flush! if @pool.size >= 256
194
+ end
195
+ end # Rubigraph
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'lib/rubigraph'
3
+
4
+ Rubigraph.init
5
+
6
+ class RubigraphTest < Test::Unit::TestCase
7
+ def test_clear
8
+ Rubigraph.clear
9
+ end
10
+
11
+ def test_vertex
12
+ v = Rubigraph::Vertex.new
13
+ v.set_attribute('size', '2.0')
14
+ v.remove
15
+ end
16
+
17
+ def test_edge
18
+ v1 = Rubigraph::Vertex.new
19
+ v2 = Rubigraph::Vertex.new
20
+ e = Rubigraph::Edge.new(v1, v2)
21
+ e.label = 'edge'
22
+ e.remove
23
+ end
24
+
25
+ def test_many
26
+ vs = []
27
+ 100.times do |i|
28
+ v = Rubigraph::Vertex.new
29
+ v.color = sprintf("#%02d%02d%02d", i, i, i)
30
+ vs.push v
31
+ end
32
+
33
+ 100.times do |i|
34
+ e = Rubigraph::Edge.new(vs[i], vs[(i+1)%100])
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mootoh-rubigraph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - mootoh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.3
24
+ version:
25
+ description: a Ruby wrap for Ubigraph (http://www.ubietylab.net/ubigraph). see http://www.ubietylab.net/ubigraph/content/Docs/index.html to get complete description about API.
26
+ email: mootoh@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - lib/rubigraph.rb
41
+ - test/test_rubigraph.rb
42
+ has_rdoc: true
43
+ homepage: http://rubyforge.org/projects/rubigraph
44
+ licenses:
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: rubigraph
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: a Ruby wrap for Ubigraph (http://www.ubietylab.net/ubigraph)
70
+ test_files:
71
+ - test/test_rubigraph.rb