googlecharts 1.6.8 → 1.6.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa6cc0f0e71b51d4dcc1583a1b0a14b4015a41e3
4
+ data.tar.gz: 083b34ae2a25223b6c56d8a0b9ceefb665e95597
5
+ SHA512:
6
+ metadata.gz: f68d4956480164bcee5e66c5d3de359023e355e21a9079b5318f740b321706969040ecfd1236c778e365330da55dc65292fa1bf6774262dab66fff111d29f2c5
7
+ data.tar.gz: e972de17e3f51432b417394d83ab2dd4a715c958bf7bd9c50d2eb3cd43f18bcfd8d6cbd634a23c91377b5c4253923211b5edf5b39e1395e338fbcb12d519968b
data/.gitignore CHANGED
@@ -1,4 +1,7 @@
1
1
  .DS_Store
2
2
  log/*
3
3
  .manifest
4
- pkg
4
+ pkg
5
+ .rspec
6
+ .rvmrc
7
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - ree
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ group :test do
5
+ gem 'rspec'
6
+ gem 'rake', '>= 0.8.7'
7
+ end
8
+
9
+
10
+
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 1.6.12
2
+ * added license to gemspec
3
+ * added pie_c type for concentric pie charts
4
+
5
+ == 1.6.10
6
+ * added support for custom position on axis with label (parameter chxp)
7
+ * refactored bar chart
8
+ * fixed issue #44
9
+ * allows GChart to take a theme
10
+
1
11
  == 1.6.8
2
12
  * added title alignment support
3
13
 
data/README.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ ## Googlecharts
2
+
3
+ [![Build Status](https://travis-ci.org/mattetti/googlecharts.png?branch=master)](https://travis-ci.org/mattetti/googlecharts)
4
+
1
5
  The goal of this Gem is to make the creation of Google Charts a simple and easy task.
2
6
 
3
7
  require 'googlecharts'
@@ -291,6 +295,7 @@ Multi Lines Chart Sample :
291
295
 
292
296
  chart = Gchart.new( :type => 'line',
293
297
  :title => "example title",
298
+ :theme => :keynote,
294
299
  :data => [[17, 17, 11, 8, 2],[10, 20, 15, 5, 7],[2, 3, 7, 9, 12]],
295
300
  :line_colors => 'e0440e,e62ae5,287eec',
296
301
  :legend => ['courbe 1','courbe 2','courbe 3'],
@@ -313,4 +318,4 @@ try yourself
313
318
  "http://chart.apis.google.com/chart?chs=300x200&chdl=matt|patrick&chd=s:AAANUIv,JENCN9y&chtt=SDRuby+Fu+level&chf=bg,lg,0,76A4FB,0,ffffff,1&cht=bvs&chco=ff0000,00ff00"
314
319
 
315
320
  Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan'])
316
- http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
321
+ http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
- require 'rubygems'
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc 'Default: run specs.'
4
+ task :default => :spec
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new do |task|
8
+ task.pattern = "**/spec/*_spec.rb"
9
+ task.rspec_opts = []
10
+ task.rspec_opts << '--color'
11
+ task.rspec_opts << '-f documentation'
12
+ end
data/googlecharts.gemspec CHANGED
@@ -6,12 +6,13 @@ Gem::Specification.new do |s|
6
6
  s.name = %q{googlecharts}
7
7
  s.version = GchartInfo::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Matt Aimonetti", "Andrey Deryabin"]
10
- s.date = %q{2011-05-21}
9
+ s.authors = ["Matt Aimonetti", "Andrey Deryabin", "Pedro Pimentel"]
10
+ s.date = %q{2015-08-12}
11
11
  s.summary = %q{Generate charts using Google API & Ruby}
12
12
  s.description = %q{Generate charts using Google API & Ruby}
13
- s.email = %q{mattaimonetti@gmail.com deriabin@gmail.com}
13
+ s.email = %q{mattaimonetti@gmail.com deriabin@gmail.com zukunft@gmail.com}
14
14
  s.homepage = %q{http://googlecharts.rubyforge.org/}
15
+ s.license = 'MIT'
15
16
 
16
17
  s.files = `git ls-files`.split("\n")
17
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -9,7 +9,6 @@ class Gchart
9
9
  alias_method :line_color=, :bar_colors=
10
10
  alias_method :slice_colors=, :bar_colors=
11
11
  alias_method :horizontal?, :horizontal
12
- alias_method :grouped?, :grouped
13
12
  alias_method :curved?, :curved
14
13
 
15
14
  end
@@ -1,3 +1,3 @@
1
1
  module GchartInfo #:nodoc:
2
- VERSION = "1.6.8"
2
+ VERSION = "1.6.12"
3
3
  end
data/lib/gchart.rb CHANGED
@@ -19,7 +19,7 @@ class Gchart
19
19
  end
20
20
 
21
21
  def self.types
22
- @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'jstize', 'sparkline', 'meter', 'map', 'radar']
22
+ @types ||= ['line', 'line_xy', 'scatter', 'bar', 'venn', 'pie', 'pie_3d', 'pie_c', 'jstize', 'sparkline', 'meter', 'map', 'radar']
23
23
  end
24
24
 
25
25
  def self.simple_chars
@@ -38,14 +38,14 @@ class Gchart
38
38
  'chart.png'
39
39
  end
40
40
 
41
- attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :legend, :legend_position, :labels, :data, :encoding, :bar_colors,
42
- :title_color, :title_size, :title_alignment, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass,
41
+ attr_accessor :title, :type, :width, :height, :curved, :horizontal, :grouped, :overlapped, :legend, :legend_position, :labels, :data, :encoding, :bar_colors,
42
+ :title_color, :title_size, :title_alignment, :custom, :axis_with_labels, :custom_axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :klass,
43
43
  :range_markers, :geographical_area, :map_colors, :country_codes, :axis_range, :filename, :min, :max, :colors, :usemap
44
44
 
45
45
  attr_accessor :bg_type, :bg_color, :bg_angle, :chart_type, :chart_color, :chart_angle, :axis_range, :thickness, :new_markers, :grid_lines, :use_ssl
46
46
 
47
47
  attr_accessor :min_value, :max_value
48
-
48
+
49
49
  types.each do |type|
50
50
  instance_eval <<-DYNCLASSMETH
51
51
  def #{type}(options = {})
@@ -73,13 +73,21 @@ class Gchart
73
73
  end
74
74
 
75
75
  def initialize(options={})
76
+ # Allow Gchart to take a theme too
77
+ @theme = options[:theme]
78
+ options = @theme ? Chart::Theme.load(@theme).to_options.merge(options) : options
79
+ options.delete(:theme)
80
+
76
81
  @type = options[:type] || 'line'
77
82
  @data = []
78
83
  @width = 300
79
84
  @height = 200
80
85
  @curved = false
81
86
  @horizontal = false
87
+
82
88
  @grouped = false
89
+ @overlapped = false
90
+
83
91
  @use_ssl = false
84
92
  @encoding = 'simple'
85
93
  # @max_value = 'auto'
@@ -106,11 +114,11 @@ class Gchart
106
114
  def size=(size='300x200')
107
115
  @width, @height = size.split("x").map { |dimension| dimension.to_i }
108
116
  end
109
-
117
+
110
118
  def size
111
119
  "#{width}x#{height}"
112
120
  end
113
-
121
+
114
122
  def dimensions
115
123
  # TODO: maybe others?
116
124
  [:line_xy, :scatter].include?(type) ? 2 : 1
@@ -125,9 +133,14 @@ class Gchart
125
133
  end
126
134
  end
127
135
 
128
- # Sets the bar graph presentation (stacked or grouped)
129
- def stacked=(option=true)
130
- @grouped = option ? false : true
136
+ def bar_presentation
137
+ if @overlapped
138
+ 'o'
139
+ elsif @grouped
140
+ 'g'
141
+ else
142
+ 's'
143
+ end
131
144
  end
132
145
 
133
146
  def bg=(options)
@@ -149,7 +162,7 @@ class Gchart
149
162
  @chart_angle = options[:angle]
150
163
  end
151
164
  end
152
-
165
+
153
166
  def max_value=(max_v)
154
167
  if max_v =~ /false/
155
168
  @max_value = false
@@ -174,7 +187,7 @@ class Gchart
174
187
  ds.each_with_index do |mds, mds_index|
175
188
  mds[:min_value] ||= min_value
176
189
  mds[:max_value] ||= max_value
177
-
190
+
178
191
  if mds_index == 0 && type.to_s == 'bar'
179
192
  # TODO: unless you specify a zero line (using chp or chds),
180
193
  # the min_value of a bar chart is always 0.
@@ -235,7 +248,7 @@ class Gchart
235
248
  @dataset
236
249
  end
237
250
  end
238
-
251
+
239
252
  # Sets of data to handle multiple sets
240
253
  def datasets
241
254
  datasets = []
@@ -248,7 +261,7 @@ class Gchart
248
261
  end
249
262
  datasets
250
263
  end
251
-
264
+
252
265
  def self.jstize(string)
253
266
  # See http://github.com/mattetti/googlecharts/issues#issue/27
254
267
  #URI.escape( string ).gsub("%7C", "|")
@@ -313,7 +326,7 @@ class Gchart
313
326
  # The title size cannot be set without specifying a color.
314
327
  # A dark key will be used for the title color if no color is specified
315
328
  def set_title
316
- title_params = "chtt=#{title}"
329
+ title_params = "chtt=#{title}".gsub(/\|/,"\n")
317
330
  unless (title_color.nil? && title_size.nil? && title_alignment.nil?)
318
331
  title_params << "&chts=" + (color, size, alignment = (title_color || '454545'), title_size, (title_alignment.to_s[0,1] || 'c')).compact.join(',')
319
332
  end
@@ -460,6 +473,11 @@ class Gchart
460
473
  "chxt=#{axis_with_labels}"
461
474
  end
462
475
 
476
+ def set_custom_axis_with_labels
477
+ @custom_axis_with_labels = custom_axis_with_labels.join(',') if @custom_axis_with_labels.is_a?(Array)
478
+ "chxp=#{custom_axis_with_labels}"
479
+ end
480
+
463
481
  def set_axis_labels
464
482
  if axis_labels.is_a?(Array)
465
483
  if RUBY_VERSION.to_f < 1.9
@@ -510,6 +528,7 @@ class Gchart
510
528
  when 'line' then "lc"
511
529
  when 'line_xy' then "lxy"
512
530
  when 'pie_3d' then "p3"
531
+ when 'pie_c' then "pc"
513
532
  when 'pie' then "p"
514
533
  when 'venn' then "v"
515
534
  when 'scatter' then "s"
@@ -519,7 +538,7 @@ class Gchart
519
538
  when 'radar'
520
539
  "r" + (curved? ? 's' : '')
521
540
  when 'bar'
522
- "b" + (horizontal? ? "h" : "v") + (grouped? ? "g" : "s")
541
+ "b" + (horizontal? ? "h" : "v") + bar_presentation
523
542
  end
524
543
  end
525
544
 
@@ -530,7 +549,7 @@ class Gchart
530
549
  when 'stripes' then 'ls'
531
550
  end
532
551
  end
533
-
552
+
534
553
  def number_visible
535
554
  n = 0
536
555
  dataset.each do |mds|
@@ -543,7 +562,7 @@ class Gchart
543
562
  end
544
563
  ""
545
564
  end
546
-
565
+
547
566
  # Turns input into an array of axis hashes, dependent on the chart type
548
567
  def convert_dataset(ds)
549
568
  if dimensions == 2
@@ -563,7 +582,7 @@ class Gchart
563
582
  end
564
583
  ds
565
584
  end
566
-
585
+
567
586
  # just an alias
568
587
  def axis_set
569
588
  dataset
@@ -577,7 +596,7 @@ class Gchart
577
596
  value.nil? ? "_" : value
578
597
  end
579
598
  end
580
-
599
+
581
600
  def convert_to_extended_value(number)
582
601
  if number.nil?
583
602
  '__'
@@ -586,7 +605,7 @@ class Gchart
586
605
  value.nil? ? "__" : value
587
606
  end
588
607
  end
589
-
608
+
590
609
  def encode_scaled_dataset(chars, nil_char)
591
610
  dsets = []
592
611
  dataset.each do |ds|
@@ -655,6 +674,7 @@ class Gchart
655
674
  def query_builder(options="")
656
675
  query_params = instance_variables.sort.map do |var|
657
676
  case var.to_s
677
+
658
678
  when '@data'
659
679
  set_data unless data == []
660
680
  # Set the graph size
@@ -673,7 +693,7 @@ class Gchart
673
693
  when '@thickness'
674
694
  set_line_thickness
675
695
  when '@new_markers'
676
- set_line_markers
696
+ set_line_markers
677
697
  when '@bg_color'
678
698
  set_colors
679
699
  when '@chart_color'
@@ -690,6 +710,8 @@ class Gchart
690
710
  set_range_markers
691
711
  when '@grid_lines'
692
712
  set_grid_lines
713
+ when '@custom_axis_with_labels'
714
+ set_custom_axis_with_labels
693
715
  when '@geographical_area'
694
716
  set_geographical_area
695
717
  when '@country_codes'