class Graphy::Diagram
GraphViz wrapper
Constants
- EDGE_ATTRIBUTES
- GRAPH_ATTRIBUTES
- NODE_ATTRIBUTES
Attributes
edges[RW]
graph[RW]
Public Class Methods
new(name, options = {})
click to toggle source
# File lib/graphy/diagram.rb, line 35 def initialize(name, options = {}) graph_opts = { parent: options[:parent], type: options[: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] = options[:orientation] == :horizonal ? :LR : :TB @graph[:label] = "#{name}\\n\\n" @edges = [] end
Public Instance Methods
draw_edge(from, to, options)
click to toggle source
# File lib/graphy/diagram.rb, line 63 def draw_edge(from, to, options) graph.add_edges(from, to, options) end
draw_graph(diagram)
click to toggle source
# File lib/graphy/diagram.rb, line 67 def draw_graph(diagram) graph.add_graph(diagram.graph) end
draw_node(name, options = {})
click to toggle source
# File lib/graphy/diagram.rb, line 59 def draw_node(name, options = {}) graph.add_nodes(name, options) end
get_node(name)
click to toggle source
# File lib/graphy/diagram.rb, line 51 def get_node(name) graph.search_node(name) end
node_exists?(name)
click to toggle source
# File lib/graphy/diagram.rb, line 55 def node_exists?(name) !!get_node(name) end
write(options = {})
click to toggle source
# File lib/graphy/diagram.rb, line 71 def write(options = {}) graph.output(options) end