Skip to content
Browse files

Documentation Updates

  • Loading branch information...
1 parent d529e8a commit d11fa1647c76418dc46c9b9359fff93dbb545cf0 Rimas Silkaitis committed May 19, 2008
Showing with 40 additions and 7 deletions.
  1. +40 −7 lib/gruff/scatter.rb
View
47 lib/gruff/scatter.rb
@@ -1,11 +1,12 @@
require File.dirname(__FILE__) + '/base'
-# Here's how to set up the Scatter graph
+# Here's how to set up an XY Scatter Chart
#
# g = Gruff::Scatter.new(800)
+# g.data(:apples, [1,2,3,4], [4,3,2,1])
+# g.data('oranges', [5,7,8], [4,1,7])
+# g.write('test/output/scatter.png')
#
-# In the event that someone doesn't have both the x and y points filled in
-# the data point will just get dropped from the dataset.
#
class Gruff::Scatter < Gruff::Base
@@ -32,6 +33,13 @@ class Gruff::Scatter < Gruff::Base
#~ # Color of the horizontal baseline
#~ attr_accessor :baseline_x_color
+
+ # Gruff::Scatter takes the same parameters as the Gruff::Line graph
+ #
+ # ==== Example
+ #
+ # g = Gruff::Scatter.new
+ #
def initialize(*args)
super(*args)
@@ -100,8 +108,9 @@ def draw
@d.draw(@base_image)
end
- # Parameters are an array where the first element is the name of the dataset
- # and the value is an array of values to plot.
+ # The first parameter is the name of the dataset. The next two are the
+ # x and y axis data points contain in their own array in that respective
+ # order. The final parameter is the color.
#
# Can be called multiple times with different datasets for a multi-valued
# graph.
@@ -112,11 +121,35 @@ def draw
# NOTE: If you want to use a preset theme, you must set it before calling
# data().
#
+ # ==== Parameters
+ # name:: String or Symbol containing the name of the dataset.
+ # x_data_points:: An Array of of x-axis data points.
+ # y_data_points:: An Array of of y-axis data points.
+ # color:: The hex string for the color of the dataset. Defaults to nil.
+ #
+ # ==== Exceptions
+ # Data points contain nil values::
+ # This error will get raised if either the x or y axis data points array
+ # contains a <tt>nil</tt> value. The graph will not make an assumption
+ # as how to graph <tt>nil</tt>
+ # x_data_points is empty::
+ # This error is raised when the array for the x-axis points are empty
+ # y_data_points is empty::
+ # This error is raised when the array for the y-axis points are empty
+ # x_data_points.length != y_data_points.length::
+ # Error means that the x and y axis point arrays do not match in length
+ #
+ # ==== Examples
+ # g = Gruff::Scatter.new
+ # g.data(:apples, [1,2,3], [3,2,1])
+ # g.data('oranges', [1,1,1], [2,3,4])
+ # g.data('bitter_melon', [3,5,6], [6,7,8], '#000000')
+ #
def data(name, x_data_points=[], y_data_points=[], color=nil)
raise ArgumentError, "Data Points contain nil Value!" if x_data_points.include?(nil) || y_data_points.include?(nil)
- raise ArgumentError, "x_data_points is nil!" if x_data_points.empty?
- raise ArgumentError, "y_data_points is nil!" if y_data_points.empty?
+ raise ArgumentError, "x_data_points is empty!" if x_data_points.empty?
+ raise ArgumentError, "y_data_points is empty!" if y_data_points.empty?
raise ArgumentError, "x_data_points.length != y_data_points.length!" if x_data_points.length != y_data_points.length
# Call the existing data routine for the y axis data

0 comments on commit d11fa16

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