Class: Vizier::Graph

Inherits:
SubGraph show all
Defined in:
lib/support/vizier.rb

Constant Summary

Constants included from Support

Support::LEGAL_CHARS

Instance Attribute Summary

Attributes inherited from SubGraph

#links, #name

Instance Method Summary collapse

Methods inherited from SubGraph

#add_link, #add_node, #build, #edge, #graph, #node, #write_comment

Methods included from Support

#attributes, #attributes=, included, #legal?, #quote, #sanitize

Methods inherited from Base

#[], #[]=

Constructor Details

#initialize(name = 'my_graph', attrs = {}) {|_self| ... } ⇒ Graph

Returns a new instance of Graph.

Yields:

  • (_self)

Yield Parameters:

  • _self (Vizier::Graph)

    the object that the method was called on



295
296
297
298
299
# File 'lib/support/vizier.rb', line 295

def initialize(name = 'my_graph', attrs = {})
  @subgraphs = []
  super( name, attrs )
  yield self if block_given?
end

Instance Method Details

#cluster(name = nil, a = {}, &block) ⇒ Object



283
284
285
286
287
288
289
# File 'lib/support/vizier.rb', line 283

def cluster(name = nil, a = {}, &block)
  if name && name = "cluster_#{name}"
    subgraph( name, a, &block )
  else
    clusters
  end
end

#clustersObject



291
292
293
# File 'lib/support/vizier.rb', line 291

def clusters
  @subgraphs.select {|s| s.name =~ /^cluster_/ }.extend( Finder )
end

#comment(str) ⇒ Object



250
251
252
# File 'lib/support/vizier.rb', line 250

def comment( str )
  write_comment( str, 1 )
end

#publish!(a = {}) ⇒ Object



272
273
274
# File 'lib/support/vizier.rb', line 272

def publish!( a = {} )
  generate! # -> png
end

#subgraph(name, a = {}) ⇒ Object



276
277
278
279
280
281
# File 'lib/support/vizier.rb', line 276

def subgraph(name, a = {})
  returning( SubGraph.new(name, a)) do |g|
    @subgraphs << g
    yield g if block_given?
  end
end

#to_strObject Also known as: generate!



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/support/vizier.rb', line 254

def to_str
  build(["digraph #{quote name} {",
         [
          comment("global options"),
          "graph #{graph};",
          "node #{node};",
          "edge #{edge};"
         ],
         comment("nodes"),
         nodes.map(&:to_str),
         comment("links"),
         links.map(&:to_str),
         comment("subgraphs"),
         subgraphs.map(&:to_str),
         "}"])
end