googlecharts 1.3.1 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1,4 +1,4 @@
1
- 
2
- ��l-��,��/�!�m�V�Gj�ޙ�=�ea�z�����F����h�)�X�u:i��Z��Զy�~�F�O5m��|�7��!��/'��k������f�%���*���R�sk���H�$�dϞnw��5���
3
- *U�Ìq��^�� m��
4
- 5��C8gB!�i����u��Kj�|�bD��C!��
1
+ {�(�
2
+ �����?������~^��k�
3
+ �H��с7���j����J� �1)F��XC��ږ����c̘<9a�9�p�t5K�p �5��`�сb II�3��F鐫ﶫ_ ��bl&`=�; ����I#�3Zd�@�sx�ޭa��^#'�z�2O������1��̀�>�s��|�
4
+ �bw���\"Lڇ�j <���K��ynv�9d`~��G��Y�
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.3.4
2
+ * updated documentation and cleaned it up (mokolabs)
3
+ * added support for custom class, id and alt tags when using the image_tag format (i.e Gchart.line(:data => [0, 26], :format => 'image_tag')) (mokolabs)
4
+
5
+ == 1.3.2 - 1.3.3
6
+ * changes required by github
7
+
1
8
  == 1.3.1
2
9
  * added width and spacing options
3
10
 
data/Manifest.txt CHANGED
@@ -8,20 +8,9 @@ config/requirements.rb
8
8
  lib/gchart.rb
9
9
  lib/gchart/aliases.rb
10
10
  lib/gchart/version.rb
11
- log/debug.log
12
- script/destroy
13
- script/generate
14
- script/txt2html
15
11
  setup.rb
16
12
  spec/gchart_spec.rb
17
13
  spec/spec.opts
18
14
  spec/spec_helper.rb
19
- tasks/deployment.rake
20
15
  tasks/environment.rake
21
16
  tasks/rspec.rake
22
- tasks/website.rake
23
- website/index.html
24
- website/index.txt
25
- website/javascripts/rounded_corners_lite.inc.js
26
- website/stylesheets/screen.css
27
- website/template.rhtml
data/README.txt CHANGED
@@ -1,180 +1,9 @@
1
- The goal of this Gem is to make the creation of Google Charts a simple and easy task.
1
+ CHECK README.markdown (open as a text file)
2
2
 
3
- Gchart.line( :size => '200x300',
4
- :title => "example title",
5
- :bg => 'efefef',
6
- :legend => ['first data set label', 'second data set label'],
7
- :data => [10, 30, 120, 45, 72])
8
-
3
+ Or check:
9
4
 
5
+ http://googlecharts.rubyforge.org
10
6
 
11
- ==Chart Type
7
+ and/or
12
8
 
13
- This gem supports the following types of charts:
14
-
15
- * line,
16
- * line_xy
17
- * sparkline
18
- * scatter
19
- * bar
20
- * venn
21
- * pie
22
- * pie_3d
23
-
24
- To create a chart, simply require Gchart and call any of the existing type:
25
-
26
- require 'gchart'
27
- Gchart.pie
28
-
29
-
30
- ==Chart Title
31
-
32
- To add a title to a chart pass the title to your chart:
33
-
34
- Gchart.line(:title => 'Sexy Charts!')
35
-
36
- You can also specify the color and/or size
37
-
38
- Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20')
39
-
40
- ==Colors
41
-
42
- Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example:
43
-
44
- * FF0000 = red
45
- * 00FF00 = green
46
- * 0000FF = blue
47
- * 000000 = black
48
- * FFFFFF = white
49
-
50
- You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example:
51
-
52
- * 0000FFFF = solid blue
53
- * 0000FF00 = transparent blue
54
-
55
- If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00'
56
-
57
- Some charts have more options than other, make sure to refer to the documentation.
58
-
59
- ===Background options:
60
-
61
- If you don't set the background option, your graph will be transparent.
62
-
63
- * You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill
64
-
65
- - solid
66
- - gradient
67
- - stripes
68
-
69
- By default, if you set a background color, the fill will be solid:
70
-
71
- Gchart.bar(:bg => 'efefef')
72
-
73
- However you can specify another fill type such as:
74
-
75
- Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'})
76
-
77
- In the above code, we decided to have a gradient background, however since we only passed one color, the chart will start by the specified color and transition to white. By the default, the gradient angle is 0. Change it as follows:
78
-
79
- Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90})
80
-
81
- For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient
82
-
83
- Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'})
84
-
85
-
86
- The same way you set the background color, you can also set the graph background:
87
-
88
- Gchart.line(:graph_bg => 'cccccc')
89
-
90
- or both
91
-
92
- Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart')
93
-
94
-
95
- Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes
96
-
97
- Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'})
98
-
99
- You can customize the amount of stripes, colors and width by changing the color value.
100
-
101
-
102
- == Legend & Labels
103
-
104
- You probably will want to use a legend or labels for your graph.
105
-
106
- Gchart.line(:legend => 'legend label')
107
- or
108
- Gchart.line(:legend => ['legend label 1', 'legend label 2'])
109
-
110
- Will do the trick. You can also use the labels alias (makes more sense when using the pie charts)
111
-
112
- chart = Gchart.pie(:labels => ['label 1', 'label 2'])
113
-
114
- == Multiple axis labels
115
-
116
- Multiple axis labels are available for line charts, bar charts and scatter plots.
117
-
118
- * x = bottom x-axis
119
- * t = top x-axis
120
- * y = left y-axis
121
- * r = right y-axis
122
-
123
- Gchart.line(:label_axis => 'x,y,r')
124
-
125
- To add labels on these axis:
126
-
127
- Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007'])
128
-
129
-
130
- == Data options
131
-
132
- Data are passed using an array or a nested array.
133
-
134
- Gchart.bar(:data => [1,2,4,67,100,41,234])
135
-
136
- Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]])
137
-
138
- By default, the graph is drawn with your max value representing 100% of the height or width of the graph. You can change that my passing the max value.
139
-
140
- Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300)
141
- Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto')
142
-
143
- or if you want to use the real values from your dataset:
144
-
145
- Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false)
146
-
147
-
148
- You can also define a different encoding to add more granularity:
149
-
150
- Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple')
151
- Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended')
152
- Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text')
153
-
154
-
155
- ==Pies:
156
-
157
- you have 2 type of pies:
158
- - Gchart.pie() the standard 2D pie
159
- _ Gchart.pie_3d() the fancy 3D pie
160
-
161
- To set labels, you can use one of these two options:
162
-
163
- @legend = ['Matt_fu', 'Rob_fu']
164
- Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200')
165
- Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200')
166
-
167
-
168
-
169
- === try yourself
170
-
171
- Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]],
172
- :title => 'SDRuby Fu level',
173
- :legend => ['matt','patrick'],
174
- :bg => {:color => '76A4FB', :type => 'gradient'},
175
- :bar_colors => 'ff0000,00ff00')
176
-
177
- "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"
178
-
179
- Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan'])
180
- http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
9
+ http://github.com/mattetti/googlecharts
data/Rakefile CHANGED
@@ -1,4 +1,32 @@
1
1
  require 'config/requirements'
2
2
  require 'config/hoe' # setup Hoe + all gem configuration
3
3
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
5
+
6
+ desc %{Update ".manifest" with the latest list of project filenames. Respect\
7
+ .gitignore by excluding everything that git ignores. Update `files` and\
8
+ `test_files` arrays in "*.gemspec" file if it's present.}
9
+ task :manifest do
10
+ list = Dir['**/*'].sort
11
+ spec_file = Dir['*.gemspec'].first
12
+ list -= [spec_file] if spec_file
13
+
14
+ File.read('.gitignore').each_line do |glob|
15
+ glob = glob.chomp.sub(/^\//, '')
16
+ list -= Dir[glob]
17
+ list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
18
+ puts "excluding #{glob}"
19
+ end
20
+
21
+ if spec_file
22
+ spec = File.read spec_file
23
+ spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
24
+ assignment = $1
25
+ bunch = $2 ? list.grep(/^test\//) : list
26
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
27
+ end
28
+
29
+ File.open(spec_file, 'w') {|f| f << spec }
30
+ end
31
+ File.open('.manifest', 'w') {|f| f << list.join("\n") }
32
+ end
data/lib/gchart.rb CHANGED
@@ -15,27 +15,24 @@ class Gchart
15
15
  @@file_name = 'chart.png'
16
16
 
17
17
  attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
18
- :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing
18
+ :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :class
19
19
 
20
- class << self
21
- # Support for Gchart.line(:title => 'my title', :size => '400x600')
22
- def method_missing(m, options={})
23
- # Extract the format and optional filename, then clean the hash
24
- format = options[:format] || 'url'
25
- @@file_name = options[:filename] unless options[:filename].nil?
26
- options.delete(:format)
27
- options.delete(:filename)
28
- # create the chart and return it in the format asked for
29
- if @@types.include?(m.to_s)
30
- chart = new(options.merge!({:type => m}))
31
- chart.send(format)
32
- elsif m.to_s == 'version'
33
- Gchart::VERSION::STRING
34
- else
35
- "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
36
- end
37
- end
38
-
20
+ # Support for Gchart.line(:title => 'my title', :size => '400x600')
21
+ def self.method_missing(m, options={})
22
+ # Extract the format and optional filename, then clean the hash
23
+ format = options[:format] || 'url'
24
+ @@file_name = options[:filename] unless options[:filename].nil?
25
+ options.delete(:format)
26
+ options.delete(:filename)
27
+ # create the chart and return it in the format asked for
28
+ if @@types.include?(m.to_s)
29
+ chart = new(options.merge!({:type => m}))
30
+ chart.send(format)
31
+ elsif m.to_s == 'version'
32
+ Gchart::VERSION::STRING
33
+ else
34
+ "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
35
+ end
39
36
  end
40
37
 
41
38
  def initialize(options={})
@@ -47,6 +44,12 @@ class Gchart
47
44
  @grouped = false
48
45
  @encoding = 'simple'
49
46
  @max_value = 'auto'
47
+ # Sets the alt tag when chart is exported as image tag
48
+ @alt = 'Google Chart'
49
+ # Sets the CSS id selector when chart is exported as image tag
50
+ @id = false
51
+ # Sets the CSS class selector when chart is exported as image tag
52
+ @class = false
50
53
 
51
54
  # set the options value if definable
52
55
  options.each do |attribute, value|
@@ -123,10 +126,20 @@ class Gchart
123
126
 
124
127
  # Format
125
128
 
126
- def img_tag
127
- "<img src='#{query_builder}'/>"
129
+ def image_tag
130
+ image = "<img"
131
+ image += " id=\"#{@id}\"" if @id
132
+ image += " class=\"#{@class}\"" if @class
133
+ image += " src=\"#{query_builder}\""
134
+ image += " width=\"#{@width}\""
135
+ image += " height=\"#{@height}\""
136
+ image += " alt=\"#{@alt}\""
137
+ image += " title=\"#{@title}\"" if @title
138
+ image += " />"
128
139
  end
129
140
 
141
+ alias_method :img_tag, :image_tag
142
+
130
143
  def url
131
144
  query_builder
132
145
  end
@@ -2,7 +2,7 @@ module GchartInfo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 3
5
- TINY = 1
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/spec/gchart_spec.rb CHANGED
@@ -377,10 +377,34 @@ describe 'exporting a chart' do
377
377
  Gchart.line(:data => [0, 26], :format => 'url').should == Gchart.line(:data => [0, 26])
378
378
  end
379
379
 
380
- it "should be available as the img tag" do
381
- Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*)\/>/)
380
+ it "should be available as an image tag" do
381
+ Gchart.line(:data => [0, 26], :format => 'image_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/)
382
382
  end
383
383
 
384
+ it "should be available as an image tag using img_tag alias" do
385
+ Gchart.line(:data => [0, 26], :format => 'img_tag').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" \/>/)
386
+ end
387
+
388
+ it "should be available as an image tag using custom dimensions" do
389
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :size => '400x400').should match(/<img src=(.*) width="400" height="400" alt="Google Chart" \/>/)
390
+ end
391
+
392
+ it "should be available as an image tag using custom alt text" do
393
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :alt => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Sexy chart" \/>/)
394
+ end
395
+
396
+ it "should be available as an image tag using custom title text" do
397
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :title => 'Sexy chart').should match(/<img src=(.*) width="300" height="200" alt="Google Chart" title="Sexy chart" \/>/)
398
+ end
399
+
400
+ it "should be available as an image tag using custom css id selector" do
401
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :id => 'chart').should match(/<img id="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
402
+ end
403
+
404
+ it "should be available as an image tag using custom css class selector" do
405
+ Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
406
+ end
407
+
384
408
  it "should be available as a file" do
385
409
  File.delete('chart.png') if File.exist?('chart.png')
386
410
  Gchart.line(:data => [0, 26], :format => 'file')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlecharts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Aimonetti
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ZR7qHIpykzr3ezcNiWtBWw==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-05-08 00:00:00 -07:00
33
+ date: 2008-06-26 00:00:00 -07:00
34
34
  default_executable:
35
35
  dependencies: []
36
36
 
@@ -45,7 +45,6 @@ extra_rdoc_files:
45
45
  - License.txt
46
46
  - Manifest.txt
47
47
  - README.txt
48
- - website/index.txt
49
48
  files:
50
49
  - History.txt
51
50
  - License.txt
@@ -57,23 +56,12 @@ files:
57
56
  - lib/gchart.rb
58
57
  - lib/gchart/aliases.rb
59
58
  - lib/gchart/version.rb
60
- - log/debug.log
61
- - script/destroy
62
- - script/generate
63
- - script/txt2html
64
59
  - setup.rb
65
60
  - spec/gchart_spec.rb
66
61
  - spec/spec.opts
67
62
  - spec/spec_helper.rb
68
- - tasks/deployment.rake
69
63
  - tasks/environment.rake
70
64
  - tasks/rspec.rake
71
- - tasks/website.rake
72
- - website/index.html
73
- - website/index.txt
74
- - website/javascripts/rounded_corners_lite.inc.js
75
- - website/stylesheets/screen.css
76
- - website/template.rhtml
77
65
  has_rdoc: true
78
66
  homepage: http://googlecharts.rubyforge.org
79
67
  post_install_message:
@@ -97,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
85
  requirements: []
98
86
 
99
87
  rubyforge_project: googlecharts
100
- rubygems_version: 1.1.1
88
+ rubygems_version: 1.2.0
101
89
  signing_key:
102
90
  specification_version: 2
103
91
  summary: description of gem