Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Apr 27, 2008
1 parent 4453b35 commit 79bbafd
Show file tree
Hide file tree
Showing 27 changed files with 4,272 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
log/*
21 changes: 21 additions & 0 deletions History.txt
@@ -0,0 +1,21 @@
== 1.1.0
* fixed another bug fix related to the uri escaping required to download the file properly.
== 1.0.0
* fixed the (URI::InvalidURIError) issue
== 0.2.0
* added export options (file and image tag)
* added support for all arguments to be passed as a string or an array

== 0.1.0 2007-12-11
* fixed the axis labels

== 0.0.3 2007-12-11
* added :chart_background alias and fixed a bug related to the background colors.

== 0.0.2 2007-12-11
* added support for more features and aliases

== 0.0.1 2007-12-08

* 1 major enhancement:
* Initial release
20 changes: 20 additions & 0 deletions License.txt
@@ -0,0 +1,20 @@
Copyright (c) 2007 Matt Aimonetti

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions Manifest.txt
@@ -0,0 +1,27 @@
History.txt
License.txt
Manifest.txt
README.txt
Rakefile
config/hoe.rb
config/requirements.rb
lib/gchart.rb
lib/gchart/aliases.rb
lib/gchart/version.rb
log/debug.log
script/destroy
script/generate
script/txt2html
setup.rb
spec/gchart_spec.rb
spec/spec.opts
spec/spec_helper.rb
tasks/deployment.rake
tasks/environment.rake
tasks/rspec.rake
tasks/website.rake
website/index.html
website/index.txt
website/javascripts/rounded_corners_lite.inc.js
website/stylesheets/screen.css
website/template.rhtml
179 changes: 179 additions & 0 deletions README.txt
@@ -0,0 +1,179 @@
The goal of this Gem is to make the creation of Google Charts a simple and easy task.

Gchart.line( :size => '200x300',
:title => "example title",
:bg => 'efefef',
:legend => ['first data set label', 'second data set label'],
:data => [10, 30, 120, 45, 72])



==Chart Type

This gem supports the following types of charts:

* line,
* line_xy
* scatter
* bar
* venn
* pie
* pie_3d

To create a chart, simply require Gchart and call any of the existing type:

require 'gchart'
Gchart.pie


==Chart Title

To add a title to a chart pass the title to your chart:

Gchart.line(:title => 'Sexy Charts!')

You can also specify the color and/or size

Gchart.line(:title => 'Sexy Charts!', :title_color => 'FF0000', :title_size => '20')

==Colors

Specify a color with at least a 6-letter string of hexadecimal values in the format RRGGBB. For example:

* FF0000 = red
* 00FF00 = green
* 0000FF = blue
* 000000 = black
* FFFFFF = white

You can optionally specify transparency by appending a value between 00 and FF where 00 is completely transparent and FF completely opaque. For example:

* 0000FFFF = solid blue
* 0000FF00 = transparent blue

If you need to use multiple colors, check the doc. Usually you just need to pass :attribute => 'FF0000,00FF00'

Some charts have more options than other, make sure to refer to the documentation.

===Background options:

If you don't set the background option, your graph will be transparent.

* You have 3 types of background http://code.google.com/apis/chart/#chart_or_background_fill

- solid
- gradient
- stripes

By default, if you set a background color, the fill will be solid:

Gchart.bar(:bg => 'efefef')

However you can specify another fill type such as:

Gchart.line(:bg => {:color => 'efefef', :type => 'gradient'})

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:

Gchart.line(:title =>'bg example', :bg => {:color => 'efefef', :type => 'gradient', :angle => 90})

For a more advance use of colors, refer to http://code.google.com/apis/chart/#linear_gradient

Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'})


The same way you set the background color, you can also set the graph background:

Gchart.line(:graph_bg => 'cccccc')

or both

Gchart.line(:bg => {:color => '76A4FB,1,ffffff,0', :type => 'gradient'}, :graph_bg => 'cccccc', :title => 'Sexy Chart')


Another type of fill is stripes http://code.google.com/apis/chart/#linear_stripes

Gchart.line(:bg => {:color => 'efefef', :type => 'stripes'})

You can customize the amount of stripes, colors and width by changing the color value.


== Legend & Labels

You probably will want to use a legend or labels for your graph.

Gchart.line(:legend => 'legend label')
or
Gchart.line(:legend => ['legend label 1', 'legend label 2'])

Will do the trick. You can also use the labels alias (makes more sense when using the pie charts)

chart = Gchart.pie(:labels => ['label 1', 'label 2'])

== Multiple axis labels

Multiple axis labels are available for line charts, bar charts and scatter plots.

* x = bottom x-axis
* t = top x-axis
* y = left y-axis
* r = right y-axis

Gchart.line(:label_axis => 'x,y,r')

To add labels on these axis:

Gchart.line(:axis_labels => ['Jan|July|Jan|July|Jan', '0|100', 'A|B|C', '2005|2006|2007'])


== Data options

Data are passed using an array or a nested array.

Gchart.bar(:data => [1,2,4,67,100,41,234])

Gchart.bar(:data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]])

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.

Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 300)
Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => 'auto')

or if you want to use the real values from your dataset:

Gchart.bar(:data => [1,2,4,67,100,41,234], :max_value => false)


You can also define a different encoding to add more granularity:

Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'simple')
Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'extended')
Gchart.bar(:data => [1,2,4,67,100,41,234], :encoding => 'text')


==Pies:

you have 2 type of pies:
- Gchart.pie() the standard 2D pie
_ Gchart.pie_3d() the fancy 3D pie

To set labels, you can use one of these two options:

@legend = ['Matt_fu', 'Rob_fu']
Gchart.pie_3d(:title => @title, :labels => @legend, :data => @data, :size => '400x200')
Gchart.pie_3d(:title => @title, :legend => @legend, :data => @data, :size => '400x200')



=== try yourself

Gchart.bar( :data => [[1,2,4,67,100,41,234],[45,23,67,12,67,300, 250]],
:title => 'SDRuby Fu level',
:legend => ['matt','patrick'],
:bg => {:color => '76A4FB', :type => 'gradient'},
:bar_colors => 'ff0000,00ff00')

"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"

Gchart.pie(:data => [20,10,15,5,50], :title => 'SDRuby Fu level', :size => '400x200', :labels => ['matt', 'rob', 'patrick', 'ryan', 'jordan'])
http://chart.apis.google.com/chart?cht=p&chs=400x200&chd=s:YMSG9&chtt=SDRuby+Fu+level&chl=matt|rob|patrick|ryan|jordan
4 changes: 4 additions & 0 deletions Rakefile
@@ -0,0 +1,4 @@
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration

Dir['tasks/**/*.rake'].each { |rake| load rake }
71 changes: 71 additions & 0 deletions config/hoe.rb
@@ -0,0 +1,71 @@
require 'gchart/version'

AUTHOR = 'Matt Aimonetti' # can also be an array of Authors
EMAIL = "mattaimonetti@gmail.com"
DESCRIPTION = "description of gem"
GEM_NAME = 'googlecharts' # what ppl will type to install your gem
RUBYFORGE_PROJECT = 'googlecharts' # The unix name for your project
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"

@config_file = "~/.rubyforge/user-config.yml"
@config = nil
RUBYFORGE_USERNAME = "matt_a"
def rubyforge_username
unless @config
begin
@config = YAML.load(File.read(File.expand_path(@config_file)))
rescue
puts <<-EOS
ERROR: No rubyforge config file found: #{@config_file}
Run 'rubyforge setup' to prepare your env for access to Rubyforge
- See http://newgem.rubyforge.org/rubyforge.html for more details
EOS
exit
end
end
RUBYFORGE_USERNAME.replace @config["username"]
end


REV = nil
# UNCOMMENT IF REQUIRED:
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
VERS = GchartInfo::VERSION::STRING + (REV ? ".#{REV}" : "")
RDOC_OPTS = ['--quiet', '--title', 'gchart documentation',
"--opname", "index.html",
"--line-numbers",
"--main", "README",
"--inline-source"]

class Hoe
def extra_deps
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
@extra_deps
end
end

# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
hoe = Hoe.new(GEM_NAME, VERS) do |p|
p.author = AUTHOR
p.description = DESCRIPTION
p.email = EMAIL
p.summary = DESCRIPTION
p.url = HOMEPATH
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
p.test_globs = ["test/**/test_*.rb"]
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.

# == Optional
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]

#p.spec_extras = {} # A hash of extra values to set in the gemspec.

end

CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
hoe.rsync_args = '-av --delete --ignore-errors'
16 changes: 16 additions & 0 deletions config/requirements.rb
@@ -0,0 +1,16 @@
require 'fileutils'
include FileUtils

require 'rubygems'
%w[rake hoe newgem rubigen].each do |req_gem|
begin
require req_gem
rescue LoadError
puts "This Rakefile could use '#{req_gem}' RubyGem."
puts "Installation: gem install #{req_gem} -y"
end
end

$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))

require 'gchart'

0 comments on commit 79bbafd

Please sign in to comment.