Class: Graphviz::Graph
- Inherits:
-
Object
- Object
- Graphviz::Graph
- Defined in:
- lib/graphviz/graph.rb
Overview
Contains a set of nodes, edges and subgraphs.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
Any associated graphviz attributes.
-
#edges ⇒ Array<Edge>
readonly
All edges in the graph.
-
#graphs ⇒ Array<Graph>
readonly
Any subgraphs.
-
#nodes ⇒ Array<Node>
readonly
All nodes in the graph.
-
#parent ⇒ Graph
readonly
The parent graph, if any.
Instance Method Summary collapse
-
#add_node(name, attributes = {}) ⇒ Node
Add a node to this graph.
-
#add_subgraph(name, attributes = {}) ⇒ Graph
Add a subgraph with a given name and attributes.
-
#attach(parent) ⇒ Object
Make this graph a subgraph of the parent.
-
#initialize(name = 'G', attributes = {}) ⇒ Graph
constructor
Initialize the graph with the specified unique name.
-
#to_dot(options = {}) ⇒ String
Output the graph using the dot format.
Constructor Details
#initialize(name = 'G', attributes = {}) ⇒ Graph
Initialize the graph with the specified unique name.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/graphviz/graph.rb', line 105 def initialize(name = 'G', attributes = {}) @name = name @nodes = {} @edges = [] @graphs = {} @parent = nil @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Hash
Returns Any associated graphviz attributes.
130 131 132 |
# File 'lib/graphviz/graph.rb', line 130 def attributes @attributes end |
#edges ⇒ Array<Edge> (readonly)
Returns All edges in the graph.
124 125 126 |
# File 'lib/graphviz/graph.rb', line 124 def edges @edges end |
#graphs ⇒ Array<Graph> (readonly)
Returns Any subgraphs.
127 128 129 |
# File 'lib/graphviz/graph.rb', line 127 def graphs @graphs end |
#nodes ⇒ Array<Node> (readonly)
Returns All nodes in the graph.
121 122 123 |
# File 'lib/graphviz/graph.rb', line 121 def nodes @nodes end |
#parent ⇒ Graph (readonly)
Returns The parent graph, if any.
118 119 120 |
# File 'lib/graphviz/graph.rb', line 118 def parent @parent end |
Instance Method Details
#add_node(name, attributes = {}) ⇒ Node
Returns Add a node to this graph.
133 134 135 |
# File 'lib/graphviz/graph.rb', line 133 def add_node(name, attributes = {}) Node.new(self, name, attributes) end |
#add_subgraph(name, attributes = {}) ⇒ Graph
Add a subgraph with a given name and attributes.
139 140 141 142 143 144 145 146 |
# File 'lib/graphviz/graph.rb', line 139 def add_subgraph(name, attributes = {}) graph = Graph.new(name, attributes) graph.attach(self) @graphs[name] = graph return graph end |
#attach(parent) ⇒ Object
Make this graph a subgraph of the parent.
149 150 151 |
# File 'lib/graphviz/graph.rb', line 149 def attach(parent) @parent = parent end |
#to_dot(options = {}) ⇒ String
Returns Output the graph using the dot format.
154 155 156 157 158 159 160 |
# File 'lib/graphviz/graph.rb', line 154 def to_dot( = {}) buffer = StringIO.new dump_graph(buffer, "", ) return buffer.string end |