chartify 0.2.2 → 0.3.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 +4 -4
- data/lib/chartify.rb +14 -0
- data/lib/chartify/area_chart.rb +1 -1
- data/lib/chartify/bar_chart.rb +1 -1
- data/lib/chartify/chart_base.rb +14 -6
- data/lib/chartify/column_chart.rb +1 -1
- data/lib/chartify/config.rb +2 -1
- data/lib/chartify/line_chart.rb +1 -1
- data/lib/chartify/pie_chart.rb +1 -1
- data/lib/chartify/version.rb +1 -1
- data/lib/chartify/web_chart/google_chart/area_chart.rb +4 -7
- data/lib/chartify/web_chart/google_chart/bar_chart.rb +4 -7
- data/lib/chartify/web_chart/google_chart/column_chart.rb +4 -7
- data/lib/chartify/web_chart/google_chart/google_chart_module.rb +10 -0
- data/lib/chartify/web_chart/google_chart/line_chart.rb +4 -7
- data/lib/chartify/web_chart/google_chart/pie_chart.rb +10 -18
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a84aaa269508d4800411f45b4bc9fc32e4afe96
|
4
|
+
data.tar.gz: dc1a5b2d9870c4f6c8e34c9d54761ab420532783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e95056a8fb0daa61d68e3342214f0e5dd9c13e535059d76c0700e9cda84434f8f0960b0b436c4e614a84fac38720d4e880734b6824e9408148a86623c0310d20
|
7
|
+
data.tar.gz: 1f24b86302ceea18ae5191b96b318f38dc518f2b806d3c65f9963385624060a2249f1a2df5b6496a501786bbd53a3786e78757ebab3c057cb9f08a74818201c1
|
data/lib/chartify.rb
CHANGED
@@ -11,6 +11,20 @@ module Chartify
|
|
11
11
|
|
12
12
|
configure do |config|
|
13
13
|
config.web_api_name = :google_chart
|
14
|
+
config.image_theme = {
|
15
|
+
:colors => [
|
16
|
+
'#3366CC', # blue
|
17
|
+
'#DC3912', # red
|
18
|
+
'#FF9900', # yellow
|
19
|
+
'#109618', # green
|
20
|
+
'#990099', # dk purple
|
21
|
+
'#0099C6', # sky
|
22
|
+
'#DD4477' # grey
|
23
|
+
],
|
24
|
+
:marker_color => '#aea9a9', # Grey
|
25
|
+
:font_color => '#666666',
|
26
|
+
:background_colors => '#FFFFFF'
|
27
|
+
}
|
14
28
|
|
15
29
|
config.web do |wc|
|
16
30
|
wc.background_color = '#FFFFFF'
|
data/lib/chartify/area_chart.rb
CHANGED
data/lib/chartify/bar_chart.rb
CHANGED
data/lib/chartify/chart_base.rb
CHANGED
@@ -18,10 +18,8 @@ module Chartify
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def render_chart(html_dom_id, options = {})
|
21
|
-
api_name = options
|
22
|
-
|
23
|
-
load "chartify/web_chart/#{api_name}/#{class_name.underscore}.rb"
|
24
|
-
chart = "Chartify::WebChart::#{api_name.camelize}::#{class_name}".constantize.new
|
21
|
+
api_name = fetch_api_name(options)
|
22
|
+
chart = instantiate_chart(api_name)
|
25
23
|
chart.data, chart.columns, chart.label_column = self.data, self.columns, self.label_column
|
26
24
|
html = <<-HTML
|
27
25
|
<script type="application/javascript" class="chart_script">
|
@@ -36,13 +34,23 @@ module Chartify
|
|
36
34
|
end
|
37
35
|
|
38
36
|
protected
|
37
|
+
def instantiate_chart(api_name)
|
38
|
+
class_name = self.class.name.split("::")[1]
|
39
|
+
load "chartify/web_chart/#{api_name}/#{class_name.underscore}.rb"
|
40
|
+
"Chartify::WebChart::#{api_name.camelize}::#{class_name}".constantize.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def fetch_api_name(options)
|
44
|
+
options[:web_api_name] || config.web_api_name.to_s
|
45
|
+
end
|
46
|
+
|
39
47
|
# @param type - type of the Gruff. It's a factory to create the appropriate
|
40
|
-
def
|
48
|
+
def instantiate_gruff(type)
|
41
49
|
chart_type = type.to_s.classify
|
42
50
|
chart_type = "Gruff::#{chart_type}".constantize
|
43
51
|
|
44
52
|
g = chart_type.new
|
45
|
-
g.theme =
|
53
|
+
g.theme = config.image_theme
|
46
54
|
g.title = self.title
|
47
55
|
g
|
48
56
|
end
|
data/lib/chartify/config.rb
CHANGED
data/lib/chartify/line_chart.rb
CHANGED
data/lib/chartify/pie_chart.rb
CHANGED
data/lib/chartify/version.rb
CHANGED
@@ -9,14 +9,11 @@ module Chartify
|
|
9
9
|
|
10
10
|
def render(html_dom_id)
|
11
11
|
js = <<-JS
|
12
|
-
google.
|
13
|
-
|
14
|
-
|
15
|
-
var chart = new google.visualization.AreaChart(document.getElementById('#{html_dom_id}'));
|
16
|
-
chart.draw(data, #{chart_options.to_json});
|
17
|
-
}
|
12
|
+
var data = google.visualization.arrayToDataTable(#{array_data_table.to_json});
|
13
|
+
var chart = new google.visualization.AreaChart(document.getElementById('#{html_dom_id}'));
|
14
|
+
chart.draw(data, #{chart_options.to_json});
|
18
15
|
JS
|
19
|
-
js.html_safe
|
16
|
+
wrap_in_function(js).html_safe
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
@@ -9,14 +9,11 @@ module Chartify
|
|
9
9
|
|
10
10
|
def render(html_dom_id)
|
11
11
|
js = <<-JS
|
12
|
-
google.
|
13
|
-
|
14
|
-
|
15
|
-
var chart = new google.visualization.BarChart(document.getElementById('#{html_dom_id}'));
|
16
|
-
chart.draw(data, #{chart_options.to_json});
|
17
|
-
}
|
12
|
+
var data = google.visualization.arrayToDataTable(#{array_data_table.to_json});
|
13
|
+
var chart = new google.visualization.BarChart(document.getElementById('#{html_dom_id}'));
|
14
|
+
chart.draw(data, #{chart_options.to_json});
|
18
15
|
JS
|
19
|
-
js.html_safe
|
16
|
+
wrap_in_function(js).html_safe
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
@@ -9,14 +9,11 @@ module Chartify
|
|
9
9
|
|
10
10
|
def render(html_dom_id)
|
11
11
|
js = <<-JS
|
12
|
-
google.
|
13
|
-
|
14
|
-
|
15
|
-
var chart = new google.visualization.ColumnChart(document.getElementById('#{html_dom_id}'));
|
16
|
-
chart.draw(data, #{chart_options.to_json});
|
17
|
-
}
|
12
|
+
var data = google.visualization.arrayToDataTable(#{array_data_table.to_json});
|
13
|
+
var chart = new google.visualization.ColumnChart(document.getElementById('#{html_dom_id}'));
|
14
|
+
chart.draw(data, #{chart_options.to_json});
|
18
15
|
JS
|
19
|
-
js.html_safe
|
16
|
+
wrap_in_function(js).html_safe
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
@@ -35,6 +35,16 @@ module Chartify
|
|
35
35
|
def include_js
|
36
36
|
%q{<script type="text/javascript" src="https://www.google.com/jsapi"></script>}
|
37
37
|
end
|
38
|
+
|
39
|
+
def wrap_in_function(code)
|
40
|
+
js = <<-JS
|
41
|
+
google.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
|
42
|
+
function drawChart#{timestamp}() {
|
43
|
+
#{code}
|
44
|
+
}
|
45
|
+
JS
|
46
|
+
js.html_safe
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
@@ -9,14 +9,11 @@ module Chartify
|
|
9
9
|
|
10
10
|
def render(html_dom_id)
|
11
11
|
js = <<-JS
|
12
|
-
google.
|
13
|
-
|
14
|
-
|
15
|
-
var chart = new google.visualization.LineChart(document.getElementById('#{html_dom_id}'));
|
16
|
-
chart.draw(data, #{chart_options.to_json});
|
17
|
-
}
|
12
|
+
var data = google.visualization.arrayToDataTable(#{array_data_table.to_json});
|
13
|
+
var chart = new google.visualization.LineChart(document.getElementById('#{html_dom_id}'));
|
14
|
+
chart.draw(data, #{chart_options.to_json});
|
18
15
|
JS
|
19
|
-
js.html_safe
|
16
|
+
wrap_in_function(js).html_safe
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
@@ -6,16 +6,6 @@ module Chartify
|
|
6
6
|
module GoogleChart
|
7
7
|
class PieChart < Chartify::PieChart
|
8
8
|
include Chartify::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
9
|
def render(html_dom_id)
|
20
10
|
datasets = data.collect do |column|
|
21
11
|
if column.kind_of?(Array)
|
@@ -25,17 +15,19 @@ module Chartify
|
|
25
15
|
end
|
26
16
|
[title, val]
|
27
17
|
end
|
28
|
-
datasets
|
18
|
+
insert_title_row(datasets)
|
29
19
|
|
30
20
|
js = <<-JS
|
31
|
-
google.
|
32
|
-
|
33
|
-
|
34
|
-
var chart = new google.visualization.PieChart(document.getElementById('#{html_dom_id}'));
|
35
|
-
chart.draw(data, #{chart_options.to_json});
|
36
|
-
}
|
21
|
+
var data = google.visualization.arrayToDataTable(#{datasets.to_json});
|
22
|
+
var chart = new google.visualization.PieChart(document.getElementById('#{html_dom_id}'));
|
23
|
+
chart.draw(data, #{chart_options.to_json});
|
37
24
|
JS
|
38
|
-
js.html_safe
|
25
|
+
wrap_in_function(js).html_safe
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def insert_title_row(datasets)
|
30
|
+
datasets.insert 0, column_names
|
39
31
|
end
|
40
32
|
end
|
41
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chartify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- A.K.M. Ashrafuzzaman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gruff
|
@@ -142,8 +142,10 @@ dependencies:
|
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '1.2'
|
145
|
-
description:
|
146
|
-
|
145
|
+
description: |-
|
146
|
+
This gem wraps the data to render chart and then it draws those charts in the web
|
147
|
+
and use the same data to render charts as images, which is often useful when you want to render the chart
|
148
|
+
in pdf or attach it to emails
|
147
149
|
email:
|
148
150
|
- ashrafuzzaman.g2@gmail.com
|
149
151
|
executables: []
|
@@ -172,7 +174,8 @@ files:
|
|
172
174
|
- lib/chartify/web_chart/google_chart/pie_chart.rb
|
173
175
|
- lib/tasks/chartify_tasks.rake
|
174
176
|
homepage: https://github.com/ashrafuzzaman/chartify
|
175
|
-
licenses:
|
177
|
+
licenses:
|
178
|
+
- MIT
|
176
179
|
metadata: {}
|
177
180
|
post_install_message:
|
178
181
|
rdoc_options: []
|
@@ -193,6 +196,6 @@ rubyforge_project:
|
|
193
196
|
rubygems_version: 2.2.2
|
194
197
|
signing_key:
|
195
198
|
specification_version: 4
|
196
|
-
summary: A gem to manage
|
197
|
-
code.
|
199
|
+
summary: A gem to manage charts in the web and to make it exportable in image from
|
200
|
+
ruby code.
|
198
201
|
test_files: []
|