GraDA 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/grada.rb +32 -4
  2. metadata +1 -1
@@ -45,7 +45,6 @@ class Grada
45
45
  # y: (Array) *optional*
46
46
 
47
47
  def initialize(x, y = nil)
48
- raise NoPlotDataError if ! y.nil? && x.size != y.size
49
48
 
50
49
  @x = validate(x)
51
50
  @y = y.nil? ? y : validate(y)
@@ -140,7 +139,7 @@ class Grada
140
139
  raise NotValidArrayError if ! l.is_a?(Array)
141
140
 
142
141
  l.each do |elem|
143
- raise NotValidDataError if ! ( elem.is_a?(Float) || elem.is_a?(Integer) || elem.is_a?(Array))
142
+ raise NotValidDataError if ! ( elem.is_a?(Float) || elem.is_a?(Integer) || elem.is_a?(Array) || elem.is_a?(Hash))
144
143
  end
145
144
  end
146
145
 
@@ -152,6 +151,18 @@ class Grada
152
151
  end
153
152
  end
154
153
 
154
+ def multiple_data?(l)
155
+ if l.is_a?(Array)
156
+ l.each do |elem|
157
+ return false if ! elem.is_a?(Hash)
158
+ end
159
+
160
+ return true
161
+ end
162
+
163
+ false
164
+ end
165
+
155
166
  def plot_and(&block)
156
167
  Gnuplot.open do |gp|
157
168
  Gnuplot::Plot.new(gp) do |plot|
@@ -162,8 +173,25 @@ class Grada
162
173
  plot.xlabel @opts[:x_label]
163
174
  plot.ylabel @opts[:y_label]
164
175
 
165
- plot.data << Gnuplot::DataSet.new([@x,@y]) do |ds|
166
- ds.with = @opts[:with]
176
+ if multiple_data?(@y)
177
+ @y.each do |dic|
178
+ dic.each do |k, v|
179
+ if k.to_sym != :with
180
+ raise NoPlotDataError if ! v.nil? && @x.size != v.size
181
+
182
+ plot.data << Gnuplot::DataSet.new([@x,v]) do |ds|
183
+ ds.with = dic[:with] || @opts[:with]
184
+ ds.title = "#{k}"
185
+ end
186
+ end
187
+ end
188
+ end
189
+ else
190
+ raise NoPlotDataError if ! @y.nil? && @x.size != @y.size
191
+
192
+ plot.data << Gnuplot::DataSet.new([@x,@y]) do |ds|
193
+ ds.with = @opts[:with]
194
+ end
167
195
  end
168
196
  end
169
197
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GraDA
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: