Skip to content
Browse files

Improved README a bit, implemented fetch and write.

git-svn-id: http://gchart.rubyforge.org/svn/trunk@7 97666ce3-63e7-4ded-9107-7b9b1732aa72
  • Loading branch information...
1 parent 43efd4b commit 80211423d68375422b66ffd74a05fc32090d6b8d jbarnette committed Dec 10, 2007
Showing with 40 additions and 14 deletions.
  1. +2 −0 .gitignore
  2. +1 −1 CHANGELOG.txt
  3. +21 −1 README.txt
  4. +15 −11 lib/gchart.rb
  5. +1 −1 lib/version.rb
View
2 .gitignore
@@ -1,2 +1,4 @@
.DS_Store
+doc
+pkg
View
2 CHANGELOG.txt
@@ -1,3 +1,3 @@
-== 1.0.0
+== 0.1.0
* Birthday!
View
22 README.txt
@@ -12,7 +12,27 @@ a friendly Ruby interface. It can generate the URL for a given chart
== SYNOPSIS:
- FIX (code sample of usage)
+ # line chart
+ g = GChart.line(:data => [0, 10, 100])
+
+ # bar chart
+ g = GChart.bar(:data => [100, 1000, 10000])
+
+ # pie chart
+ g = GChart.pie(:data => [33, 33, 34])
+
+ # venn diagram (asize, bsize, csize, ab, bc, ca, abc)
+ g = GChart.venn(:data => [100, 80, 60, 30, 30, 30, 10])
+
+ # scatter plot (list of x coords, list of y coords, optional sizes)
+ g = GChart.scatter(:data => [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]])
+
+ # chart title
+ g = GChart.line(:title => "Awesomeness over Time", :data => [0, 10, 100])
+
+ g.to_url # generate the chart's URL, or
+ g.fetch # get the PNG bytes, or
+ g.write("foo.png") # write to a file or IO object (defaults to "chart.png")
== REQUIREMENTS:
View
26 lib/gchart.rb
@@ -1,4 +1,6 @@
require File.dirname(__FILE__) + "/version"
+
+require "open-uri"
require "uri"
class GChart
@@ -12,18 +14,19 @@ def encode_extended(number)
return "__" if number.nil?
PAIRS[number.to_i]
end
+
+ TYPES.each do |type|
+ class_eval <<-END
+ def #{type}(options={}, &block)
+ new(options.merge(:type => #{type.inspect}, &block))
+ end
+ END
+ end
end
# for 1.0:
# colors
# background
- #
- # fetch()
- # write()
- #
- # for 1.1:
- # legends
- # area fills
attr_accessor :data, :width, :height, :horizontal, :grouped, :title
attr_reader :type
@@ -36,7 +39,7 @@ def initialize(options={}, &block)
@data = []
@width = 300
@height = 200
- @horizontal = true
+ @horizontal = false
@grouped = false
options.each { |k, v| send("#{k}=", v) }
@@ -65,11 +68,12 @@ def to_url
end
def fetch
- raise "returns the PNG data as a string"
+ open(to_url) { |data| data.read }
end
- def write(io_or_file)
- raise "fetches and then writes to io_or_file"
+ def write(io_or_file="chart.png")
+ return io_or_file.write(fetch) if io_or_file.respond_to?(:write)
+ open(io_or_file, "w+") { |f| f.write(fetch) }
end
private
View
2 lib/version.rb
@@ -1,3 +1,3 @@
class GChart
- VERSION = "1.0.0"
+ VERSION = "0.1.0"
end

0 comments on commit 8021142

Please sign in to comment.
Something went wrong with that request. Please try again.