mokolabs-googlecharts 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,33 @@
1
+ == 1.3.1
2
+ * added width and spacing options
3
+
4
+ == 1.3.0
5
+ * added support for google-o-meter
6
+ * fixed a bug when the max value of a data set was 0
7
+
8
+ == 1.2.0
9
+ * added support for sparklines
10
+
11
+ == 1.1.0
12
+ * fixed another bug fix related to the uri escaping required to download the file properly.
13
+
14
+ == 1.0.0
15
+ * fixed the (URI::InvalidURIError) issue
16
+
17
+ == 0.2.0
18
+ * added export options (file and image tag)
19
+ * added support for all arguments to be passed as a string or an array
20
+
21
+ == 0.1.0 2007-12-11
22
+ * fixed the axis labels
23
+
24
+ == 0.0.3 2007-12-11
25
+ * added :chart_background alias and fixed a bug related to the background colors.
26
+
27
+ == 0.0.2 2007-12-11
28
+ * added support for more features and aliases
29
+
30
+ == 0.0.1 2007-12-08
31
+
32
+ * 1 major enhancement:
33
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Matt Aimonetti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/gchart.rb
9
+ lib/gchart/aliases.rb
10
+ lib/gchart/version.rb
11
+ setup.rb
12
+ spec/gchart_spec.rb
13
+ spec/spec.opts
14
+ spec/spec_helper.rb
15
+ tasks/environment.rake
16
+ tasks/rspec.rake
data/README.txt ADDED
@@ -0,0 +1,180 @@
1
+ The goal of this Gem is to make the creation of Google Charts a simple and easy task.
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
+
9
+
10
+
11
+ ==Chart Type
12
+
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
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
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/config/hoe.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'gchart/version'
2
+
3
+ AUTHOR = 'Matt Aimonetti' # can also be an array of Authors
4
+ EMAIL = "mattaimonetti@gmail.com"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'googlecharts' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'googlecharts' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "matt_a"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = GchartInfo::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'gchart documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile could use '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ end
12
+ end
13
+
14
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
15
+
16
+ require 'gchart'
@@ -0,0 +1,14 @@
1
+ class Gchart
2
+
3
+ alias_method :background=, :bg=
4
+ alias_method :chart_bg=, :graph_bg=
5
+ alias_method :chart_color=, :graph_bg=
6
+ alias_method :chart_background=, :graph_bg=
7
+ alias_method :bar_color=, :bar_colors=
8
+ alias_method :line_colors=, :bar_colors=
9
+ alias_method :line_color=, :bar_colors=
10
+ alias_method :labels=, :legend=
11
+ alias_method :horizontal?, :horizontal
12
+ alias_method :grouped?, :grouped
13
+
14
+ end
@@ -0,0 +1,9 @@
1
+ module GchartInfo #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 3
5
+ TINY = 2
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end