Class: Dogviz::GraphvizRenderer
- Inherits:
-
Object
- Object
- Dogviz::GraphvizRenderer
- Defined in:
- lib/dogviz/graphviz_renderer.rb
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
Instance Method Summary collapse
-
#initialize(title, hints) ⇒ GraphvizRenderer
constructor
A new instance of GraphvizRenderer.
- #render_edge(from, other, options) ⇒ Object
- #render_node(parent, id, attributes) ⇒ Object
- #render_subgraph(parent, id, attributes) ⇒ Object
Constructor Details
#initialize(title, hints) ⇒ GraphvizRenderer
Returns a new instance of GraphvizRenderer.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dogviz/graphviz_renderer.rb', line 8 def initialize(title, hints) construction_hints = {} after_hints = hints.clone if hints.has_key?(:use) construction_hints[:use] = hints[:use] after_hints.delete :use end @graph = GraphViz.digraph(title, construction_hints) @graph[after_hints] @subgraphs = {} @nodes = {} @rendered_subgraph_ids = {} end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
6 7 8 |
# File 'lib/dogviz/graphviz_renderer.rb', line 6 def graph @graph end |
Instance Method Details
#render_edge(from, other, options) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/dogviz/graphviz_renderer.rb', line 22 def render_edge(from, other, ) edge = graph.add_edges from.id, other.id .each { |key, value| edge[key] = value unless value.nil? } edge end |
#render_node(parent, id, attributes) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/dogviz/graphviz_renderer.rb', line 30 def render_node(parent, id, attributes) clean_node_attributes attributes default_attributes = {:shape => 'box', :style => ''} merged_attributes = default_attributes.merge(attributes) parent_node(parent).add_nodes(id, merged_attributes) end |
#render_subgraph(parent, id, attributes) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dogviz/graphviz_renderer.rb', line 37 def render_subgraph(parent, id, attributes) if (attributes[:bounded] == true) then rendered_id = 'cluster_' + id else rendered_id = id end @rendered_subgraph_ids[id] = rendered_id subgraph = parent_node(parent).add_graph(rendered_id, clean_subgraph_attributes(attributes.clone)) @subgraphs[id] = subgraph subgraph end |