Method: RGL::Graph#to_dot_graph
- Defined in:
- lib/rgl/dot.rb
#to_dot_graph(params = {}) ⇒ Object
Return a DOT::Digraph for directed graphs or a DOT::Graph for an undirected RGL::Graph. params can contain any graph property specified in rdot.rb.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rgl/dot.rb', line 48 def to_dot_graph(params = {}) params['name'] ||= self.class.name.gsub(/:/, '_') 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' => vertex_id(v), 'fontsize' => fontsize, 'label' => vertex_label(v) } = if && [v] RGL::DOT::NODE_OPTS.each do |opt| if [v].key?(:"#{opt}") ["#{opt}"] = [v].fetch(:"#{opt}") end end end graph << DOT::Node.new() end edges.each do |edge| = { 'from' => edge.source, 'to' => edge.target, 'fontsize' => fontsize } = if && [edge] RGL::DOT::EDGE_OPTS.each do |opt| if [edge].key?(:"#{opt}") ["#{opt}"] = [edge].fetch(:"#{opt}") end end end graph << edge_class.new() end graph end |