class GraphViz::Edge
Public Class Methods
new( vNodeOne, vNodeTwo, parent_graph )
click to toggle source
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)
-
parent_graph : Graph
# File lib/graphviz/edge.rb, line 30 def initialize( vNodeOne, vNodeTwo, parent_graph ) @node_one_id, @node_one_port = getNodeNameAndPort( vNodeOne ) @node_two_id, @node_two_port = getNodeNameAndPort( vNodeTwo ) @parent_graph = parent_graph @edge_attributes = GraphViz::Attrs::new( nil, "edge", EDGESATTRS ) @index = nil unless @parent_graph.directed? (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).incidents << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)) (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).neighbors << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)) end (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)).neighbors << (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)) (@parent_graph.find_node(@node_two_id) || @parent_graph.add_nodes(@node_two_id)).incidents << (@parent_graph.find_node(@node_one_id) || @parent_graph.add_nodes(@node_one_id)) end
Public Instance Methods
[]( attribute_name )
click to toggle source
Set values for edge attributes or get the value of the given edge attribute
attribute_name
# File lib/graphviz/edge.rb, line 82 def []( attribute_name ) # Modification by axgle (http://github.com/axgle) if Hash === attribute_name attribute_name.each do |key, value| self[key] = value end else if @edge_attributes[attribute_name.to_s] @edge_attributes[attribute_name.to_s].clone else nil end end end
[]=( attribute_name, attribute_value )
click to toggle source
Set value attribute_value
to the edge attribute
attribute_name
# File lib/graphviz/edge.rb, line 75 def []=( attribute_name, attribute_value ) attribute_value = attribute_value.to_s if attribute_value.class == Symbol @edge_attributes[attribute_name.to_s] = attribute_value end
each_attribut(global = true, &b)
click to toggle source
# File lib/graphviz/edge.rb, line 112 def each_attribut(global = true, &b) warn "`GraphViz::Edge#each_attribut` is deprecated, please use `GraphViz::Edge#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 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 attributes set globally
# File lib/graphviz/edge.rb, line 103 def each_attribute(global = true, &b) attrs = @edge_attributes.to_h if global attrs = pg.edge.to_h.merge attrs end attrs.each do |k,v| yield(k,v) end end
index()
click to toggle source
Return the index of the edge
# File lib/graphviz/edge.rb, line 67 def index @index end
node_one(with_port = true, escaped = true)
click to toggle source
Return the node one as string (so with port if any)
# File lib/graphviz/edge.rb, line 47 def node_one(with_port = true, escaped = true) if not(@node_one_port and with_port) escaped ? GraphViz.escape(@node_one_id) : @node_one_id else escaped ? GraphViz.escape(@node_one_id, :force => true) + ":#{@node_one_port}" : "#{@node_one_id}:#{@node_one_port}" end end
Also aliased as: tail_node
node_two(with_port = true, escaped = true)
click to toggle source
Return the node two as string (so with port if any)
# File lib/graphviz/edge.rb, line 57 def node_two(with_port = true, escaped = true) if not(@node_two_port and with_port) escaped ? GraphViz.escape(@node_two_id) : @node_two_id else escaped ? GraphViz.escape(@node_two_id, :force => true) + ":#{@node_two_port}" : "#{@node_two_id}:#{@node_two_port}" end end
Also aliased as: head_node
root_graph()
click to toggle source
Return the root graph
# File lib/graphviz/edge.rb, line 129 def root_graph return( (self.pg.nil?) ? nil : self.pg.root_graph ) end
set( ) { |self| ... }
click to toggle source
Set edge attributes
Example :
e = graph.add_edges( ... ) ... e.set { |_e| _e.color = "blue" _e.fontcolor = "red" }
# File lib/graphviz/edge.rb, line 146 def set( &b ) yield( self ) end
Private Instance Methods
getNodeNameAndPort( node )
click to toggle source
# File lib/graphviz/edge.rb, line 186 def getNodeNameAndPort( node ) name, port = nil, nil if node.class == Hash node.each do |k, v| name, port = getNodeNameAndPort(k) port = v end elsif node.class == String name = node else name = node.id end return name, port end