Module: RDG::RGL::AllowDuplicates

Included in:
Graph::BidirectedAdjacencyGraph
Defined in:
lib/rdg/graph/rgl/allow_duplicates.rb

Instance Method Summary collapse

Instance Method Details

#to_dot_graph(params = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rdg/graph/rgl/allow_duplicates.rb', line 13

def to_dot_graph(params = {})
  params['name'] ||= self.class.name.gsub(/:/, '_')
  fontsize       = params['fontsize'] ? params['fontsize'] : '8'
  graph          = (directed? ? ::RGL::DOT::Digraph : ::RGL::DOT::Graph).new(params)
  edge_class     = directed? ? ::RGL::DOT::DirectedEdge : ::RGL::DOT::Edge

  each_vertex do |v|
    graph << ::RGL::DOT::Node.new(
        'name'     => v.object_id,
        'fontsize' => fontsize,
        'label'    => vertex_label(v)
    )
  end

  each_edge do |u, v|
    graph << edge_class.new(
        'from'     => u.object_id,
        'to'       => v.object_id,
        'fontsize' => fontsize
    )
  end

  graph
end

#vertex_label(v) ⇒ Object

Returns a label for vertex v. Default is v.to_s



39
40
41
# File 'lib/rdg/graph/rgl/allow_duplicates.rb', line 39

def vertex_label(v)
  v.to_s
end