lib/rgl/dot.rb in rgl-0.5.0 vs lib/rgl/dot.rb in rgl-0.5.1
- old
+ new
@@ -10,10 +10,15 @@
module RGL
module Graph
+ # Returns a label for vertex v. Default is v.to_s
+ def vertex_label(v)
+ v.to_s
+ end
+
# Return a RGL::DOT::Digraph for directed graphs or a DOT::Graph for an
# undirected Graph. _params_ can contain any graph property specified in
# rdot.rb.
#
def to_dot_graph(params = {})
@@ -21,21 +26,20 @@
fontsize = params['fontsize'] ? params['fontsize'] : '8'
graph = (directed? ? DOT::Digraph : DOT::Graph).new(params)
edge_class = directed? ? DOT::DirectedEdge : DOT::Edge
each_vertex do |v|
- name = v.to_s
graph << DOT::Node.new(
- 'name' => name,
+ 'name' => v.object_id,
'fontsize' => fontsize,
- 'label' => name
+ 'label' => vertex_label(v)
)
end
each_edge do |u, v|
graph << edge_class.new(
- 'from' => u.to_s,
- 'to' => v.to_s,
+ 'from' => u.object_id,
+ 'to' => v.object_id,
'fontsize' => fontsize
)
end
graph