class GraphViz::MindMap::Node
Attributes
name[RW]
nodes[RW]
options[RW]
parent[RW]
pass_on_options[RW]
used_identifiers[RW]
Public Class Methods
new(*args)
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 12 def initialize *args @options = args.last.is_a?(Hash) ? args.pop : {} @name = args.first @nodes = [] @used_identifiers = [] @pass_on_options = false raise ArgumentError.new("You need to name this mind map") unless name end
Public Instance Methods
at(dot_path)
click to toggle source
tree walking things
# File lib/graph_viz/mind_map/node.rb, line 39 def at(dot_path) path = dot_path.split(/\./) if path.any? index = path.shift.to_i nodes[index].at(path.join('.')) else self end end
build_dot_at_index(o, idx)
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 116 def build_dot_at_index(o, idx) leader = " "*(idx * 2) o << "#{leader}#{node_def}" if parent && idx > 1 o << "#{leader}#{parent.dot_identifier} -- #{dot_identifier}" end if nodes.any? o << "#{leader}subgraph sg_#{dot_identifier} {" nodes.each do |node| node.to_dot(o, idx + 1) end o << "#{leader}}" end end
build_dot_from_root()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 102 def build_dot_from_root o = [] o << "graph #{dot_identifier} {" opts = dot_options if opts.length > 0 o << " graph #{dot_options}" end nodes.each do |node| node.to_dot(o, 1) end o << "}" o.join("\n") end
dot_identifier()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 65 def dot_identifier @dot_identifier ||= make_dot_identifier end
dot_options()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 78 def dot_options o=[] unless parent.nil? o << "label=\"#{name}\"" end options.each_pair do |k,v| o << "#{k}=\"#{v}\"" end if o.any? "[#{o.join(' ')}]" else '' end end
inherit!()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 21 def inherit!; @pass_on_options = true end
make_dot_identifier()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 69 def make_dot_identifier id = name.downcase.gsub(/[^ a-z]/,'').sub(/ +$/,'').gsub(/ +/,'_') if root.used_identifiers.include? id id = "#{parent.dot_identifier}_#{id}" end root.used_identifiers << id id end
no_inherit!()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 22 def no_inherit!; @pass_on_options = false end
node(*args, &block)
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 24 def node(*args, &block) @nodes << Node.new(*args).tap do |n| n.parent = self if @pass_on_options n.options = options.dup.merge(n.options) n.pass_on_options = true end end if block_given? @nodes.last.instance_eval &block end end
node_def()
click to toggle source
dot generation things
# File lib/graph_viz/mind_map/node.rb, line 55 def node_def opts = dot_options o = [dot_identifier] if opts.length > 0 o << ' ' o << opts end o.join end
root()
click to toggle source
# File lib/graph_viz/mind_map/node.rb, line 49 def root parent ? parent.root : self end
to_dot(output=nil, indent=0)
click to toggle source
assumes the node you call to_dot
on is the root of the graph and should be treated like a graph
# File lib/graph_viz/mind_map/node.rb, line 94 def to_dot(output=nil, indent=0) if indent == 0 build_dot_from_root else build_dot_at_index(output,indent) end end