Class: GraphViz::Node

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/graphviz/node.rb

Constant Summary

Constants included from Constants

Constants::EDGESATTRS, Constants::FORMATS, Constants::GENCS_ATTRS, Constants::GRAPHSATTRS, Constants::GRAPHTYPE, Constants::NODESATTRS, Constants::PROGRAMS, Constants::RGV_VERSION

Instance Method Summary collapse

Methods included from Constants

getAttrsFor

Constructor Details

#initialize(xNodeName, oGParrent = nil) ⇒ Node

Create a new node

In:

  • xNodeName : Name of the node

  • oGParrent : Graph



34
35
36
37
38
# File 'lib/graphviz/node.rb', line 34

def initialize( xNodeName, oGParrent = nil )
  @xNodeName = xNodeName
  @oGParrent = oGParrent
  @oAttrNode = GraphViz::Attrs::new( nil, "node", NODESATTRS )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(idName, *args, &block) ⇒ Object

Add node options use node.<option>=<value> or node.<option>( <value> )



95
96
97
98
99
# File 'lib/graphviz/node.rb', line 95

def method_missing( idName, *args, &block ) #:nodoc:
  xName = idName.id2name
  
  self[xName.gsub( /=$/, "" )]=args[0]
end

Instance Method Details

#<<(oNode) ⇒ Object Also known as: >, -, >>

Create an edge between the current node and the node oNode



65
66
67
68
69
70
71
72
73
# File 'lib/graphviz/node.rb', line 65

def <<( oNode )
  if( oNode.class == Array ) 
    oNode.each do |no|
      self << no
    end
  else
    return GraphViz::commonGraph( oNode, self ).add_edge( self, oNode )
  end
end

#[](xAttrName) ⇒ Object

Get the value of the node attribut xAttrName



58
59
60
# File 'lib/graphviz/node.rb', line 58

def []( xAttrName )
  @oAttrNode[xAttrName.to_s].clone
end

#[]=(xAttrName, xAttrValue) ⇒ Object

Set value xAttrValue to the node attribut xAttrName



50
51
52
53
# File 'lib/graphviz/node.rb', line 50

def []=( xAttrName, xAttrValue )
  xAttrValue = xAttrValue.to_s if xAttrValue.class == Symbol
  @oAttrNode[xAttrName.to_s] = xAttrValue
end

#nameObject

Get the node name



43
44
45
# File 'lib/graphviz/node.rb', line 43

def name
  @xNodeName.clone
end

#outputObject

:nodoc:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/graphviz/node.rb', line 105

def output #:nodoc:
  #xNodeName = @xNodeName.clone
  #xNodeName = '"' << xNodeName << '"' if xNodeName.match( /^[a-zA-Z_]+[a-zA-Z0-9_\.]*$/ ).nil?
  xNodeName = GraphViz.escape(@xNodeName)
  
  xOut = "" << xNodeName
  xAttr = ""
  xSeparator = ""
  @oAttrNode.data.each do |k, v|
   if k == "html"
    xAttr << xSeparator + "label = <" + v + ">"
  else
      xAttr << xSeparator + k + " = " + GraphViz.escape(v, true)
  end
    xSeparator = ", "
  end
  if xAttr.length > 0
    xOut << " [" + xAttr + "]"
  end
  xOut << ";"

  return( xOut )
end

#pgObject

:nodoc:



101
102
103
# File 'lib/graphviz/node.rb', line 101

def pg #:nodoc:
  @oGParrent
end

#set {|_self| ... } ⇒ Object

Set node attributs

Example :

n = graph.add_node( ... )
...
n.set { |_n|
  _n.color = "blue"
  _n.fontcolor = "red"
}

Yields:

  • (_self)

Yield Parameters:



89
90
91
# File 'lib/graphviz/node.rb', line 89

def set( &b )
  yield( self )
end