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
|
# File 'lib/purechart/chart_helper.rb', line 3
def lollipop_chart(data, configuration = { axes: { horizontal: "Value" } }, path = "")
default_config_path = File.join( File.dirname(__FILE__), 'styles/default.yml' )
default_config_hash = YAML.load(File.read(default_config_path))
user_config_hash = {}
if path != ""
if File.file?("app/purechart/" + path + ".yml")
user_config_hash = YAML.load(File.read("app/purechart/" + path + ".yml"))
elsif File.file?("app/purechart/" + path + ".yaml")
user_config_hash = YAML.load(File.read("app/purechart/" + path + ".yaml"))
elsif File.file?("app/purechart/" + path + ".json")
user_config_hash = JSON.load(File.read("app/purechart/" + path + ".json"))
else
raise "(PureChart) ERROR - Could not locate configuration file '" + path + ".[YML, YAML, JSON]'. Make sure this file exists in your 'app/purechart' directory."
end
end
style_config = default_config_hash.merge(user_config_hash)
largest_value = (data.map { |object| object[:value] }).max()
data.each do |object|
object[:width] = (Float(object[:value]) / largest_value) * 100
end
gridlines = {
vertical_lines: 10,
vertical_increment: (Float(largest_value) / 10).ceil
}
ActionController::Base.render partial: '/lollipop', locals: {
data: data,
gridlines: gridlines,
configuration: configuration,
style: style_config
}
end
|