Skip to content

Instantly share code, notes, and snippets.

@fooqri
Last active December 10, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fooqri/4431708 to your computer and use it in GitHub Desktop.
Save fooqri/4431708 to your computer and use it in GitHub Desktop.
require 'graphviz'
# Create a new graph
g = GraphViz.new( :G, :type => :digraph )
us_num = 47 #placeholder, will get from file name in final version.
# set global node options
g.node[:color] = "#333333"
g.node[:style] = "filled"
g.node[:shape] = "box"
g.node[:penwidth] = "1"
g.node[:fontname] = "Trebuchet MS"
g.node[:fontsize] = "8"
g.node[:fillcolor]= "#294b76"
g.node[:fontcolor]= "white"
g.node[:margin] = "0.0"
# set global edge options
g.edge[:color] = "#666666"
g.edge[:weight] = "1"
g.edge[:fontsize] = "6"
g.edge[:fontcolor]= "#444444"
g.edge[:fontname] = "Verdana"
g.edge[:dir] = "forward"
g.edge[:arrowhead]="open"
g.edge[:arrowsize]= "0.5"
my_nodes={"WF1"=>"New Account Screen", "WF2" =>"Account Recover Screen", "WF3" => "Welcome Screen"}
my_decisions={"D1"=>"", "D2" =>"", "D3" => "", "D4" => ""}
g.add_nodes("Start",{:label => "", :shape => "circle"})
my_nodes.each do |key, value|
# When adding a node the node name becomes the label so can access later.
g.add_nodes(key,{:label => value})
end
my_decisions.each do |key, value|
# When adding a node the node name becomes the label so can access later.
g.add_nodes(key,{:label => value, :shape => "diamond"})
end
g.add_nodes("End",{:label => "", :shape => "circle"})
#hello = g.add_nodes( "Hello" )
#world = g.add_nodes( "World" )
puts g.inspect
# Create an edge between the two nodes
g.add_edges( g.Start, g.D1)
g.add_edges( g.D1, g.WF1, {:label => "[create account]"})
g.add_edges( g.D1, g.WF2, {:label => "[attach account]"})
g.add_edges( g.WF1, g.D2)
g.add_edges( g.D2, g.D3, {:label => "[failure]"})
g.add_edges( g.D2, g.WF3, {:label => "[account created]"})
g.add_edges( g.D3, g.WF2, {:label => "[account exists]"})
g.add_edges( g.WF2, g.D4)
g.add_edges( g.D4, g.WF2, {:label => "[failure]"})
g.add_edges( g.D4, g.End, {:label => "[recovered]"})
g.add_edges( g.WF3, g.End)
# Generate output image
g.output( :png => "US#{us_num}.png" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment