Permalink
Browse files

* Allow line xy data to be entered as pairs.

  • Loading branch information...
donv committed Oct 16, 2012
1 parent 478fad2 commit 6384f988feeb460f21963e81fb4591cf8a48d3e0
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/gruff/line.rb
View
@@ -83,10 +83,14 @@ def initialize(*args)
# g.labels = {0 => '2003', 2 => '2004', 4 => '2005'} #labels
def dataxy(name, x_data_points=[], y_data_points=[], color=nil)
-
raise ArgumentError, "x_data_points is nil!" if x_data_points.length == 0
+
+ if x_data_points.all?{|p| p.size == 2}
+ x_data_points, y_data_points = x_data_points.map{|p| p[0]}, x_data_points.map{|p| p[1]}
+ end
+
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 data.
self.data(name, y_data_points, color)

0 comments on commit 6384f98

Please sign in to comment.