lib/gv.rb in gv-0.0.2 vs lib/gv.rb in gv-0.0.3
- old
+ new
@@ -49,22 +49,30 @@
attach_function :agtail, [:ag_edge], :ag_node
attach_function :aghead, [:ag_edge], :ag_node
attach_function :agget, [:pointer, :string], :string
attach_function :agsafeset, [:pointer, :string, :string, :string], :pointer
- attach_function :agstrdup_html, [:pointer, :string], :string
- attach_function :agstrfree, [:pointer, :string], :int
+ attach_function :agstrdup_html, [AGraph.by_ref, :string], :pointer
+ attach_function :agstrfree, [AGraph.by_ref, :pointer], :int
attach_function :agisdirected, [AGraph.by_ref], :int
attach_function :agisstrict, [AGraph.by_ref], :int
end
class Component
@@gvc = FFI.gvContext()
attr_reader :graph
+ def html(string)
+ ptr = FFI.agstrdup_html(graph.ptr, string)
+ string = ptr.read_string
+ FFI.agstrfree graph.ptr, ptr
+
+ string
+ end
+
def hash
ptr.hash
end
def ==(other)
@@ -125,11 +133,11 @@
def edge(name, tail, head, attrs = {})
component Edge, [name, tail, head], attrs
end
- def graph(name, attrs = {})
+ def sub_graph(name, attrs = {})
graph = component SubGraph, [name], attrs
yield graph if block_given?
graph
end
@@ -195,9 +203,13 @@
end
end
def initialize(ptr)
@ptr = ptr
+ end
+
+ def graph
+ self
end
def write(filename, format = 'png', layout = 'dot')
FFI.gvLayout(@@gvc, ptr, layout.to_s)
FFI.gvRenderFilename(@@gvc, ptr, format.to_s, filename);