Class: GV::Graph
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseGraph
#directed?, #edge, #node, #strict?, #sub_graph
Methods inherited from Component
#==, #[], #[]=, #hash, #html, #name
Constructor Details
#initialize(ptr) ⇒ Graph
Returns a new instance of Graph.
206
207
208
|
# File 'lib/gv.rb', line 206
def initialize(ptr)
@ptr = ptr
end
|
Class Method Details
.load(io) ⇒ Object
196
197
198
199
200
201
202
203
|
# File 'lib/gv.rb', line 196
def load(io)
data = if io.is_a? String
io
else
io.read
end
new FFI.agmemread(data)
end
|
.open(name, type = :directed, strict = :normal) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/gv.rb', line 177
def open(name, type = :directed, strict = :normal)
ag_type = case [type, strict]
when [:directed, :normal] then FFI.Agdirected
when [:undirected, :normal] then FFI.Agundirected
when [:directed, :strict] then FFI.Agstrictdirected
when [:undirected, :strict] then FFI.Agstrictundirected
else
raise ArgumentError, "invalid graph type #{[type, strict]}"
end
graph = new(FFI.agopen(name, ag_type, ::FFI::Pointer::NULL))
if block_given?
yield graph
end
graph
end
|
Instance Method Details
#graph ⇒ Object
210
211
212
|
# File 'lib/gv.rb', line 210
def graph
self
end
|
#render(format = 'png', layout = 'dot') ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/gv.rb', line 220
def render(format = 'png', layout = 'dot')
FFI.gvLayout(@@gvc, ptr, layout.to_s)
data_ptr = ::FFI::MemoryPointer.new(:pointer, 1)
len_ptr = ::FFI::MemoryPointer.new(:int, 1)
FFI.gvRenderData(@@gvc, ptr, format.to_s, data_ptr, len_ptr);
len = len_ptr.read_uint
data_ptr = data_ptr.read_pointer
data = data_ptr.read_string_length len
FFI.gvFreeRenderData(data_ptr)
FFI.gvFreeLayout(@@gvc, ptr)
data
end
|
#write(filename, format = 'png', layout = 'dot') ⇒ Object
214
215
216
217
218
|
# File 'lib/gv.rb', line 214
def write(filename, format = 'png', layout = 'dot')
FFI.gvLayout(@@gvc, ptr, layout.to_s)
FFI.gvRenderFilename(@@gvc, ptr, format.to_s, filename);
FFI.gvFreeLayout(@@gvc, ptr)
end
|