Class: RGL::DOT::Graph

### Home Classes Methods

### In Files

- lib/rgl/rdot.rb

### Parent

RGL::DOT::Element

### Methods

- ::new
- #<<
- #each_element
- #pop
- #push
- #to_s

### Class/Module Index

Quicksearch

- RGL
- RGL::AdjacencyGraph
- RGL::BFSIterator
- RGL::BellmanFordAlgorithm
- RGL::BellmanFordVisitor
- RGL::BidirectionalGraph
- RGL::BipartiteBFSIterator
- RGL::DFSIterator
- RGL::DFSVisitor
- RGL::DOT
- RGL::DOT::Digraph
- RGL::DOT::DirectedEdge
- RGL::DOT::Edge
- RGL::DOT::Element
- RGL::DOT::Graph
- RGL::DOT::Node
- RGL::DOT::Port
- RGL::DOT::Subgraph
- RGL::DijkstraAlgorithm
- RGL::DijkstraVisitor
- RGL::DirectedAdjacencyGraph
- RGL::Edge
- RGL::Edge::DirectedEdge
- RGL::Edge::UnDirectedEdge
- RGL::EdgePropertiesMap
- RGL::EdmondsKarpAlgorithm
- RGL::EdmondsKarpAlgorithm::EdmondsKarpBFSIterator
- RGL::Graph
- RGL::Graph::TarjanSccVisitor
- RGL::GraphIterator
- RGL::GraphVisitor
- RGL::GraphVisitor::ClassMethods
- RGL::GraphVisitor::DistanceMapSupport
- RGL::ImplicitGraph
- RGL::MutableGraph
- RGL::MutableGraph::MutableGraphParser
- RGL::NoEdgeError
- RGL::NoVertexError
- RGL::NonNegativeEdgePropertiesMap
- RGL::NotDirectedError
- RGL::NotUndirectedError
- RGL::PrimAlgorithm
- RGL::TopsortIterator
- Enumerable
- Object

No matching classes.

# RGL::DOT::Graph

A graph representation. Whether or not it is rendered as directed or undirected depends on which of the programs dot or neato is used to process and render the graph.

### Public Class Methods

new(params = {}, option_list = GRAPH_OPTS) click to toggle source

Creates a new Graph with the params Hash providing settings for all graph options. The option_list parameter restricts those options to the list of valid names it contains. The exception to this is the elements option which, if specified, must be an Enumerable containing a list of nodes, edges, and/or subgraphs.

    # File lib/rgl/rdot.rb, line 309
    def initialize(params = {}, option_list = GRAPH_OPTS)
      super(params, option_list)
      @elements   = params['elements'] ? params['elements'] : []
      @dot_string = 'graph'
    end

### Public Instance Methods

graph << element → graph click to toggle source

Adds a new node, edge, or subgraph to this graph.

    # File lib/rgl/rdot.rb, line 331
    def << (element)
      @elements << element
      self
    end

Also aliased as: push
each_element {|element| block} → graph click to toggle source

Calls block once for each node, edge, or subgraph contained by this graph, passing the node, edge, or subgraph to the block.

    # File lib/rgl/rdot.rb, line 321
    def each_element(&block)
      @elements.each(&block)
      self
    end

pop → element click to toggle source

Removes the most recently added node, edge, or subgraph from this graph and returns it.

    # File lib/rgl/rdot.rb, line 344
    def pop
      @elements.pop
    end

push(element) click to toggle source
Alias for: <<
to_s(leader = '', indent = ' ') click to toggle source

Returns a string representation of this graph which is consumable by the graphviz tools `dot` and `neato`. The leader parameter is used to indent every line of the returned string, and the indent parameter is used to additionally indent nested items.

    # File lib/rgl/rdot.rb, line 353
    def to_s(leader = '', indent = '    ')
      hdr = leader + @dot_string + (@name.nil? ? '' : ' ' + quote_ID(@name)) + " {\n"

      options = @options.to_a.collect do |name, val|
        unless val.nil?
          if name == 'label'
            leader + indent + "#{quote_ID(name)} = #{quote_label(val)}"
          else
            leader + indent + "#{quote_ID(name)} = #{quote_ID(val)}"
          end
        end
      end.compact.join("\n")

      elements = @elements.collect do |element|
        element.to_s(leader + indent, indent)
      end.join("\n\n")

      hdr + (options.empty? ? '' : options + "\n\n") +
          (elements.empty? ? '' : elements + "\n") + leader + "}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.