Class: MotionBlender::GraphMaker
- Inherits:
-
Object
- Object
- MotionBlender::GraphMaker
- Defined in:
- lib/motion_blender/graph_maker.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#output ⇒ Object
Returns the value of attribute output.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(dependencies, opts = {}) ⇒ GraphMaker
constructor
A new instance of GraphMaker.
Constructor Details
#initialize(dependencies, opts = {}) ⇒ GraphMaker
Returns a new instance of GraphMaker.
10 11 12 13 14 15 16 |
# File 'lib/motion_blender/graph_maker.rb', line 10 def initialize dependencies, opts = {} @dependencies = dependencies @title = opts[:title] @filter = opts[:filter] @layout = opts[:layout].try(:to_sym) || :sfdp @output = opts[:output] || 'graph.pdf' end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
7 8 9 |
# File 'lib/motion_blender/graph_maker.rb', line 7 def dependencies @dependencies end |
#filter ⇒ Object
Returns the value of attribute filter.
8 9 10 |
# File 'lib/motion_blender/graph_maker.rb', line 8 def filter @filter end |
#layout ⇒ Object
Returns the value of attribute layout.
8 9 10 |
# File 'lib/motion_blender/graph_maker.rb', line 8 def layout @layout end |
#output ⇒ Object
Returns the value of attribute output.
8 9 10 |
# File 'lib/motion_blender/graph_maker.rb', line 8 def output @output end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/motion_blender/graph_maker.rb', line 8 def title @title end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/motion_blender/graph_maker.rb', line 18 def build g = GraphViz.new(@title || 'Graph', type: :digraph, use: @layout) label = [@title, (@filter && "/#{@filter}/")].compact.join(' ') g[:label] = label if label.present? g[:overlap] = false deps = @dependencies .select { |k, _| acceptable? k } .map { |k, v| [k, v.select { |f| acceptable? f }] } deps.map { |k, v| [k, *v] }.flatten.uniq.reverse_each do |f| g.add_node f, (f) end deps.each do |k, v| v.each { |f| g.add_edge k, f, (k, f) } end g.output(output_format => @output) end |