我正在制作一个可以在过渡系统上执行一些操作并且还需要可视化它们的工具。
虽然没有太多关于 ruby-gem 的文档(这是我能得到的最好的:http ://www.omninerd.com/articles/Automating_Data_Visualization_with_Ruby_and_Graphviz ),但我设法从我的转换系统制作了一个图表。(随意使用它,周围没有太多示例代码。也欢迎评论/提问)
# note: model is something of my own datatype,
# having states, labels, transitions, start_state and a name
# I hope the code is self-explaining
@graph = GraphViz::new(model.name, "type" => "graph" )
#settings
@graph.edge[:dir] = "forward"
@graph.edge[:arrowsize]= "0.5"
#make the graph
model.states.each do |cur_state|
@graph.add_node(cur_state.name).label = cur_state.name
cur_state.out_transitions.each do |cur_transition|
@graph.add_edge(cur_transition.from.name, cur_transition.to.name).label = cur_transition.label.to_s
end
end
#make a .pdf output (can also be changed to .eps, .png or whatever)
@graph.output("pdf" => File.join(".")+"/" + @graph.name + ".pdf")
#it's really not that hard :-)
只有一件事我不能做:在开始状态下“无中生有”地画一个箭头。建议任何人?