forked from fugalh/dfa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rb
More file actions
88 lines (74 loc) · 2.32 KB
/
test.rb
File metadata and controls
88 lines (74 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require 'rubygems' # allows for the loading of gems
require 'graphviz' # this loads the ruby-graphviz gem
# Constants defining file names and paths
CSVRecipeFileName = "recipes.csv"
CSVRecipeFilePath = File.join(".")
CSVMaterialFileName = "materials.csv"
CSVMaterialFilePath = File.join(".")
CSVPlantFileName = "plants.csv"
CSVPlantFilePath = File.join(".")
OutputPath = File.join(".")
# load 3 arrays with CSV data
recipes = []; materials = []; plants = []
[[CSVRecipeFileName, CSVRecipeFilePath, recipes],
[CSVMaterialFileName, CSVMaterialFilePath, materials],
[CSVPlantFileName, CSVPlantFilePath, plants]].each do |array|
File.open(File.join(array[1], array[0])).each do |line|
array[2] << line.chop.split(",")
end
end
puts("recipes: ")
puts recipes
# initialize new Graphviz graph
g = GraphViz::new( "structs", "type" => "graph" )
g[:rankdir] = "LR"
# set global node options
g.node[:color] = "#ddaa66"
g.node[:style] = "filled"
g.node[:shape] = "box"
g.node[:penwidth] = "1"
g.node[:fontname] = "Trebuchet MS"
g.node[:fontsize] = "8"
g.node[:fillcolor]= "#ffeecc"
g.node[:fontcolor]= "#775500"
g.node[:margin] = "0.0"
# set global edge options
g.edge[:color] = "#999999"
g.edge[:weight] = "1"
g.edge[:fontsize] = "6"
g.edge[:fontcolor]= "#444444"
g.edge[:fontname] = "Verdana"
g.edge[:dir] = "forward"
g.edge[:arrowsize]= "0.5"
#########
puts plants
puts ("\n\n\n")
puts plants[0][1]
puts ("\n")
puts plants[1]
puts ("\n")
puts plants[2]
#########
# draw our nodes, i.e., plants
plants.each do |plant|
g.add_nodes(plant[0]).label = plant[1]+
"\\n"+
plant[2]+
", "+plant[3]+
"\\n("+
plant[0]+
")"
end
# brute force, but simple function to find a material record by number
def find_material_record(materials_array, material_number)
materials_array.collect{|m| m[1] unless m.index(material_number).nil?}.compact[0]
end
# connect the nodes with our recipes, add labels from material data
recipes.each do |recipe|
end_material = find_material_record(materials, recipe[1])
component_material = find_material_record(materials, recipe[3])
g.add_edges(recipe[4],recipe[2]).label=
component_material+" for\\n"+end_material+"\\n(Recipe "+recipe[0]+")"
end
#g.output( "output" => "png", :file => OutputPath+"/graph.jpeg" )
g.output(:png => "test2.png" )