Class: Graphy::Diagram
- Inherits:
-
Object
- Object
- Graphy::Diagram
- Defined in:
- lib/graphy/diagram.rb
Overview
GraphViz wrapper
Constant Summary collapse
- GRAPH_ATTRIBUTES =
{ ranksep: 0.5, nodesep: 0.4, pad: '0.4,0.4', margin: '0,0', concentrate: true, labelloc: :t, fontsize: 14, fontname: 'Arial BoldMT', splines: 'spline' }
- NODE_ATTRIBUTES =
{ shape: "Mrecord", fontsize: 12, fontname: "ArialMT", margin: "0.07,0.05", penwidth: 1.0 }
- EDGE_ATTRIBUTES =
{ fontname: "ArialMT", fontsize: 10, arrowsize: 0.9, penwidth: 1.0, labelangle: 32, labeldistance: 1.8, }
Instance Attribute Summary collapse
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#graph ⇒ Object
Returns the value of attribute graph.
Instance Method Summary collapse
- #draw_edge(from, to, options) ⇒ Object
- #draw_graph(diagram) ⇒ Object
- #draw_node(name, options = {}) ⇒ Object
- #get_node(name) ⇒ Object
-
#initialize(name, options = {}) ⇒ Diagram
constructor
A new instance of Diagram.
- #node_exists?(name) ⇒ Boolean
- #write(options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Diagram
Returns a new instance of Diagram.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/graphy/diagram.rb', line 35 def initialize(name, = {}) graph_opts = { parent: [:parent], type: [:parent]&.type }.compact @graph = GraphViz.new(name, **graph_opts) GRAPH_ATTRIBUTES.each { |attribute, value| @graph[attribute] = value } NODE_ATTRIBUTES.each { |attribute, value| @graph.node[attribute] = value } EDGE_ATTRIBUTES.each { |attribute, value| @graph.edge[attribute] = value } @graph[:rankdir] = [:orientation] == :horizonal ? :LR : :TB @graph[:label] = "#{name}\\n\\n" @edges = [] end |
Instance Attribute Details
#edges ⇒ Object
Returns the value of attribute edges.
4 5 6 |
# File 'lib/graphy/diagram.rb', line 4 def edges @edges end |
#graph ⇒ Object
Returns the value of attribute graph.
4 5 6 |
# File 'lib/graphy/diagram.rb', line 4 def graph @graph end |
Instance Method Details
#draw_edge(from, to, options) ⇒ Object
63 64 65 |
# File 'lib/graphy/diagram.rb', line 63 def draw_edge(from, to, ) graph.add_edges(from, to, ) end |
#draw_graph(diagram) ⇒ Object
67 68 69 |
# File 'lib/graphy/diagram.rb', line 67 def draw_graph(diagram) graph.add_graph(diagram.graph) end |
#draw_node(name, options = {}) ⇒ Object
59 60 61 |
# File 'lib/graphy/diagram.rb', line 59 def draw_node(name, = {}) graph.add_nodes(name, ) end |
#get_node(name) ⇒ Object
51 52 53 |
# File 'lib/graphy/diagram.rb', line 51 def get_node(name) graph.search_node(name) end |
#node_exists?(name) ⇒ Boolean
55 56 57 |
# File 'lib/graphy/diagram.rb', line 55 def node_exists?(name) !!get_node(name) end |
#write(options = {}) ⇒ Object
71 72 73 |
# File 'lib/graphy/diagram.rb', line 71 def write( = {}) graph.output() end |