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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99adce276ba3286967a95fb4e69945856a37d36e
4
- data.tar.gz: cd16d06e9a0c70b42fa6296fb17dac5879d12d25
3
+ metadata.gz: 1a84aaa269508d4800411f45b4bc9fc32e4afe96
4
+ data.tar.gz: dc1a5b2d9870c4f6c8e34c9d54761ab420532783
5
5
  SHA512:
6
- metadata.gz: 6636b438419a0e2b0fdc1b2b1ad33e6848ff2446414a2a79ad3b6949812d2bb64b1e37266f885894b985aac322e6e8c64ee876628325b7750c146fb0878b3b9c
7
- data.tar.gz: 22bef703c2f0fac5dc28bef9c9e9a5120b733e94b8160850ae7a9eeb0e1848fbd18cbf9f89402063feae75cfc4614a046d91bad9d8002774612f0665fada6ecf
6
+ metadata.gz: e95056a8fb0daa61d68e3342214f0e5dd9c13e535059d76c0700e9cda84434f8f0960b0b436c4e614a84fac38720d4e880734b6824e9408148a86623c0310d20
7
+ data.tar.gz: 1f24b86302ceea18ae5191b96b318f38dc518f2b806d3c65f9963385624060a2249f1a2df5b6496a501786bbd53a3786e78757ebab3c057cb9f08a74818201c1
@@ -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'
@@ -14,7 +14,7 @@ module Chartify
14
14
  class AreaChart < ChartBase
15
15
  def to_blob
16
16
  raise 'Need to specify label_column' unless label_column.present?
17
- g = prepare_gruff(:area)
17
+ g = instantiate_gruff(:area)
18
18
 
19
19
  columns.each do |column|
20
20
  if column.kind_of?(Array)
@@ -5,7 +5,7 @@ module Chartify
5
5
  class BarChart < ChartBase
6
6
  def to_blob
7
7
  raise 'Need to specify label_column' unless label_column.present?
8
- g = prepare_gruff(:side_bar)
8
+ g = instantiate_gruff(:side_bar)
9
9
 
10
10
  columns.each do |column|
11
11
  if column.kind_of?(Array)
@@ -18,10 +18,8 @@ module Chartify
18
18
  end
19
19
 
20
20
  def render_chart(html_dom_id, options = {})
21
- api_name = options[:web_api_name] || config.web_api_name.to_s
22
- class_name = self.class.name.split("::")[1]
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 prepare_gruff(type)
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 = Chartify::Themes::GOOGLE_CHART
53
+ g.theme = config.image_theme
46
54
  g.title = self.title
47
55
  g
48
56
  end
@@ -5,7 +5,7 @@ module Chartify
5
5
  class ColumnChart < ChartBase
6
6
  def to_blob
7
7
  raise 'Need to specify label_column' unless label_column.present?
8
- g = prepare_gruff(:bar)
8
+ g = instantiate_gruff(:bar)
9
9
 
10
10
  columns.each do |column|
11
11
  if column.kind_of?(Array)
@@ -2,7 +2,8 @@ module Chartify
2
2
  class Configuration
3
3
  include ActiveSupport::Configurable
4
4
  config_accessor :web_api_name
5
- config_accessor :chart
5
+ # config_accessor :chart
6
+ config_accessor :image_theme
6
7
 
7
8
  def web(&block)
8
9
  yield @web_config ||= Chartify::WebConfiguration.new
@@ -15,7 +15,7 @@ module Chartify
15
15
  class LineChart < ChartBase
16
16
  def to_blob
17
17
  raise 'Need to specify label_column' unless label_column.present?
18
- g = prepare_gruff(:line)
18
+ g = instantiate_gruff(:line)
19
19
 
20
20
  columns.each do |column|
21
21
  if column.kind_of?(Array)
@@ -16,7 +16,7 @@ module Chartify
16
16
  end
17
17
 
18
18
  def to_blob
19
- g = prepare_gruff(:pie)
19
+ g = instantiate_gruff(:pie)
20
20
 
21
21
  data.each do |row|
22
22
  if row.kind_of?(Array)
@@ -1,3 +1,3 @@
1
1
  module Chartify
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -9,14 +9,11 @@ module Chartify
9
9
 
10
10
  def render(html_dom_id)
11
11
  js = <<-JS
12
- google.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
13
- function drawChart#{timestamp}() {
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
- }
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.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
13
- function drawChart#{timestamp}() {
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
- }
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.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
13
- function drawChart#{timestamp}() {
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
- }
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.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
13
- function drawChart#{timestamp}() {
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
- }
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.insert 0, column_names
18
+ insert_title_row(datasets)
29
19
 
30
20
  js = <<-JS
31
- google.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
32
- function drawChart#{timestamp}() {
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
- }
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.2.2
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-08 00:00:00.000000000 Z
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: A gem to manage online chart so that it can be exportable in image from
146
- ruby code.
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 online chart so that it can be exportable in image from ruby
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: []