chartify 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chartify/area_chart.rb +29 -0
- data/lib/chartify/bar_chart.rb +2 -1
- data/lib/chartify/chart_base.rb +1 -1
- data/lib/chartify/column_chart.rb +29 -0
- data/lib/chartify/factory.rb +2 -0
- data/lib/chartify/line_chart.rb +1 -0
- data/lib/chartify/version.rb +1 -1
- data/lib/chartify/web_chart/google_chart/area_chart.rb +24 -0
- data/lib/chartify/web_chart/google_chart/column_chart.rb +24 -0
- data/lib/chartify/web_chart/google_chart/google_chart_module.rb +3 -2
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f3138a3aaabede918897180074d61740e25d180
|
4
|
+
data.tar.gz: ce208f1f14a6282a0d3294729395b03722279479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1e524cad2309a25152e16a6832204c444eb04018d93a0a14381cd710e0e5edd1665808db6c9063b66f03bbcd087cf507d32665feaf79c0b6eb8430dff09642d
|
7
|
+
data.tar.gz: f45202af7bd870ade18aaed0df653aec6c2d40f815f7ca98dffb1f509a657c0ef22455b7baa64a125b2864e088fb1aa82b8db4f479a940324bb0a9a411fc3e32
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'chartify/chart_base'
|
2
|
+
require 'gruff'
|
3
|
+
|
4
|
+
# Example
|
5
|
+
# -------
|
6
|
+
# Chartify::Factory.build(:area) 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
|
+
module Chartify
|
14
|
+
class AreaChart < ChartBase
|
15
|
+
def to_blob
|
16
|
+
g = prepare_gruff(:area)
|
17
|
+
|
18
|
+
data.each do |row|
|
19
|
+
if row.kind_of?(Array)
|
20
|
+
key, val = row[0], row[1]
|
21
|
+
else
|
22
|
+
key, val = row.key, row.val
|
23
|
+
end
|
24
|
+
g.data(key, val)
|
25
|
+
end
|
26
|
+
g.to_blob
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/chartify/bar_chart.rb
CHANGED
data/lib/chartify/chart_base.rb
CHANGED
@@ -18,7 +18,7 @@ module Chartify
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def render_chart(html_dom_id, options = {})
|
21
|
-
api_name = options[:web_api_name] ||
|
21
|
+
api_name = options[:web_api_name] || config.web_api_name.to_s
|
22
22
|
class_name = self.class.name.split("::")[1]
|
23
23
|
load "chartify/web_chart/#{api_name}/#{class_name.underscore}.rb"
|
24
24
|
chart = "Chartify::WebChart::#{api_name.camelize}::#{class_name}".constantize.new
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'chartify/chart_base'
|
2
|
+
require 'gruff'
|
3
|
+
|
4
|
+
module Chartify
|
5
|
+
class ColumnChart < ChartBase
|
6
|
+
def to_blob
|
7
|
+
raise 'Need to specify label_column' unless label_column.present?
|
8
|
+
g = prepare_gruff(:bar)
|
9
|
+
|
10
|
+
columns.each do |column|
|
11
|
+
if column.kind_of?(Array)
|
12
|
+
key, text = column[0], column[1]
|
13
|
+
else
|
14
|
+
key, text = column, column.to_s.humanize
|
15
|
+
end
|
16
|
+
|
17
|
+
g.data(text, data_for_column(key))
|
18
|
+
end
|
19
|
+
|
20
|
+
labels = {}
|
21
|
+
data_for_column(label_column).each_with_index do |label, index|
|
22
|
+
labels[index] = label.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
g.labels = labels
|
26
|
+
g.to_blob
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/chartify/factory.rb
CHANGED
data/lib/chartify/line_chart.rb
CHANGED
data/lib/chartify/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'chartify/area_chart'
|
2
|
+
require 'chartify/web_chart/google_chart/google_chart_module'
|
3
|
+
|
4
|
+
module Chartify
|
5
|
+
module WebChart
|
6
|
+
module GoogleChart
|
7
|
+
class AreaChart < Chartify::AreaChart
|
8
|
+
include Chartify::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.AreaChart(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,24 @@
|
|
1
|
+
require 'chartify/bar_chart'
|
2
|
+
require 'chartify/web_chart/google_chart/google_chart_module'
|
3
|
+
|
4
|
+
module Chartify
|
5
|
+
module WebChart
|
6
|
+
module GoogleChart
|
7
|
+
class ColumnChart < Chartify::ColumnChart
|
8
|
+
include Chartify::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.ColumnChart(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
|
@@ -21,9 +21,10 @@ module Chartify
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def array_data_table
|
24
|
-
array_data = [[label_column] + column_names]
|
24
|
+
array_data = label_column.present? ? [[label_column] + column_names] : [column_names]
|
25
25
|
array_data + data.collect do |row|
|
26
|
-
|
26
|
+
row_val = column_keys.collect { |col| row[col] }
|
27
|
+
label_column.present? ? [row[label_column]] + row_val : row_val
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
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.2.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-06-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gruff
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,14 +48,14 @@ dependencies:
|
|
48
48
|
name: sqlite3
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
@@ -154,15 +154,19 @@ files:
|
|
154
154
|
- README.md
|
155
155
|
- Rakefile
|
156
156
|
- lib/chartify.rb
|
157
|
+
- lib/chartify/area_chart.rb
|
157
158
|
- lib/chartify/bar_chart.rb
|
158
159
|
- lib/chartify/chart_base.rb
|
160
|
+
- lib/chartify/column_chart.rb
|
159
161
|
- lib/chartify/config.rb
|
160
162
|
- lib/chartify/factory.rb
|
161
163
|
- lib/chartify/gruff_themes.rb
|
162
164
|
- lib/chartify/line_chart.rb
|
163
165
|
- lib/chartify/pie_chart.rb
|
164
166
|
- lib/chartify/version.rb
|
167
|
+
- lib/chartify/web_chart/google_chart/area_chart.rb
|
165
168
|
- lib/chartify/web_chart/google_chart/bar_chart.rb
|
169
|
+
- lib/chartify/web_chart/google_chart/column_chart.rb
|
166
170
|
- lib/chartify/web_chart/google_chart/google_chart_module.rb
|
167
171
|
- lib/chartify/web_chart/google_chart/line_chart.rb
|
168
172
|
- lib/chartify/web_chart/google_chart/pie_chart.rb
|