Class: GraphViz::Edge
- Inherits:
-
Object
- Object
- GraphViz::Edge
- 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
-
#<<(oNode) ⇒ Object
(also: #>, #-, #>>)
:nodoc:.
-
#[](xAttrName) ⇒ Object
Set values for edge attributs or get the value of the given edge attribut
xAttrName. -
#[]=(xAttrName, xAttrValue) ⇒ Object
Set value
xAttrValueto the edge attributxAttrName. -
#each_attribut(global = true, &b) ⇒ Object
Calls block once for each attribut of the edge, passing the name and value to the block as a two-element array.
-
#index ⇒ Object
Return the index of the edge.
-
#index=(i) ⇒ Object
:nodoc:.
-
#initialize(vNodeOne, vNodeTwo, oGParrent) ⇒ Edge
constructor
Create a new edge.
-
#method_missing(idName, *args, &block) ⇒ Object
Add edge options use edge.<option>=<value> or edge.<option>( <value> ).
-
#node_one(with_port = true) ⇒ Object
(also: #tail_node)
Return the node one as string (so with port if any).
-
#node_two(with_port = true) ⇒ Object
(also: #head_node)
Return the node two as string (so with port if any).
-
#output(oGraphType) ⇒ Object
:nodoc:.
-
#pg ⇒ Object
:nodoc:.
-
#root_graph ⇒ Object
Return the root graph.
-
#set {|_self| ... } ⇒ Object
Set edge attributs.
Methods included from Constants
Constructor Details
#initialize(vNodeOne, vNodeTwo, oGParrent) ⇒ Edge
Create a new edge
In:
-
vNodeOne : First node (can be a GraphViz::Node or a node ID)
-
vNodeTwo : Second node (can be a GraphViz::Node or a node ID)
-
oGParrent : Graph
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/graphviz/edge.rb', line 38 def initialize( vNodeOne, vNodeTwo, oGParrent ) @xNodeOne, @xNodeOnePort = getNodeNameAndPort( vNodeOne ) # if vNodeOne.class == String # @xNodeOne = vNodeOne # else # @xNodeOne = vNodeOne.id # end @xNodeTwo, @xNodeTwoPort = getNodeNameAndPort( vNodeTwo ) # if vNodeTwo.class == String # @xNodeTwo = vNodeTwo # else # @xNodeTwo = vNodeTwo.id # end @oGParrent = oGParrent @oAttrEdge = GraphViz::Attrs::new( nil, "edge", EDGESATTRS ) @index = nil 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> )
168 169 170 171 172 173 |
# File 'lib/graphviz/edge.rb', line 168 def method_missing( idName, *args, &block ) #:nodoc: return if idName == :to_ary # ruby 1.9.2 fix xName = idName.id2name self[xName.gsub( /=$/, "" )]=args[0] end |
Instance Method Details
#<<(oNode) ⇒ Object Also known as: >, -, >>
:nodoc:
131 132 133 134 135 |
# File 'lib/graphviz/edge.rb', line 131 def <<( oNode ) #:nodoc: n = @oGParrent.get_node(@xNodeTwo) GraphViz::commonGraph( oNode, n ).add_edge( n, oNode ) end |
#[](xAttrName) ⇒ Object
Set values for edge attributs or get the value of the given edge attribut xAttrName
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/graphviz/edge.rb', line 100 def []( xAttrName ) # Modification by axgle (http://github.com/axgle) if Hash === xAttrName xAttrName.each do |key, value| self[key] = value end else if @oAttrEdge[xAttrName.to_s] @oAttrEdge[xAttrName.to_s].clone else nil end end end |
#[]=(xAttrName, xAttrValue) ⇒ Object
Set value xAttrValue to the edge attribut xAttrName
91 92 93 94 |
# File 'lib/graphviz/edge.rb', line 91 def []=( xAttrName, xAttrValue ) xAttrValue = xAttrValue.to_s if xAttrValue.class == Symbol @oAttrEdge[xAttrName.to_s] = xAttrValue end |
#each_attribut(global = true, &b) ⇒ Object
Calls block once for each attribut of the edge, 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 attributs set globally
121 122 123 124 125 126 127 128 129 |
# File 'lib/graphviz/edge.rb', line 121 def each_attribut(global = true, &b) attrs = @oAttrEdge.to_h if global attrs = pg.edge.to_h.merge attrs end attrs.each do |k,v| yield(k,v) end end |
#index ⇒ Object
Return the index of the edge
81 82 83 |
# File 'lib/graphviz/edge.rb', line 81 def index @index end |
#index=(i) ⇒ Object
:nodoc:
84 85 86 |
# File 'lib/graphviz/edge.rb', line 84 def index=(i) #:nodoc: @index = i if @index == nil end |
#node_one(with_port = true) ⇒ Object Also known as: tail_node
Return the node one as string (so with port if any)
60 61 62 63 64 65 66 |
# File 'lib/graphviz/edge.rb', line 60 def node_one( with_port = true ) if @xNodeOnePort.nil? or with_port == false GraphViz.escape(@xNodeOne) else GraphViz.escape(@xNodeOne, :force => true) + ":#{@xNodeOnePort}" end end |
#node_two(with_port = true) ⇒ Object Also known as: head_node
Return the node two as string (so with port if any)
70 71 72 73 74 75 76 |
# File 'lib/graphviz/edge.rb', line 70 def node_two( with_port = true ) if @xNodeTwoPort.nil? or with_port == false GraphViz.escape(@xNodeTwo) else GraphViz.escape(@xNodeTwo, :force => true) + ":#{@xNodeTwoPort}" end end |
#output(oGraphType) ⇒ Object
:nodoc:
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/graphviz/edge.rb', line 175 def output( oGraphType ) #:nodoc: xLink = " -> " if oGraphType == "graph" xLink = " -- " end xOut = self.node_one + xLink + self.node_two xAttr = "" xSeparator = "" @oAttrEdge.data.each do |k, v| xAttr << xSeparator + k + " = " + v.to_gv xSeparator = ", " end if xAttr.length > 0 xOut << " [" + xAttr + "]" end xOut + ";" return( xOut ) end |
#pg ⇒ Object
:nodoc:
147 148 149 |
# File 'lib/graphviz/edge.rb', line 147 def pg #:nodoc: @oGParrent end |
#root_graph ⇒ Object
Return the root graph
143 144 145 |
# File 'lib/graphviz/edge.rb', line 143 def root_graph return( (self.pg.nil?) ? nil : self.pg.root_graph ) end |
#set {|_self| ... } ⇒ Object
Set edge attributs
Example :
e = graph.add_edge( ... )
...
e.set { |_e|
_e.color = "blue"
_e.fontcolor = "red"
}
162 163 164 |
# File 'lib/graphviz/edge.rb', line 162 def set( &b ) yield( self ) end |