Class: AasmStatechart::Renderer
- Inherits:
-
Object
- Object
- AasmStatechart::Renderer
- Defined in:
- lib/aasm_statechart.rb
Constant Summary collapse
- FORMATS =
GraphViz::Constants::FORMATS
- GRAPH_STYLE =
{ rankdir: :TB, }
- NODE_STYLE =
{ shape: :Mrecord, fontname: 'Arial', fontsize: 10, penwidth: 0.7, }
- EDGE_STYLE =
{ dir: :forward, fontname: 'Arial', fontsize: 9, penwidth: 0.7, }
- START_NODE_STYLE =
{ shape: :circle, label: '', style: :filled, color: 'black', fillcolor: 'black', fixedsize: true, width: 0.25, height: 0.25, }
- END_NODE_STYLE =
{ shape: :doublecircle, label: '', style: :filled, color: 'black', fillcolor: 'black', fixedsize: true, width: 0.20, height: 0.20, }
- ENTER_CALLBACKS =
[:before_enter, :enter, :after_enter, :after_commit]
- EXIT_CALLBACKS =
[:before_exit, :exit, :after_exit]
- TRANSITION_CALLBACKS =
[:before, :on_transition, :after]
Instance Method Summary collapse
-
#initialize(klass) ⇒ Renderer
constructor
A new instance of Renderer.
- #save(filename, format: 'png') ⇒ Object
Constructor Details
#initialize(klass) ⇒ Renderer
Returns a new instance of Renderer.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/aasm_statechart.rb', line 56 def initialize(klass) @start_node = nil @end_node = nil @graph = GraphViz.new(:statechart) @graph.type = 'digraph' # ruby-graphviz is missing an API to set styles in bulk, so set them here GRAPH_STYLE.each { |k, v| @graph.graph[k] = v } NODE_STYLE.each { |k, v| @graph.node[k] = v } EDGE_STYLE.each { |k, v| @graph.edge[k] = v } klass.aasm.states.each { |state| render_state(state) } klass.aasm.events.each { |name, event| render_event(name, event) } end |
Instance Method Details
#save(filename, format: 'png') ⇒ Object
72 73 74 |
# File 'lib/aasm_statechart.rb', line 72 def save(filename, format: 'png') @graph.output({format => filename}) end |