class GraphViz::Node
Attributes
incidents[R]
List of nodes that are incident to the given node (in a directed graph neighbors == incidents)
neighbors[R]
List of nodes that are directly accessible from given node (in a directed graph neighbors == incidents)
Public Class Methods
new( node_id, parent_graph )
click to toggle source
Create a new node
-
node_id : ID of the node
-
parent_graph : Graph
# File lib/graphviz/node.rb, line 33 def initialize( node_id, parent_graph ) @neighbors = [] @incidents = [] @node_id = node_id @parent_graph = parent_graph @node_attributes = GraphViz::Attrs::new( nil, "node", NODESATTRS ) @index = nil end
Public Instance Methods
<<( node )
click to toggle source
Create an edge between the current node and the node node
# File lib/graphviz/node.rb, line 97 def <<( node ) if( node.class == Array ) node.each do |no| self << no end else return GraphViz::commonGraph( node, self ).add_edges( self, node ) end end
[]( attribute_name )
click to toggle source
Get the value of the node attribute attribute_name
# File lib/graphviz/node.rb, line 67 def []( attribute_name ) if Hash === attribute_name attribute_name.each do |key, value| self[key] = value end return self else (@node_attributes[attribute_name.to_s].nil?)?nil:@node_attributes[attribute_name.to_s].clone end end
[]=( attribute_name, attribute_value )
click to toggle source
Set value attribute_value
to the node attribute
attribute_name
# File lib/graphviz/node.rb, line 61 def []=( attribute_name, attribute_value ) attribute_value = attribute_value.to_s if attribute_value.class == Symbol @node_attributes[attribute_name.to_s] = attribute_value end
each_attribut(global = true, &b)
click to toggle source
# File lib/graphviz/node.rb, line 91 def each_attribut(global = true, &b) warn "`GraphViz::Node#each_attribut` is deprecated, please use `GraphViz::Node#each_attribute`" each_attribute(global, &b) end
each_attribute(global = true) { |k,v| ... }
click to toggle source
Calls block once for each attribute of the node, passing the name and value to the block as a two-element array.
If global is set to false, the block does not receive the attributes set globally
# File lib/graphviz/node.rb, line 82 def each_attribute(global = true, &b) attrs = @node_attributes.to_h if global attrs = pg.node.to_h.merge attrs end attrs.each do |k,v| yield(k,v) end end
id()
click to toggle source
Get the node ID
# File lib/graphviz/node.rb, line 43 def id @node_id.clone end
index()
click to toggle source
Return the node index
# File lib/graphviz/node.rb, line 48 def index @index end
root_graph()
click to toggle source
Return the root graph
# File lib/graphviz/node.rb, line 56 def root_graph return( (self.pg.nil?) ? nil : self.pg.root_graph ) end
set( ) { |self| ... }
click to toggle source
Set node attributes
Example :
n = graph.add_nodes( ... ) ... n.set { |_n| _n.color = "blue" _n.fontcolor = "red" }
# File lib/graphviz/node.rb, line 120 def set( &b ) yield( self ) end