Class: GV::BaseGraph

Inherits:
Component show all
Defined in:
lib/gv.rb

Overview

Common super-class for graphs and sub-graphs

Direct Known Subclasses

Graph, SubGraph

Instance Attribute Summary

Attributes inherited from Component

#graph

Instance Method Summary collapse

Methods inherited from Component

#==, #[], #[]=, #hash, #html, #name

Instance Method Details

#directed?Boolean

Returns whether this graph is directed.

Returns:

  • (Boolean)

    whether this graph is directed



190
191
192
# File 'lib/gv.rb', line 190

def directed?
  Libcgraph.agisdirected(ptr) == 1
end

#edge(name, tail, head, attrs = {}) ⇒ Edge

Creates a new edge to associate with this edge

Parameters:

  • name (String)

    the name (identifier) of the edge

  • tail (Node)

    the edge’s tail node

  • head (Node)

    the edge’s head node

  • attrs (Hash{String, Symbol => Object}) (defaults to: {})

    the attributes

Returns:

  • (Edge)

    the newly created edge

See Also:



172
173
174
# File 'lib/gv.rb', line 172

def edge(name, tail, head, attrs = {})
  component Edge, [name, tail, head], attrs
end

#node(name, attrs = {}) ⇒ Node

Creates a new node to associate with this node

Parameters:

  • name (String)

    the name (identifier) of the node

  • attrs (Hash{String, Symbol => Object}) (defaults to: {})

    the attributes

Returns:

  • (Node)

    the newly created node

See Also:



160
161
162
# File 'lib/gv.rb', line 160

def node(name, attrs = {})
  component Node, [name], attrs
end

#strict?Boolean

Returns whether this graph is strict.

Returns:

  • (Boolean)

    whether this graph is strict



195
196
197
# File 'lib/gv.rb', line 195

def strict?
  Libcgraph.agisstrict(ptr) == 1
end

#sub_graph(name, attrs = {}) {|graph| ... } ⇒ SubGraph

Creates a new sub-graph to associate with this sub-graph

Parameters:

  • name (String)

    the name (identifier) of the sub-graph

  • attrs (Hash{String, Symbol => Object}) (defaults to: {})

    the attributes

Yields:

Returns:

  • (SubGraph)

    the newly created sub-graph

See Also:



182
183
184
185
186
187
# File 'lib/gv.rb', line 182

def sub_graph(name, attrs = {})
  graph = component SubGraph, [name], attrs
  yield graph if block_given?

  graph
end