Class: GraphViz::Edge

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/graphviz/edge.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(vNodeOne, vNodeTwo, oGParrent = nil) ⇒ Edge

Create a new edge

In:

  • vNodeOne : First node

  • vNodeTwo : Second node

  • oGParrent : Graph



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/graphviz/edge.rb', line 36

def initialize( vNodeOne, vNodeTwo, oGParrent = nil )
 if vNodeOne.class == String
    @xNodeOne = vNodeOne
 else
    @xNodeOne = vNodeOne.name
 end
	  
 if vNodeTwo.class == String
    @xNodeTwo = vNodeTwo
 else
    @xNodeTwo = vNodeTwo.name
 end
 
 @oGParrent = oGParrent

  @oAttrEdge = GraphViz::Attrs::new( nil, "edge", EDGESATTRS )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

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



95
96
97
98
99
# File 'lib/graphviz/edge.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: >, -, >>

:nodoc:



69
70
71
72
73
# File 'lib/graphviz/edge.rb', line 69

def <<( oNode ) #:nodoc:
  n = @oGParrent.get_node(@xNodeTwo)
  
  GraphViz::commonGraph( oNode, n ).add_edge( n, oNode )
end

#[](xAttrName) ⇒ Object

Get the value of the node attribut xAttrName



65
66
67
# File 'lib/graphviz/edge.rb', line 65

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

#[]=(xAttrName, xAttrValue) ⇒ Object

Set value xAttrValue to the edge attribut xAttrName



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

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

#output(oGraphType) ⇒ Object

:nodoc:



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

def output( oGraphType ) #:nodoc:
  xLink = " -> "
  if oGraphType == "graph"
    xLink = " -- "
  end

  #xNodeNameOne = @xNodeOne.clone
  #xNodeNameOne = '"' << xNodeNameOne << '"' if xNodeNameOne.match( /^[a-zA-Z_]+[a-zA-Z0-9_\.]*$/ ).nil?
  xNodeNameOne = GraphViz.escape(@xNodeOne)
  
  #xNodeNameTwo = @xNodeTwo.clone
  #xNodeNameTwo = '"' << xNodeNameTwo << '"' if xNodeNameTwo.match( /^[a-zA-Z_]+[a-zA-Z0-9_\.]*$/ ).nil?
  xNodeNameTwo = GraphViz.escape(@xNodeTwo)
   
   xOut = xNodeNameOne + xLink + xNodeNameTwo
   xAttr = ""
   xSeparator = ""
   @oAttrEdge.data.each do |k, v|
     xAttr << xSeparator + k + " = " + GraphViz.escape(v, true)
     xSeparator = ", "
   end
   if xAttr.length > 0
     xOut << " [" + xAttr + "]"
   end
   xOut + ";"

   return( xOut )
end

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

Set edge attributs

Example :

e = graph.add_edge( ... )
...
e.set { |_e|
  _e.color = "blue"
  _e.fontcolor = "red"
}

Yields:

  • (_self)

Yield Parameters:



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

def set( &b )
  yield( self )
end