chartify 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +48 -0
- data/Rakefile +37 -0
- data/lib/charter.rb +29 -0
- data/lib/charter/bar_chart.rb +28 -0
- data/lib/charter/chart_base.rb +119 -0
- data/lib/charter/config.rb +23 -0
- data/lib/charter/factory.rb +16 -0
- data/lib/charter/gruff_themes.rb +18 -0
- data/lib/charter/line_chart.rb +38 -0
- data/lib/charter/pie_chart.rb +27 -0
- data/lib/charter/version.rb +3 -0
- data/lib/charter/web_chart/google_chart/bar_chart.rb +24 -0
- data/lib/charter/web_chart/google_chart/google_chart_module.rb +37 -0
- data/lib/charter/web_chart/google_chart/line_chart.rb +24 -0
- data/lib/charter/web_chart/google_chart/pie_chart.rb +43 -0
- data/lib/tasks/charter_tasks.rake +4 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2f754d491ce71c728183aefc7185bfafa1640e5d
|
4
|
+
data.tar.gz: 7dac10f51fc23054e640b775ea81faebe53eb7c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9b855fa25fb15fb6ec2da9c9adb192664c6300686cd9b3b7f2b03ae66b4b0ba3b5c43f360e31d26bb60b8da34e33c773489db790f35e56f5aa12e5d01744cfb
|
7
|
+
data.tar.gz: 852b34561415658344c9ab8a1be2583988d5a86056ea551de2ac7f33d65eba80d5c9d5880930f0a4a93ae6663ea77105033ce81272416c3b72358eb86c54f478
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
Charter
|
2
|
+
=======
|
3
|
+
The purpose of this gem is to capture data to create a chart, in an object, so that we can do the following things
|
4
|
+
|
5
|
+
- Render javascript graph, (which can be chart library agnostic)
|
6
|
+
- Create the chart data using ruby only (no js to render chart)
|
7
|
+
- Export chart as image (Needed when you want to email a chart)
|
8
|
+
- Configuration for chart colors
|
9
|
+
|
10
|
+
Note
|
11
|
+
----
|
12
|
+
The project is in progress. So please wait for the release.
|
13
|
+
|
14
|
+
The project is similar to [chartkick](http://chartkick.com/). The reason I am planning to create another project
|
15
|
+
is because it does not support to export charts in image.
|
16
|
+
|
17
|
+
Charts supported
|
18
|
+
----------------
|
19
|
+
* Line chart
|
20
|
+
* Bar chart
|
21
|
+
* Pie chart
|
22
|
+
|
23
|
+
For generating image from the chart data we are using [Gruff](https://github.com/topfunky/gruff)
|
24
|
+
|
25
|
+
Here are some sample code to generate graph object and render to web.
|
26
|
+
```ruby
|
27
|
+
@chart = Charter::Factory.build(:line) do |chart|
|
28
|
+
chart.data = [{hours_remain: 100, estimated_hours_remain: 100, day: 3.days.ago.to_date},
|
29
|
+
{hours_remain: 50, estimated_hours_remain: 45, day: 2.days.ago.to_date},
|
30
|
+
{hours_remain: 5, estimated_hours_remain: 10, day: 1.days.ago.to_date}]
|
31
|
+
chart.columns = {hours_remain: 'Hours remaining', estimated_hours_remain: 'Estimated hours remaining'}
|
32
|
+
chart.label_column = :day
|
33
|
+
end
|
34
|
+
```
|
35
|
+
In the web page,
|
36
|
+
```erb
|
37
|
+
<div id="chart" style="width: 900px; height: 180px;"></div>
|
38
|
+
<%= @chart.render_chart('chart') %>
|
39
|
+
```
|
40
|
+
To export the chart as image,
|
41
|
+
```ruby
|
42
|
+
@chart.to_blob
|
43
|
+
```
|
44
|
+
Now you can attach the blob to email or in the PDF file.
|
45
|
+
|
46
|
+
License
|
47
|
+
-------
|
48
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => "spec:all"
|
15
|
+
|
16
|
+
namespace :spec do
|
17
|
+
desc "Run Tests against all ORMs"
|
18
|
+
task :all do
|
19
|
+
sh "bundle --quiet"
|
20
|
+
sh "bundle exec rake spec"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'rdoc/task'
|
26
|
+
|
27
|
+
Rake::RDocTask.new do |rdoc|
|
28
|
+
require 'charter/version'
|
29
|
+
|
30
|
+
rdoc.rdoc_dir = 'rdoc'
|
31
|
+
rdoc.title = "Charter #{Charter::VERSION}"
|
32
|
+
rdoc.rdoc_files.include('README*')
|
33
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
puts 'RDocTask is not supported on this VM and platform combination.'
|
37
|
+
end
|
data/lib/charter.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Charter
|
2
|
+
autoload :Configuration, "charter/config"
|
3
|
+
|
4
|
+
def self.configure(&block)
|
5
|
+
yield @config ||= Charter::Configuration.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
|
12
|
+
configure do |config|
|
13
|
+
config.web_api_name = :google_chart
|
14
|
+
|
15
|
+
config.web do |wc|
|
16
|
+
wc.background_color = '#FFFFFF'
|
17
|
+
wc.colors = ['#3366CC', # blue
|
18
|
+
'#DC3912', # red
|
19
|
+
'#FF9900', # yellow
|
20
|
+
'#109618', # green
|
21
|
+
'#990099', # dk purple
|
22
|
+
'#0099C6', # sky
|
23
|
+
'#DD4477' # grey
|
24
|
+
]
|
25
|
+
wc.text_color = '#666666'
|
26
|
+
wc.line_width = 2
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'charter/chart_base'
|
2
|
+
require 'gruff'
|
3
|
+
|
4
|
+
module Charter
|
5
|
+
class BarChart < ChartBase
|
6
|
+
def to_blob
|
7
|
+
g = prepare_gruff(:bar)
|
8
|
+
|
9
|
+
columns.each do |column|
|
10
|
+
if column.kind_of?(Array)
|
11
|
+
key, text = column[0], column[1]
|
12
|
+
else
|
13
|
+
key, text = column, column.to_s.humanize
|
14
|
+
end
|
15
|
+
|
16
|
+
g.data(text, data_for_column(key))
|
17
|
+
end
|
18
|
+
|
19
|
+
labels = {}
|
20
|
+
data_for_column(label_column).each_with_index do |label, index|
|
21
|
+
labels[index] = label.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
g.labels = labels
|
25
|
+
g.to_blob
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'charter/gruff_themes'
|
2
|
+
|
3
|
+
module Charter
|
4
|
+
class ChartBase
|
5
|
+
attr_accessor :title, :data, :columns, :label_column
|
6
|
+
|
7
|
+
# data: array of hash
|
8
|
+
# [{date: 2013-1-2, hours_remain: 2, estimated_hours_remain: 10},
|
9
|
+
# {date: 2013-1-3, hours_remain: 4, estimated_hours_remain: 10},
|
10
|
+
# {date: 2013-1-4, hours_remain: 10, estimated_hours_remain: 10}]
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
columns, data = [], []
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_row(row)
|
17
|
+
data << row
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_chart(html_dom_id, options = {})
|
21
|
+
api_name = options[:web_api_name] || Charter.config.web_api_name.to_s
|
22
|
+
class_name = self.class.name.split("::")[1]
|
23
|
+
load "charter/web_chart/#{api_name}/#{class_name.underscore}.rb"
|
24
|
+
chart = "Charter::WebChart::#{api_name.camelize}::#{class_name}".constantize.new
|
25
|
+
chart.data, chart.columns, chart.label_column = self.data, self.columns, self.label_column
|
26
|
+
html = <<-HTML
|
27
|
+
#{chart.include_js if chart.respond_to?(:include_js)}
|
28
|
+
<script type="application/javascript" class="chart_script">
|
29
|
+
#{chart.render(html_dom_id)}
|
30
|
+
</script>
|
31
|
+
HTML
|
32
|
+
html.html_safe
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.evaluate_js
|
36
|
+
"eval($('script.chart_script').text());"
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
# @param type - type of the Gruff. It's a factory to create the appropriate
|
41
|
+
def prepare_gruff(type)
|
42
|
+
chart_type = type.to_s.classify
|
43
|
+
chart_type = "Gruff::#{chart_type}".constantize
|
44
|
+
|
45
|
+
g = chart_type.new
|
46
|
+
g.theme = Charter::Themes::GOOGLE_CHART
|
47
|
+
g.title = self.title
|
48
|
+
g
|
49
|
+
end
|
50
|
+
|
51
|
+
def data_for_column(column_name)
|
52
|
+
data.map { |row| row[column_name] }
|
53
|
+
end
|
54
|
+
|
55
|
+
def column_names
|
56
|
+
@column_names ||= begin
|
57
|
+
columns.collect do |column|
|
58
|
+
column.kind_of?(Array) ? column[1] : column.to_s.humanize
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def column_keys
|
64
|
+
@column_keys ||= begin
|
65
|
+
columns.collect do |column|
|
66
|
+
column.kind_of?(Array) ? column[0] : column
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def text_color
|
72
|
+
web_config.text_color
|
73
|
+
end
|
74
|
+
|
75
|
+
def baseline_color
|
76
|
+
text_color
|
77
|
+
end
|
78
|
+
|
79
|
+
def grid_color
|
80
|
+
text_color
|
81
|
+
end
|
82
|
+
|
83
|
+
def bg_color
|
84
|
+
web_config.background_color
|
85
|
+
end
|
86
|
+
|
87
|
+
def web_colors
|
88
|
+
web_config.colors
|
89
|
+
end
|
90
|
+
|
91
|
+
# Amount should be a decimal between 0 and 1. Lower means darker
|
92
|
+
def darken_color(hex_color, amount=0.4)
|
93
|
+
hex_color = hex_color.gsub('#','')
|
94
|
+
rgb = hex_color.scan(/../).map {|color| color.hex}
|
95
|
+
rgb[0] = (rgb[0].to_i * amount).round
|
96
|
+
rgb[1] = (rgb[1].to_i * amount).round
|
97
|
+
rgb[2] = (rgb[2].to_i * amount).round
|
98
|
+
"#%02x%02x%02x" % rgb
|
99
|
+
end
|
100
|
+
|
101
|
+
# Amount should be a decimal between 0 and 1. Higher means lighter
|
102
|
+
def lighten_color(hex_color, amount=0.6)
|
103
|
+
hex_color = hex_color.gsub('#','')
|
104
|
+
rgb = hex_color.scan(/../).map {|color| color.hex}
|
105
|
+
rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min
|
106
|
+
rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min
|
107
|
+
rgb[2] = [(rgb[2].to_i + 255 * amount).round, 255].min
|
108
|
+
"#%02x%02x%02x" % rgb
|
109
|
+
end
|
110
|
+
|
111
|
+
def config
|
112
|
+
@config ||= Charter.config
|
113
|
+
end
|
114
|
+
|
115
|
+
def web_config
|
116
|
+
@web_config ||= Charter.config.web_config
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Charter
|
2
|
+
class Configuration
|
3
|
+
include ActiveSupport::Configurable
|
4
|
+
config_accessor :web_api_name
|
5
|
+
config_accessor :chart
|
6
|
+
|
7
|
+
def web(&block)
|
8
|
+
yield @web_config ||= Charter::WebConfiguration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def web_config
|
12
|
+
@web_config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class WebConfiguration
|
17
|
+
include ActiveSupport::Configurable
|
18
|
+
config_accessor :background_color
|
19
|
+
config_accessor :colors
|
20
|
+
config_accessor :text_color
|
21
|
+
config_accessor :line_width
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'charter/gruff_themes'
|
2
|
+
require 'charter/line_chart'
|
3
|
+
require 'charter/pie_chart'
|
4
|
+
require 'charter/bar_chart'
|
5
|
+
|
6
|
+
module Charter
|
7
|
+
class Factory
|
8
|
+
# @param type can be of line, pie, bar etc
|
9
|
+
def self.build(type, &block)
|
10
|
+
raise "type has to be a symbol" unless type.kind_of? Symbol
|
11
|
+
chart = "Charter::#{type.to_s.camelize}Chart".constantize.new
|
12
|
+
block.call chart
|
13
|
+
chart
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Charter
|
2
|
+
module Themes
|
3
|
+
GOOGLE_CHART = {
|
4
|
+
:colors => [
|
5
|
+
'#3366CC', # blue
|
6
|
+
'#DC3912', # red
|
7
|
+
'#FF9900', # yellow
|
8
|
+
'#109618', # green
|
9
|
+
'#990099', # dk purple
|
10
|
+
'#0099C6', # sky
|
11
|
+
'#DD4477' # grey
|
12
|
+
],
|
13
|
+
:marker_color => '#aea9a9', # Grey
|
14
|
+
:font_color => 'black',
|
15
|
+
:background_colors => 'white'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'charter/chart_base'
|
2
|
+
require 'gruff'
|
3
|
+
|
4
|
+
# Example
|
5
|
+
# -------
|
6
|
+
# Charter::Factory.build(:line) do |chart|
|
7
|
+
# chart.data = [{hours_remain: 100, estimated_hours_remain: 100, day: 3.days.ago.to_date},
|
8
|
+
# {hours_remain: 50, estimated_hours_remain: 45, day: 2.days.ago.to_date},
|
9
|
+
# {hours_remain: 5, estimated_hours_remain: 10, day: 1.days.ago.to_date}]
|
10
|
+
# chart.columns = {hours_remain: 'Hours remaining', estimated_hours_remain: 'Estimated hours remaining'}
|
11
|
+
# chart.label_column = :day
|
12
|
+
# end
|
13
|
+
|
14
|
+
module Charter
|
15
|
+
class LineChart < ChartBase
|
16
|
+
def to_blob
|
17
|
+
g = prepare_gruff(:line)
|
18
|
+
|
19
|
+
columns.each do |column|
|
20
|
+
if column.kind_of?(Array)
|
21
|
+
key, text = column[0], column[1]
|
22
|
+
else
|
23
|
+
key, text = column, column.to_s.humanize
|
24
|
+
end
|
25
|
+
|
26
|
+
g.data(text, data_for_column(key))
|
27
|
+
end
|
28
|
+
|
29
|
+
labels = {}
|
30
|
+
data_for_column(label_column).each_with_index do |label, index|
|
31
|
+
labels[index] = label.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
g.labels = labels
|
35
|
+
g.to_blob
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'charter/chart_base'
|
2
|
+
require 'gruff'
|
3
|
+
|
4
|
+
# Example
|
5
|
+
# -------
|
6
|
+
# Charter::Factory.build(:pie) do |chart|
|
7
|
+
# chart.data = {'ruby' => 100,
|
8
|
+
# 'python' => 12}
|
9
|
+
# chart.columns = ['Language', 'Usage']
|
10
|
+
# end
|
11
|
+
module Charter
|
12
|
+
class PieChart < ChartBase
|
13
|
+
def to_blob
|
14
|
+
g = prepare_gruff(:pie)
|
15
|
+
|
16
|
+
data.each do |row|
|
17
|
+
if row.kind_of?(Array)
|
18
|
+
key, val = row[0], row[1]
|
19
|
+
else
|
20
|
+
key, val = row.key, row.val
|
21
|
+
end
|
22
|
+
g.data(key, val)
|
23
|
+
end
|
24
|
+
g.to_blob
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'charter/bar_chart'
|
2
|
+
require 'charter/web_chart/google_chart/google_chart_module'
|
3
|
+
|
4
|
+
module Charter
|
5
|
+
module WebChart
|
6
|
+
module GoogleChart
|
7
|
+
class BarChart < Charter::BarChart
|
8
|
+
include Charter::WebChart::GoogleChart::GoogleChartModule
|
9
|
+
|
10
|
+
def render(html_dom_id)
|
11
|
+
js = <<-JS
|
12
|
+
google.load("visualization", "1", {packages:["corechart"]});
|
13
|
+
google.setOnLoadCallback(function () {
|
14
|
+
var data = google.visualization.arrayToDataTable(#{array_data_table.to_json});
|
15
|
+
var chart = new google.visualization.BarChart(document.getElementById('#{html_dom_id}'));
|
16
|
+
chart.draw(data, #{chart_options.to_json});
|
17
|
+
});
|
18
|
+
JS
|
19
|
+
js.html_safe
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'charter/bar_chart'
|
2
|
+
|
3
|
+
module Charter
|
4
|
+
module WebChart
|
5
|
+
module GoogleChart
|
6
|
+
module GoogleChartModule
|
7
|
+
def chart_options
|
8
|
+
{
|
9
|
+
title: title,
|
10
|
+
backgroundColor: bg_color,
|
11
|
+
colors: web_colors,
|
12
|
+
vAxis: {baselineColor: baseline_color,
|
13
|
+
gridlines: {color: grid_color},
|
14
|
+
textStyle: {color: text_color}},
|
15
|
+
hAxis: {baselineColor: baseline_color,
|
16
|
+
gridlines: {color: grid_color},
|
17
|
+
textStyle: {color: text_color}},
|
18
|
+
legend: {textStyle: {color: text_color}},
|
19
|
+
lineWidth: config.web_config.line_width
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def array_data_table
|
24
|
+
array_data = [[label_column] + column_names]
|
25
|
+
array_data + data.collect do |row|
|
26
|
+
[row[label_column]] + column_keys.collect { |col| row[col] }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def include_js
|
31
|
+
%q{<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization',
|
32
|
+
'version':'1','packages':['timeline']}]}"></script>}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'charter/line_chart'
|
2
|
+
require 'charter/web_chart/google_chart/google_chart_module'
|
3
|
+
|
4
|
+
module Charter
|
5
|
+
module WebChart
|
6
|
+
module GoogleChart
|
7
|
+
class LineChart < Charter::LineChart
|
8
|
+
include Charter::WebChart::GoogleChart::GoogleChartModule
|
9
|
+
|
10
|
+
def render(html_dom_id)
|
11
|
+
js = <<-JS
|
12
|
+
google.load("visualization", "1", {packages:["corechart"]});
|
13
|
+
google.setOnLoadCallback(function () {
|
14
|
+
var data = google.visualization.arrayToDataTable(#{array_data_table.to_json});
|
15
|
+
var chart = new google.visualization.LineChart(document.getElementById('#{html_dom_id}'));
|
16
|
+
chart.draw(data, #{chart_options.to_json});
|
17
|
+
});
|
18
|
+
JS
|
19
|
+
js.html_safe
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'charter/pie_chart'
|
2
|
+
require 'charter/web_chart/google_chart/google_chart_module'
|
3
|
+
|
4
|
+
module Charter
|
5
|
+
module WebChart
|
6
|
+
module GoogleChart
|
7
|
+
class PieChart < Charter::PieChart
|
8
|
+
include Charter::WebChart::GoogleChart::GoogleChartModule
|
9
|
+
|
10
|
+
# Js data
|
11
|
+
# var data = google.visualization.arrayToDataTable([
|
12
|
+
# ['Task', 'Hours per Day'],
|
13
|
+
# ['Work', 11],
|
14
|
+
# ['Eat', 2],
|
15
|
+
# ['Commute', 2],
|
16
|
+
# ['Watch TV', 2],
|
17
|
+
# ['Sleep', 7]
|
18
|
+
# ]);
|
19
|
+
def render(html_dom_id)
|
20
|
+
datasets = data.collect do |column|
|
21
|
+
if column.kind_of?(Array)
|
22
|
+
title, val = column[0], column[1]
|
23
|
+
else
|
24
|
+
title, val = column, column.to_s.humanize
|
25
|
+
end
|
26
|
+
[title, val]
|
27
|
+
end
|
28
|
+
datasets.insert 0, column_names
|
29
|
+
|
30
|
+
js = <<-JS
|
31
|
+
google.load("visualization", "1", {packages:["corechart"]});
|
32
|
+
google.setOnLoadCallback(function () {
|
33
|
+
var data = google.visualization.arrayToDataTable(#{datasets.to_json});
|
34
|
+
var chart = new google.visualization.PieChart(document.getElementById('#{html_dom_id}'));
|
35
|
+
chart.draw(data, #{chart_options.to_json});
|
36
|
+
});
|
37
|
+
JS
|
38
|
+
js.html_safe
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chartify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- A.K.M. Ashrafuzzaman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gruff
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sqlite3
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.3'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec-mocks
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: activerecord
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '4'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '4'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: activesupport
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '4'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '4'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: database_cleaner
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.2'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1.2'
|
145
|
+
description: A gem to manage online chart so that it can be exportable in image from
|
146
|
+
ruby code.
|
147
|
+
email:
|
148
|
+
- ashrafuzzaman.g2@gmail.com
|
149
|
+
executables: []
|
150
|
+
extensions: []
|
151
|
+
extra_rdoc_files: []
|
152
|
+
files:
|
153
|
+
- MIT-LICENSE
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- lib/charter.rb
|
157
|
+
- lib/charter/bar_chart.rb
|
158
|
+
- lib/charter/chart_base.rb
|
159
|
+
- lib/charter/config.rb
|
160
|
+
- lib/charter/factory.rb
|
161
|
+
- lib/charter/gruff_themes.rb
|
162
|
+
- lib/charter/line_chart.rb
|
163
|
+
- lib/charter/pie_chart.rb
|
164
|
+
- lib/charter/version.rb
|
165
|
+
- lib/charter/web_chart/google_chart/bar_chart.rb
|
166
|
+
- lib/charter/web_chart/google_chart/google_chart_module.rb
|
167
|
+
- lib/charter/web_chart/google_chart/line_chart.rb
|
168
|
+
- lib/charter/web_chart/google_chart/pie_chart.rb
|
169
|
+
- lib/tasks/charter_tasks.rake
|
170
|
+
homepage: https://github.com/ashrafuzzaman/charter
|
171
|
+
licenses: []
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.2.2
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: A gem to manage online chart so that it can be exportable in image from ruby
|
193
|
+
code.
|
194
|
+
test_files: []
|